Skip to content

Instantly share code, notes, and snippets.

@dasheck0
Created March 11, 2020 10:08
Show Gist options
  • Save dasheck0/16768256c61abaa6dee98929949a7171 to your computer and use it in GitHub Desktop.
Save dasheck0/16768256c61abaa6dee98929949a7171 to your computer and use it in GitHub Desktop.
[iptables.txt] Some commands for configuring ip tables in a linux 2 aws ec2 instance #aws #iptables #bash #ec2
# iptables
# http://gr8idea.info/os/tutorials/security/iptables1.html
# change policy to drop (if no rule applies, connection will be dropped)
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# list all rules
iptables -L
# list all nat rules
iptables -t nat -L
# redirect a port
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
# -A appends a rule (to the bottom)
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
# -I inserts to a position
iptables -I INPUT 1 -p tcp --dport ssh -j ACCEPT
# save or restore iptable (to persist between reboots)
# save
Debian/Ubuntu: iptables-save > /etc/iptables/rules.v4
RHEL/CentOS: iptables-save > /etc/sysconfig/iptables
# restore (Debian: /etc/rc.local)
iptables-restore < /etc/iptables/rules.v4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment