Skip to content

Instantly share code, notes, and snippets.

@phanletrunghieu
Last active September 7, 2019 02:44
Show Gist options
  • Save phanletrunghieu/b17d9a9128d98b29bf5e21ce86556aaa to your computer and use it in GitHub Desktop.
Save phanletrunghieu/b17d9a9128d98b29bf5e21ce86556aaa to your computer and use it in GitHub Desktop.
# eth0 is public network interface
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
# Allow connection RELATED,ESTABLISHED on eth0
iptables -t filter -A INPUT -i eth0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# Prevent DOCKER chain
iptables -t nat -I PREROUTING -m addrtype --dst-type LOCAL -j RETURN
# Allow unlimited traffic on loopback
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
# Allow ssh
iptables -t filter -A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -t filter -A OUTPUT -p tcp -m tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT
# Allow http on eth0 interface
iptables -t filter -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
iptables -t filter -A OUTPUT -o eth0 -p tcp --sport 80 -j ACCEPT
# Allow https on eth0 interface
iptables -t filter -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
iptables -t filter -A OUTPUT -o eth0 -p tcp --sport 443 -j ACCEPT
# Allow docker port on eth0 interface
iptables -t filter -A INPUT -i eth0 -p tcp --dport 7007 -j ACCEPT
iptables -t filter -A OUTPUT -o eth0 -p tcp --sport 7007 -j ACCEPT
# Allow outgoing 80
iptables -t filter -A INPUT -i eth0 -p tcp -m tcp --sport 80 -j ACCEPT
iptables -t filter -A OUTPUT -o eth0 -p tcp -m tcp --dport 80 -j ACCEPT
iptables -t filter -A INPUT -i eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
iptables -t filter -A OUTPUT -o eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
# Allow outgoing 443
iptables -t filter -A INPUT -i eth0 -p tcp -m tcp --sport 443 -j ACCEPT
iptables -t filter -A OUTPUT -o eth0 -p tcp -m tcp --dport 443 -j ACCEPT
# Deny all request on eth0 interface
iptables -t filter -A INPUT -i eth0 -j DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment