I am using Debian / Ubuntu Linux server. How do I save iptables rules permanently on Linux using the CLI added using the iptables command? How can I store iptables IPv4 and IPv6 rules permanently on the Debian Linux cloud server?
Linux system administrator and developers use iptables and ip6tables commands to set up, maintain, and inspect the firewall tables of IPv4 and IPv6 packet filter rules in the Linux kernel. Any modification made using these commands is lost when you reboot the Linux server. Hence, we need to store those rules across reboot permanently. This page examples how to save iptables firewall rules permanently either on Ubuntu or Debian Linux server.
ADVERTISEMENTS
You need to use the following commands to save iptables firewall rules forever:
Open the terminal application and then type the following commands. For remote server login using the ssh command:
$ ssh vivek@server1.cyberciti.biz
$ ssh ec2-user@ec2-host-or-ip
You must type the following command as root user either using the sudo command or su command.
Debian and Ubuntu Linux user type:
$ sudo /sbin/iptables-save > /etc/iptables/rules.v4
### IPv6 ##
$ sudo /sbin/ip6tables-save > /etc/iptables/rules.v6
CentOS/RHEL users run:
$ sudo /sbin/iptables-save > /etc/sysconfig/iptables
### IPv6 ##
$ sudo /sbin/ip6tables-save > /etc/sysconfig/ip6tables
#[object object] #[object object] #[object object] #linux