I have a network gateway system using iptables to allow/deny traffic to/from an internal network. I have to manually add and remove rules in iptables
depending on the requirements of the entities in the internal network, including NATing their traffic. Trusted entities on the internal network can request rules to be added and removed as required. The end result is a bunch of rules in the nat
and filter
tables, including POSTROUTING
rules with SNAT
targets, setting the source IP to that of the gateway system, and rules in other tables with the gateway external ip address as dst
.
I want to be able to set the IP of the gateway system on the fly. This would of course have disruptive consequences to TCP sessions etc., but let's keep that out of the picture. The system handles these issues with other mechanisms.
The problem is that an unknown number of rules in the firewall tables still refer to this old source IP address.
Is there a way to easily change all these rules to use the new IP address instead of the old one? Of course I can also accept some fancy script using sed/awk or similar if you are more of a bash wizard than me...