Last active
December 17, 2015 14:49
-
-
Save alexsavio/5627443 to your computer and use it in GitHub Desktop.
IPTables configuration in Ubuntu 13.04. Secure your ports!
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
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 |
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
# 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 |
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/sh | |
iptables-restore < /etc/iptables.rules | |
exit 0 |
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/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