Ubuntu 14.04 Desktop: Set up connection sharing

1. Wireless to wireless sharing

Assuming Machine A:

  • wlan0 - wireless connection to external subnet (10.0.0.0) and
  • wlan1 - wireless connection to internal subnet (192.168.150.0)

suchlike:

NIC IP ADDR NETWORK GATEWAY
wlan0 10.0.0.29 10.0.0.0 10.0.0.1
wlan1 192.168.150.1 192.168.150.0  

Execute these on Machine A:

sudo iptables -A FORWARD -o wlan0 -i wlan1 -s 192.168.150.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

2. Wireless to wired sharing

Assuming Machine B:

  • eth1 - wireless connection to external subnet (192.168.150.0) and
  • eth0 - wired connection to internal subnet (10.42.0.0)

suchlike:

NIC IP ADDR NETWORK GATEWAY
eth1 192.168.150.73 192.168.150.0 192.168.1500.1
eth0 10.42.0.1 10.42.0.0  

Execute these on Machine B:

sudo iptables -A FORWARD -o eth1 -i eth0 -s 10.42.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

3. Do following on both Machine A and Machine B:

Save the iptables:

sudo iptables-save | sudo tee /etc/iptables.sav

Edit rc.local to so changes are applied after reboot:

sudo vi /etc/rc.local

add these lines before last line containing exit 0:

#
# Apply routing configuration to iptables...
iptables-restore < /etc/iptables.sav

Enable IP forwarding on the gateway for routing between interfaces:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

edit sysctl.conf:

sudo vi /etc/sysctl.conf

uncomment this line:

#net.ipv4.ip_forward=1

REFERENCES:

http://ubuntuforums.org/showthread.php?t=2179393
https://help.ubuntu.com/community/Internet/ConnectionSharing