iptables is a command-line firewall utility that uses policy chains to allow or block traffic. When a connection tries to establish itself on your system, iptables looks for a rule in its list to match it to. If it doesn’t find one, it resorts to the default action.
Step 1 – Installing Iptables Linux Firewall
apt-get update
apt-get install iptables
Step 2 – Setting chain rules
Login as root user and run the following command
Defining chain rules, for example
Open a port
iptables -I INPUT -p tcp --dport 23456 -j ACCEPT
Block an IP
iptables -A INPUT -s 88.88.188.188 -j REJECT
Delete a rule
iptables -D INPUT -s 221.194.47.0/24 -j REJECT
Step 3 – Start Iptables Service On Boot
iptables-save > /etc/iptables.up.rules
echo -e '#!/bin/bash\n/sbin/iptables-restore < /etc/iptables.up.rules' > /etc/network/if-pre-up.d/iptables
chmod +x /etc/network/if-pre-up.d/iptables
Save iptables rules
iptables-save > /etc/iptables.up.rules
Other Commands
Check all current rules
Update iptables
Status, restart iptables
service iptables status
service iptables restart
0 Comments