Last active
January 18, 2020 20:04
-
-
Save RiFi2k/32644aff5cec4791205e516fba2124c2 to your computer and use it in GitHub Desktop.
iptables-persistent rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#!/bin/bash | |
# forget old rules | |
iptables -F | |
iptables -X | |
iptables -Z | |
# set default policy to drop | |
iptables -P INPUT DROP | |
iptables -P OUTPUT DROP | |
iptables -P FORWARD DROP | |
# allow loopback | |
iptables -A INPUT -i lo -j ACCEPT | |
iptables -A OUTPUT -o lo -j ACCEPT | |
# drop invalid packets | |
iptables -A INPUT -m state --state INVALID -j DROP | |
iptables -A OUTPUT -m state --state INVALID -j DROP | |
iptables -A FORWARD -m state --state INVALID -j DROP | |
# allow established, related packets we've already seen | |
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
# output chain | |
iptables -A OUTPUT -p tcp -m tcp --dport 22 -m comment --comment "SSH" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 53 -m comment --comment "DNS-TCP" -j ACCEPT | |
iptables -A OUTPUT -p udp -m udp --dport 53 -m comment --comment "DNS-UDP" -j ACCEPT | |
iptables -A OUTPUT -p udp -m udp --dport 67:68 -m comment --comment "DHCP" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 80 -m comment --comment "HTTP" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 443 -m comment --comment "HTTPS" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 465 -m comment --comment "SMTPS" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 587 -m comment --comment "SMTPS" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 993 -m comment --comment "IMAPS" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 995 -m comment --comment "POP3S" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 5222 -m comment --comment "JABBER" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 8001 -m comment --comment "IRC" -j ACCEPT | |
iptables -A OUTPUT -p tcp -m tcp --dport 8010 -m comment --comment "JABBER FT" -j ACCEPT | |
# allow icmp packets (e.g. ping...) | |
iptables -A INPUT -p icmp -m state --state NEW -j ACCEPT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.lammertbies.nl/comm/info/iptables.html | |
*filter | |
:INPUT ACCEPT [0:0] | |
:FORWARD ACCEPT [0:0] | |
:OUTPUT ACCEPT [0:0] | |
:Always - [0:0] | |
:Allow - [0:0] | |
:Bogus - [0:0] | |
:Enemies - [0:0] | |
:Friends - [0:0] | |
-A INPUT -j Bogus | |
-A INPUT -j Always | |
-A INPUT -j Enemies | |
-A INPUT -j Allow | |
-A FORWARD -j Bogus | |
-A FORWARD -j Always | |
-A FORWARD -j Enemies | |
-A FORWARD -j Allow | |
-A Bogus -p tcp -m tcp --tcp-flags SYN,FIN SYN,FIN -j DROP | |
-A Bogus -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP | |
-A Bogus -s 169.254.0.0/16 -j DROP | |
-A Bogus -s 172.16.0.0/12 -j DROP | |
-A Bogus -s 192.0.2.0/24 -j DROP | |
-A Bogus -s 192.168.0.0/16 -j DROP | |
-A Bogus -s 10.0.0.0/8 -j DROP | |
-A Bogus -s 127.0.0.0/8 -i ! lo -j DROP | |
-A Always -p udp --dport 123 -j ACCEPT | |
-A Always -m state --state ESTABLISHED,RELATED -j ACCEPT | |
-A Always -i lo -j ACCEPT | |
-A Friends -s 123.123.123.123 -j ACCEPT | |
-A Friends -s 111.111.111.0/24 -j ACCEPT | |
-A Friends -j DROP | |
-A Enemies -m recent --name psc --update --seconds 60 -j DROP | |
-A Enemies -i ! lo -m tcp -p tcp --dport 1433 -m recent --name psc --set -j DROP | |
-A Enemies -i ! lo -m tcp -p tcp --dport 3306 -m recent --name psc --set -j DROP | |
-A Enemies -i ! lo -m tcp -p tcp --dport 8086 -m recent --name psc --set -j DROP | |
-A Enemies -i ! lo -m tcp -p tcp --dport 10000 -m recent --name psc --set -j DROP | |
-A Enemies -s 99.99.99.99 -j DROP | |
-A Allow -p icmp --icmp-type echo-request -j Friends | |
-A Allow -p icmp --icmp-type any -m limit --limit 1/second -j ACCEPT | |
-A Allow -p icmp --icmp-type any -j DROP | |
-A Allow -p tcp -m state --state NEW -m tcp --dport 22 -j Friends | |
-A Allow -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT | |
-A Allow -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT | |
-A Allow -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT | |
-A Allow -j DROP | |
COMMIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://forum.kimsufi.com/showthread.php?27726-Basic-security-with-iptables-firewall-amp-DNS