how to write iptable block rule in the /etc/iptables/rules.v4?

January 23, 2015 2.3k views

I can block some ip to link my vps in command line :
sudo iptables -A INPUT -s [IP ADDRESS] -j DROP

how to write the iptable block rule in the /etc/iptables/rules.v4?

4 Answers

It may not be the easiest way / best way, but I use iptables-persistent to do so
Once installed, launch sudo dpkg-reconfigure iptables-persistent to save your iptables

You can run the following command to save the current rules in /etc/iptables/rules.v4 and /etc/iptables/rules.v6:

sudo service iptables-persistent save

root@change:~# sudo iptables -A INPUT -s -j DROP
root@change:~# cat /etc/iptables/rules.v4

Generated by iptables-save v1.4.14 on Fri Jan 23 12:42:00 2015

:INPUT ACCEPT [415:61359]
:OUTPUT ACCEPT [398:101696]

Completed on Fri Jan 23 12:42:00 2015


Why there is no in the file /etc/iptables/rules.v4?

sudo dpkg-reconfigure iptables-persistent can do .

Have another answer? Share your knowledge.