Skip to content

Instantly share code, notes, and snippets.

@nivv
Last active August 29, 2015 14:10
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 nivv/de0cf110131f830e37fc to your computer and use it in GitHub Desktop.
Save nivv/de0cf110131f830e37fc to your computer and use it in GitHub Desktop.
# Run as root or use sudo
$ sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$ sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
$ sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
$ sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT
$ sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
$ sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
$ sudo iptables -A INPUT -j DROP
$ sudo iptables -I INPUT 1 -i lo -j ACCEPT
# Save iptables config
$ sudo iptables-save | sudo tee /etc/iptables/rules.v4
$ sudo service iptables-persistent restart
# Install and use so firewalls are saved through restarts
$ sudo apt-get install -y iptables-persistent
$ sudo service iptables-persistent start
// Source: https://serversforhackers.com/editions/2014/06/17/more-security/
// Source 2: http://fideloper.com/ubuntu-12-04-lemp-nginx-setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment