Get Mystery Box with random crypto!

How to keep iptables firewall rules on Linux by h4ck3rXc0d3r | HACKING💻️TEAM™ 💳💵💶💴💷

How to keep iptables firewall rules on Linux by h4ck3rXc0d3r

1) Permanently saving iptables firewall rules on Linux
You need to use the following commands to keep your iptables firewall rules permanently:

Iptables-save or ip6tables-save command - saves or dumps the contents of IPv4 or IPv6 tables in an easily parsed format to the screen or to a specified file.
Iptables-restore command or ip6tables-restore command -

2) Restores IPv4 or IPv6 firewall rules and tables from a given file on Linux.
Step 1 - Open Terminal
Open a terminal application and enter the following commands.

3) To log into a remote server using the ssh command:


You must enter the following command as root using the sudo or su command.

Step 2. Save the Linux firewall rules for IPv4 and IPv6.
Debian и Ubuntu Linux:

$ sudo /sbin/iptables-save > /etc/iptables/rules.v4
IPv6
$ sudo /sbin/ip6tables-save > /etc/iptables/rules.v6

CentOS / RHEL:

$ sudo /sbin/iptables-save > /etc/sysconfig/iptables
## IPv6 ##
$ sudo /sbin/ip6tables-save > /etc/sysconfig/ip6tables

4) Displaying saved rules on Linux
We can display the saved file using cat command or search using grep / egrep command:

$ cat /etc/iptables/rules.v4

Step 3. Restoring the Linux firewall rules for IPv4 and IPv6.
We'll just reverse the above commands in reverse order for each operating system:

Debian or Ubuntu
$ sudo /sbin/iptables-restore < /etc/iptables/rules.v4
$ sudo /sbin/ip6tables-restore < /etc/iptables/rules.v

CentOS/RHEL
$ sudo /sbin/iptables-save < /etc/sysconfig/iptables
$ sudo /sbin/ip6tables-save < /etc/sysconfig/ip6tables

Step 4 - Installing the iptables-persistent package for Debian or Ubuntu Linux

5) Note that the following command will conflict with iptables interfaces such as ufw or firewall-cmd. Avoid using the following packages if you are using these tools.
We need to install iptables-persistent.
It will act as a loader for Netfilter rules, the iptables netfilter-persistent plugin, which is a loader for Netfilter configuration using a plugin based architecture.
In other words, automatic loading of saved iptables rules from above files.

6) Enter the following apt command or apt-get command:
$ sudo apt install iptables-persistent
$ sudo apt-get install iptables-persistent

7) Make sure services are enabled on Debian or Ubuntu using the systemctl command:
$ sudo systemctl is-enabled netfilter-persistent.service
If not, enable:
$ sudo systemctl enable netfilter-persistent.service
Checking status:
$ sudo systemctl status netfilter-persistent.service

Step 5 - Install the iptables-services package for RHEL / CentOS
By default, RHEL / CentOS 7 or 8 comes with firewalld.

If you want a good old file firewall, enter the following commands:

$ sudo systemctl stop firewalld.service
$ sudo systemctl disable firewalld.service
$ sudo systemctl mask firewalld.service
$ sudo yum install iptables-services
$ sudo systemctl enable iptables
$ sudo systemctl enable ip6tables
$ sudo systemctl status iptables