iptables and combining additional rule sources

Aruna Hewapathirane aruna.hewapathirane at gmail.com
Sun Apr 26 08:42:18 EDT 2020


<snip>
> The problem I am having is, adding the new information to the existing
> iptables rules in /etc/sysconfig/iptables. I want to write my rules to
> a separate file and then tell /etc/sysconfig/iptables to include it at
> the correct position.
>
> I read the iptables(8), iptables-save(8) and iptables-restore(8) man
> pages, but I don't see how to combine the different sources.
>
> How do I tell iptables to include a second external source at a
> specific location?
<snip>

1 - Get the iptables rules list with the line numbers enabled
     $ iptables -nL –line-numbers

2 - Look up the line number you want to use and insert your rule.
     ( I am inserting a rule at line number 10, the existing rule will
shift down)
     $ sudo /sbin/iptables -I INPUT 10 -s 202.54.1.1 -j DROP -m comment
--comment "DROP spam IP address - "

3 - Save the rules to a file in etc so you can reload them at the next
reboot
     $ sudo /sbin/iptables-save > /etc/iptables.local

4 - To make the rules persistent, add the following rule to your
/etc/rc.local file)
     sudo /sbin/iptables-restore < /etc/iptables.local

If your system reboots you will not loose the rules now.

Aruna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20200426/51d7f4b0/attachment.html>


More information about the Kernelnewbies mailing list