Laptop Wifi NAT Howto

Herman Oosthuysen, GPL, 2010

This is a simple NAT script that allows you to connect a laptop machine to a WiFi network and then hook a desktop machine to the ethernet port of the laptop machine.

#! /bin/bash
echo Configure a laptop as a wlan0 to eth0 NAT router:
echo WAN = wlan0, DHCP 
echo LAN = eth0, 192.168.1.1, 255.255.255.0 

# Accept all traffic
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

# General new connection rate limiting for DOS and Brute Force protection
iptables -I INPUT -p TCP -m state --state NEW -m limit --limit 30/minute --limit-burst 5 -j ACCEPT

# Configure a port for the LAN hooked to eth0
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 up

# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Create a NAT firewall
# WAN = wlan0, LAN = eth0
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

echo
echo On the LAN machine do:
echo ifconfig eth0 192.168.1.2 netmask 255.255.255.0 up
echo route add default gw 192.168.1.1
echo
echo Edit /etc/resolv.conf and add the Google public DNS: 
echo nameserver 8.8.8.8
echo nameserver 8.8.4.4
echo
echo Now the LAN machine should be able to connect to the wild wild world via the laptop.
echo
echo La voila!