Ubuntu Linux Save / Restore Iptables Rules

Ubuntu Linux Save / Restore Iptables Rules

To save and restore iptables rules on an Ubuntu Linux system, you can use the iptables-save and iptables-restore commands, as described in the previous answer.

  1. Save the iptables rules to a file using the iptables-save command. For example:
iptables-save > /etc/iptables/rules.v4
Sou‮w:ecr‬ww.lautturi.com

This will save the iptables rules to the file /etc/iptables/rules.v4.

  1. Create a script to load the iptables rules when the system is started. The script should contain the following line:
iptables-restore < /etc/iptables/rules.v4
  1. Make the script executable using the chmod command. For example:
chmod +x /path/to/script.sh
  1. Configure the script to run when the system is started. On Ubuntu, you can do this by creating a symbolic link to the script in the /etc/init.d directory.

To create a symbolic link to the script, use the ln command like this:

ln -s /path/to/script.sh /etc/init.d/script

This will create a symbolic link called /etc/init.d/script that points to the script.

To make the script executable at startup, you can use the update-rc.d command like this:

update-rc.d script defaults

This will enable the script to be run at startup by adding symbolic links to the script in the appropriate runlevel directories.

Keep in mind that the method for saving and restoring iptables rules may vary depending on the version of Ubuntu you are using. Consult the documentation for your version of Ubuntu for more information on how to save and restore iptables rules permanently.

You can also use other tools such as iptables-persistent or firewalld to save and restore iptables rules on an Ubuntu Linux system. These tools can simplify the process of saving and restoring iptables rules, and may be easier to use depending on your needs. Consult the documentation for these tools for more information on how to use them to save and restore iptables rules.

Created Time:2017-10-30 14:27:26  Author:lautturi