Register now and start sharing your code snippets.
-->
Linux NAT with 3g PPP connection
Shell Script (Bash) posted 7 months ago by marko
I run this nat.sh 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.
1 #!/bin/bash 2 iptables --flush 3 iptables --table nat --flush 4 iptables --delete-chain 5 iptables --table nat --delete-chain 6 7 echo 1 > /proc/sys/net/ipv4/ip_forward 8 9 internal=eth0 10 external=ppp0 11 /sbin/iptables -t nat -A POSTROUTING -o ${external} -j MASQUERADE 12 /sbin/iptables -A FORWARD -i ${external} -o ${internal} -m state --state RELATED,ESTABLISHED -j ACCEPT 13 /sbin/iptables -A FORWARD -i ${internal} -o ${external} -j ACCEPT