Iptables is the current Linux firewall and routing service. It controls incoming and outgoing network.
Basically just like any other Linux service:
service iptables start service iptables stop service iptables restart
Simply call service status
service iptables status
and check the result:
Firewall is stopped.
If the status message is “Firewall is stopped.” that means that iptables are not running and you should start it with sertvice iptables start. If you get some tables with bunch of geek stuff that means that iptables are running.
To enable iptables starting on boot run
chkconfig iptables on
or run code below to disable it
chkconfig iptables off
This will block IP from accessing your server. Be careful not to block your IP address.
In command below replace “192.168.0.4” with correct IP address.
iptables -A INPUT -s 192.168.0.4 -j DROP
After blocking the IP address (adding it to the iptable rules) you must restart iptables calling:
service iptables restart
Similar to blocking, just use ACCEPT instead of DROP:
iptables -A INPUT -s 192.168.0.4 -j ACCEPT
And after allowing that IP you must also restart iptables:
service iptables restart
You can also flush your iptables rules by using:
iptables -F
This will remove all custom added rules.
Simply by running following command:
iptables -L
Rules created with the iptables command are stored in memory. If the system is restarted before saving the iptables rule set, all rules are lost. For rules to persist through a system reboot, they need to be saved. To save rules, type the following command:
iptables -save > /etc/iptables.rules
To load previously saved rules execute:
iptables --restore < /etc/iptables.rules
There are few ways and can be different on different Linux distributions. This should work on CentOS. To load rules on system boot make file /etc/init.d/iptableslr
vi /etc/init.d/iptableslr
and add these two lines to it:
#!/bin/bash /sbin/iptables-restore < /etc/iptables.rules
The file needs to be executable so change the permissions:
chmod +x /etc/init.d/iptables
Can't download new apps to your phone because there isn't enough storage space? Lack of…
This issue started to appear on macOS 13 Ventura after recent Dropbox update. I would…
Since this morning (Feb 5th 2020) search just stopped working on my Windows 10 (version…
Many of you have run into a problem when you were working on some old…
After 10 years of running my main desktop computer on Windows 7 - time has…
I installed VestaCP for a clien on a new dedicated server running CentOS 7. Once…