Minimal IPTABLES config for SOHO routers

If the br0 is LAN port, and the eth0.101 is a WAN port (and inside):

iptables -A INPUT -i br0 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s -i br0 -j ACCEPT
iptables -A FORWARD -d -i eth0.101 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0.101 -j MASQUERADE
iptables -P INPUT DROP
iptables -P FORWARD DROP

If you want to allow SSH from the WAN port (nope, but, you did remember to set a strong password, right?), you can use the following command to open up port 22 from the WAN interface:

iptables -A INPUT -i eth0.101 -p tcp -m tcp --dport 22 -j ACCEPT

If all OK, save config:

Edit /etc/network/if-pre-up.d/iptables file:

iptables-restore --counters < /etc/iptables/rules.v4
exit 0

Mod for run, and save tables:

chmod 755 /etc/network/if-pre-up.d/iptables
mkdir -p /etc/iptables
iptables-save > /etc/iptables/rules.v4

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s