share connection between personal computers

14 Dec 2010

Wireless to wired

$ sudo ifconfig eth0 10.0.0.1
$ sudo iptables -F
$ sudo iptables -X
$ sudo iptables -t nat -F
$ sudo iptables -t nat -X
$ sudo iptables -t mangle -F
$ sudo iptables -t mangle -X
$ sudo iptables -P INPUT ACCEPT
$ sudo iptables -P FORWARD ACCEPT
$ sudo iptables -P OUTPUT ACCEPT
$ sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Wired to wireless

$ sudo iwconfig wlan0 mode ad-hoc
$ sudo iwconfig wlan0 essid proxywlan
$ sudo ifconfig wlan0 10.0.0.1 up
$ sudo iptables -F
$ sudo iptables -X
$ sudo iptables -t nat -F
$ sudo iptables -t nat -X
$ sudo iptables -t mangle -F
$ sudo iptables -t mangle -X
$ sudo iptables -P INPUT ACCEPT
$ sudo iptables -P FORWARD ACCEPT
$ sudo iptables -P OUTPUT ACCEPT
$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

After completing any of the previous steps (and if no dhcp daemon has been set up) the client machine will require to be configured manually, eg:

Otherwise you can run a simple dhcpd daemon:

$ sudo simple-dhcpd -i eth0 -a 10.0.0.1