Skip to content

Instantly share code, notes, and snippets.

@davidlonjon
Last active August 29, 2015 14:03
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 davidlonjon/cc542ef54c35af2c637a to your computer and use it in GitHub Desktop.
Save davidlonjon/cc542ef54c35af2c637a to your computer and use it in GitHub Desktop.
iptables useful commands and info
# Cleaning rules
iptables -F // flush all chains
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -X // delete all chains
# install persistent iptables
sudo apt-get install -y iptables-persistent
sudo service iptables-persistent start
sudo sh -C "iptables-save > /etc/iptables/rules.v4"
Info
-A: (Append), adds a rule to the IP Tables
-L: (List), shows the current rules
-m conntrack: allows rules to be based on the current connection state, elaborated in the the --cstate command.
--cstate: explains the states that connections can be in, there are 4: New, Related, Established, and Invalid
-p: (protocol), refers to the the protocol of the rule or of the packet to check.The specified protocol can be one of tcp, udp, udplite, icmp, esp, ah, sctp or the special keyword "all".
--dport: (port), refers to the the port through which the machine connects
-j: (jump), this command refers to the action that needs to be taken if something matches a rule perfectly. It translates to one of four possibilities:
-ACCEPT: the packet is accepted, and no further rules are processed
-REJECT: the packet is rejected, and the sender is notified, and no further rules are processed
-DROP: the packet is rejected, but the sender is not notified, and no further rules are processed
-LOG: the packet is accepted but logged, and the following rules are processed
-I: (Insert), adds a rule between two previous ones
-I INPUT 3: inserts a rule into the IP Table to make it the third in the list
-v: (verbose), offers more details about a rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment