Ubuntu: Share internet connections with other computers

Posted Almost 7 years ago. Visible to the public.

You can configure a Ubuntu system as a gateway in order to share it's internet connection (maybe via WLAN or tethering) with other computers on the network.

On the gateway

  • Enable ip traffic forwarding:
    • Open /etc/sysctl.conf

    • Uncomment the line

      net.ipv4.ip_forward=1
      
    • Reload using sudo sysctl -p /etc/sysctl.conf

  • Reconfigure ip_tables to allow NAT:
    • Download the attached file
    • Replace online_device with the name of the network device that provides the internet connection
    • Replace lan_device with the name of the network device that connects to the LAN
    • Run the script with sudo

On the client PC

Add the gateway PC as the default gateway using

sudo ip route del default
sudo ip route add default via <ip of gateway pc>

Add another DNS server to /etc/resolv.conf, for example

nameserver 8.8.8.8
Tobias Kraze
Last edit
Almost 7 years ago
Tobias Kraze
Attachments
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2017-07-06 10:23)