Copy iptables rules across servers

Copy server A's iptables rules to server B and apply it.
(At that time, in order to solve a chaotic docker environment, there was a problem with the routing between docker containers, and an iptables rule was rudely copied to solve it.)

Server A
sudo iptables-save > iptables-export
cat iptables-export (modify if required)
scp iptables-export user@server_b_ip_address:/tmp
Server B

sudo iptables-restore < /tmp/iptables-export
CentOS: 

sudo service iptables save
Ubuntu: 

sudo apt-get install iptables-persistent

When applying new firewall rules, you will be asked if you want to save the new configuration, just answer yes.
If you need to modify the firewall rules in the future and save the changes, you can also execute the following command:
sudo invoke-rc.d iptables-persistent save



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324644332&siteId=291194637