Skip to content

Instantly share code, notes, and snippets.

@alexsavio
Last active December 17, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexsavio/5627443 to your computer and use it in GitHub Desktop.
Save alexsavio/5627443 to your computer and use it in GitHub Desktop.
IPTables configuration in Ubuntu 13.04. Secure your ports!
Got this from: https://help.ubuntu.com/community/IptablesHowTo
IPTables setup, which will load and save configurations made in IPTables.
This default setup will block every port except for 80 and 22.
First create the files below in
/etc/iptables.rules
/etc/network/if-post-down.d/iptablessave
/etc/network/if-pre-up.d/iptablesload
and then:
sudo chmod +x /etc/network/if-post-down.d/iptablessave
sudo chmod +x /etc/network/if-pre-up.d/iptablesload
# Generated by iptables-save v1.3.1 on Sun Apr 23 05:32:09 2006
*filter
:INPUT ACCEPT [273:55355]
:FORWARD ACCEPT [0:0]
:LOGNDROP - [0:0]
:OUTPUT ACCEPT [92376:20668252]
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -j LOGNDROP
-A LOGNDROP -p tcp -m limit --limit 5/min -j LOG --log-prefix "Denied TCP: " --log-level 7
-A LOGNDROP -p udp -m limit --limit 5/min -j LOG --log-prefix "Denied UDP: " --log-level 7
-A LOGNDROP -p icmp -m limit --limit 5/min -j LOG --log-prefix "Denied ICMP: " --log-level 7
-A LOGNDROP -j DROP
COMMIT
# Completed on Sun Apr 23 05:32:09 2006
#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0
#!/bin/sh
iptables-save -c > /etc/iptables.rules
if [ -f /etc/iptables.downrules ]; then
iptables-restore < /etc/iptables.downrules
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment