Saved iptables rules not found

Musthafa

Member
Dec 14, 2016
17
0
1
Dubai
cPanel Access Level
Root Administrator
Hi,

I am trying to block a particular IP accessing my server via iptables as "iptables -I INPUT -s x.x.x.x -j DROP"
Then saved iptables by "service iptables save" and restarted "service iptables restart"
When I checked the saved rules after some time by this command "iptables -L -n | grep 'x.x.x.x' ", I couldn't find it in the saved list. Why?

Note::I dont have a csf installed in whm

Any help are appreciated.
 

24x7server

Well-Known Member
Apr 17, 2013
1,911
97
78
India
cPanel Access Level
Root Administrator
Twitter
Hi,

Try below commands:
# cp -ar /etc/sysconfig/iptables /etc/sysconfig/iptables_BK
# iptables -A INPUT -p tcp -s x.x.x.x -j DROP
# iptables-save >> /etc/sysconfig/iptables

Note: Don't forget to back up correct IPtables file based on its appropriate location on your server..
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

You may also want to consider installing a plugin such as CSF for easier management of your IPtables firewall rules.

Thank you.
 

Musthafa

Member
Dec 14, 2016
17
0
1
Dubai
cPanel Access Level
Root Administrator
Hi,

Sorry for the late reply. I found out that the rules are being saved in /etc/sysconfig/iptables, but is not showing when I check with iptables -L -n command.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

You may want to consider installing a third-party firewall management utility such as CSF if you are having trouble manually saving your system's iptables firewall rules:

ConfigServer Security & Firewall (csf)

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Could you verify if installing CSF addresses the issue?

Thank you.
 

Musthafa

Member
Dec 14, 2016
17
0
1
Dubai
cPanel Access Level
Root Administrator
There is an update, some rules are missing from iptables. I blocked a bad bot before two weeks with its IP subnet, now its again accessing my website and creating load.

/etc/init.d/iptables save - thats all I need to do after applying the rule right?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
/etc/init.d/iptables save - thats all I need to do after applying the rule right?
Hello,

Yes, that command will save your iptables rules on CentOS 5.

Thank you.