Skip to content

Instantly share code, notes, and snippets.

@sairam
Last active December 19, 2015 10:49
Show Gist options
  • Save sairam/5943258 to your computer and use it in GitHub Desktop.
Save sairam/5943258 to your computer and use it in GitHub Desktop.
Sample iptables config in digital ocean to only allow 443, 80 and port 22
# Generated by iptables-save v1.4.7 on Mon Jul 8 01:20:10 2013
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [5:1668]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
-A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 465 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
COMMIT
# Completed on Mon Jul 8 01:20:10 2013
# No guarantees on if this would work again
# Generated by iptables-save v1.4.7 on Sun Jan 13 11:57:39 2013
*mangle
:PREROUTING ACCEPT [481:39177]
:INPUT ACCEPT [481:39177]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [336:68311]
:POSTROUTING ACCEPT [336:68311]
COMMIT
# Completed on Sun Jan 13 11:57:39 2013
# Generated by iptables-save v1.4.7 on Sun Jan 13 11:57:39 2013
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
:VZ_FORWARD - [0:0]
:VZ_INPUT - [0:0]
:VZ_OUTPUT - [0:0]
# -A INPUT -s $SERVERIP -j DROP
# -A INPUT -s $SERVERIP/$MASK -j DROP
-A INPUT -j VZ_INPUT
-A FORWARD -j VZ_FORWARD
-A OUTPUT -j VZ_OUTPUT
-A VZ_INPUT -p tcp -m tcp --dport 2222 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 465 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 20:21 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 32768:65535 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 9000 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 2222 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 110 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 53 -j ACCEPT
-A VZ_INPUT -p udp -m udp --dport 53 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 32768:65535 -j ACCEPT
-A VZ_INPUT -p udp -m udp --dport 32768:65535 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 8880 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 8443 -j ACCEPT
-A VZ_INPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -p tcp -j ACCEPT
-A VZ_INPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -p udp -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 465 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 20:21 -j ACCEPT
-A VZ_INPUT -p tcp -m tcp --dport 32768:65535 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 80 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 9000 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 25 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 110 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 53 -j ACCEPT
-A VZ_OUTPUT -p udp -m udp --sport 53 -j ACCEPT
-A VZ_OUTPUT -p tcp -j ACCEPT
-A VZ_OUTPUT -p udp -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 8880 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 8443 -j ACCEPT
-A VZ_OUTPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -p tcp -j ACCEPT
-A VZ_OUTPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -p udp -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 443 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 465 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 20:21 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 32768:65535 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 443 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 465 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 20:21 -j ACCEPT
-A VZ_OUTPUT -p tcp -m tcp --sport 32768:65535 -j ACCEPT
COMMIT
# Completed on Sun Jan 13 11:57:39 2013
# Generated by iptables-save v1.4.7 on Sun Jan 13 11:57:39 2013
*nat
:PREROUTING ACCEPT [11:800]
:POSTROUTING ACCEPT [24:1660]
:OUTPUT ACCEPT [24:1660]
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment