CentOS / RHEL : How to add iptable rules

The syntax to add an iptables rule is as shown below.

# iptables -I INPUT [line number] -s [ip address or subnet] -j ACCEPT

For example to add a new rule at line number 2 to allow subnet 192.168.0.0/24.

# iptables -I INPUT 2 -s 192.168.0.0/24 -j ACCEPT

Saving iptable rules

After configuring the iptables rules from the command line, it is required to save the iptable rules. It is important to save the list of iptable rules to make them persist across reboots or restart of iptable service.

# service iptables save
Related Post