Skip to content

Instantly share code, notes, and snippets.

@nikolaybotev
Created June 11, 2021 04:41
Show Gist options
  • Save nikolaybotev/22e35386531473f8e42c817f3d435145 to your computer and use it in GitHub Desktop.
Save nikolaybotev/22e35386531473f8e42c817f3d435145 to your computer and use it in GitHub Desktop.
Router Firewall Configuration (iptables)
UPSTREAM_IFACE="${1:-eth1}"
# IPv4 and IPv6
for iptables in iptables ip6tables; do
# :INPUT
# - returning traffic
sudo $iptables -A INPUT -i $UPSTREAM_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
# - ping
sudo $iptables -A INPUT -i $UPSTREAM_IFACE -p icmp -j ACCEPT
# - ssh
sudo $iptables -A INPUT -i $UPSTREAM_IFACE -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# - or drop
sudo $iptables -A INPUT -i $UPSTREAM_IFACE -j DROP
# :FORWARD
# - returning traffic
sudo $iptables -A FORWARD -i $UPSTREAM_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
# - or drop
sudo $iptables -A FORWARD -i $UPSTREAM_IFACE -j DROP
done
@nikolaybotev
Copy link
Author

Save the config using netfilter-persistent:

sudo apt install -y netfilter-persistent iptables-persistent
sudo netfilter-persistent save

@nikolaybotev
Copy link
Author

Review config using:

sudo iptables -nvL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment