nat snippets

Linux NAT with 3g PPP connection

Tagged nat, linux, iptables  Languages bash

I run this script whenever I need to share my 3g connection to other computers in the switch I'm plugged into. Please note that it resets existing iptables rules.

iptables --flush            
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain

echo 1 > /proc/sys/net/ipv4/ip_forward

/sbin/iptables -t nat -A POSTROUTING -o ${external} -j MASQUERADE
/sbin/iptables -A FORWARD -i ${external} -o ${internal} -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i ${internal} -o ${external} -j ACCEPT