How to add or remove iptables rules with text editor

If you want to add/remove iptables’ rules with text editor, you can do it in such way. Firstly, run such command in terminal:

iptables-save > /tmp/iptables_rules

Then open newly created file with text Editor, for example, vim:

vim /tmp/iptables_rules

Switch vim to insert mode by typing “i”. Change rules as you want. Then switch off inser mode by typing “Esc” button. Then type “wq!” combination and press “Enter”. After all these actions, run such command in terminal:

iptables-restore < /tmp/iptables_rules

Check if rules have been applied by command:

iptables -L

Leave a Reply