What is the iptables command, and how to use it for network filtering?

The iptables command configures Netfilter firewall rules providing the network address translation, packet filtering, etc. iptables inspects the network packet and then manages them according to the defined rules. Here is how you can use the iptables command for network filtering:

Run the below command to display the current iptables rules, including policies, chains, and other actions for the network:
iptables -L?

The iptables configuration uses the predefined set of chains to process the network packages at different stages. So you can define rules to these chains for manipulating the network packets:
iptables -A <chain> <options> -j <target>?

In the above command :

* <chain> : Specifies the chain where you want to define a new rule.

* <options> : Defines the conditions for the rule, like ports, protocols, etc.

* -j <target> : Defines the target action when the packet matches the rule.


By default, iptables rules get automatically removed after the system reboot, but you can use the following command to make the rules persistent:
iptables-save > /etc/iptables/rules.v4?