Simple Internet connection sharing with NetworkManager

24 March 2009

NetworkManager version 0.7, shipped with Ubuntu 8.10 and later, contains a redesigned user interface for managing network connections.

Among the new features and UI is an option to make a connection “Shared to other computers”. This is basically a dead-simple NAT (Network Address Translation), or Internet connection sharing, built right in to NetworkManager.

To enable this, you must follow three steps:

  1. Install dnsmasq on your computer. (On Ubuntu, you will want to install the dnsmasq-base package.
  2. Make sure your WAN connection (i.e. Internet-connected connection) is all configured (e.g. with DHCP or a static address) and working.
  3. For your LAN interface (which might be a second network card or a wireless card), select “Shared to other computers” in the IPv4 Settings tab.

NetworkManager doing sharing

If everything works right, NetworkManager should have auto-configured a subnet and DHCP server on your LAN interface, and is ready for sharing your Internet connection. Easy peasy!

53 replies

  • Sven says:

    All sorted. It was a misunderstanding of how to connect to the adhoc network again after a reboot.

    I setup IPs manually and it worked fine. after the reboot, it suddenly fired up the DHCP server.

    To get it working, reboot your ubuntu machine and then select “Create New Wireless Connection”. Select your previously created Adhoc Wireless Network from the dropdown and voila — all working.
    (makes more sense when you have an Ubuntu box in front of you).

    For info, I was using the Netbook version of 10.04

    • Jeremy says:

      Glad you got it working. Yeah, ad-hoc networks are a pain in NetowrkManager, I’ll give you that — they’re also very fiddly and unreliable sometimes.

  • Mr T says:

    How can I know (get a list) of all the computers who are connected at the moment through my network manager? can I see who made a dhcp request? can I see who is surfing in the internet right now? I can use somthing like “iftop”, but is there anything built in networkmanager to monitor that?

    • Jeremy says:

      You can’t get a list from NetworkManager itself, as it doesn’t actually handle the DHCP.

      dnsmasq is what handles the DHCP serving, and there is no way to query the list of DHCP clients, as this page alludes to. However, if you grep your syslog, you should be able to find entries from dnsmasq that give away clues.

  • buckett says:

    Hi, I’m really glad I found your short tutorial, because I was not having any luck with any of the others I had found. This seems very promising, as I actually get a response from the machine, but when I plug into my switch from my computer, the notifications at the top of my screen flash that the wired network is connected then disconnected, over and over. Any advice?

  • James says:

    DNSMASQ and DNSMASQ BASE are installed but the shared Ethernet port starts disconnecting and re connecting as soon as I set it to shared to other computers. I read something about this about a year ago as I started trying to share my INTERNET connection on my network. There is something more to be installed but I don’t recall what it is.
    Also remember to turn off DHCP in any wireless router in your network as your ubuntu gateway wants to hand out IP addresses.
    You may also have a IP conflict with the wireless router as they like to have the address just like the ubuntu Ethernet port.

  • Patrick Bateman says:

    I am sharing a wifi connection like this – any ideas on how to get Ubuntu to remember that eth0 exists even when the device at the other end of eth0 is off? At the moment when that device (a PS3) is off, eth0 disappears from network manager. This creates problems with applications (e.g. PS3 Media Server gets confused and starts sharing to wlan0 instead of eth0).

  • Ron Swanson says:

    I’m trying to bridge the connection that I’m getting from the wlan0 to share internet with one computer connected to eth0, First, would this be the method I would use for doing this? Also, my laptop is running ubuntu 12.04 LTS.

    • Jeremy says:

      You cannot do this (bridge wireless/wired under a single br0), due to limitations of the 802.11 specification. Vendors such as Ubiquiti resort to layer-2 based NAT (called ARPNAT) to achieve this in their products.

      (In Ubiquiti products, you can enable a feature called “WDS” which doesn’t require layer-2 based NAT, but does break the 802.11 standards in doing so.)

      The technical reason behind this is that the 802.11 spec only allows one station MAC address, but two access point MAC addresses. Therefore you cannot have more than one MAC address behind the station, and as such does not work for an Ethernet bridge.

      Your only choice is to NAT.

  • […] Jeremy Visser: Simple Internet connection sharing with NetworkManager […]

Leave a reply

Change your avatar.