Iptables explained
The following article describes how to use the Iptables and explains the commands
optional:
iptables -I INPUT 4 # This will input to line 4
iptables -A INPUT # This will input a new line
# Related and established connections: Allow related and already established
iptables -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
# Block All
iptables -P OUTPUT DROP
#Rules SSH: Allow SSH from IP adress
iptables -I INPUT 1 -p tcp –dport 22 -s 123.123.123.123 -j ACCEPT
# Drop IP from SSH
iptables -A INPUT -p tcp –dport 22 -s 0.0.0.0 -j DROP
# Drop all others from SSH
iptables -A INPUT -p tcp –dport 22 -j DROP
#Rules HTTP: Allow http from IP adress
iptables -I INPUT 1 -p tcp –dport 22 -s 123.123.123.123 -j ACCEPT
— Rate Limit for port
# Create new state for port 25 (new rule)
iptables -I INPUT -p tcp –dport 25 -i eth0 -m state –state NEW -m recent –set
# Rule apply drop connection if there are more then 15 connections every 60 seconds.
iptables -I INPUT -p tcp –dport 25 -i eth0 -m state –state NEW -m recent –update –seconds 60 –hitcount 15 -j DROP
— Redirect Ports
#Redirect port 465 to port 25 on eth0
iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 465 -j REDIRECT –to-port 25
#Disable incoming pings:
iptables -A INPUT -p icmp –icmp-type echo-request -j REJECT
#Drop all connection on port 80
iptables -A INPUT -p tcp –destination-port 80 -j DROP
# Accept only from the following
iptables -I INPUT -s 84.107.143.xxx -j ACCEPT