1.Ubuntu
First, save the existing rules:
iptables-save > /etc/iptables.rules
Then create a bash script, and save it to /etc/network/if-pre-up.d/ directory:
#!/bin/bash iptables-restore < /etc/iptables.rules
In this way, each time the system iptables rules will be automatically loaded after reboot.
! / \ Note: Do not try to execute the above command in .bashrc or .profile, because the user is not usually root, and this can only be loaded iptables rules at login
2.CentOS, RedHat
# Save iptables rules Service iptables the Save # iptables restart service Service iptables STOP Service iptables Start
View the current rules:
cat /etc/sysconfig/iptables