iptables rules to just allow access from whitelist IPs

iptables -I INPUT 1 -p icmp -j ACCEPT                    #allow ping packets

iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT          #allow one port

iptables -I INPUT 1 -i lo -j ACCEPT                      #allow loopback

iptables -I INPUT 1 -s 1.2.3.4,5.6.7.8,x.y.z.a -j ACCEPT  #allow a few IPs

iptables -I INPUT 1 -p tcp --match multiport --dport 22,80,443 -j ACCEPT
# allow a group of ports

iptables -I INPUT 1 -p tcp --match multiport --dport 39901:39999 -j ACCEPT
# allow a range of ports

iptables -A INPUT -j DROP
# drop all (this should be append to the last of the INPUT chain)

发表回复