How do I share my Ubuntu's Internet connection with a LAN (via hardware router)
I know this sort of question has been asked many times, and I've thus tried many ways to get it working, but I think my setup is a bit different from what I've seen others trying. I've got an Ubuntu box with a usb mobile broadband modem that connects me to the Internet, and I'm trying to share this Internet connection with an ordinary linksys router (WRT120N), and thereby with my wifi LAN. I've connected my Ubuntu box to the router via ethernet, but don't know how to get the router to use my Internet connection. Maybe this is more of a problem with the router configuration, but I tried creating a new wired connection in Ubuntu and selecting "Shared to Other Computers" under method, which seems useless.
Is there some easy way to make the router use the Internet connection used by the Ubuntu box for the LAN?
53 Answers
Here's how I did it:
Equipment:
Ubuntu 11.04 Desktop on 1st Gen. eeePC
Linksys WRT120N Wireless N Router
Huawei E620 USB Broadband Modem
Ethernet cable
Hardware Setup:
Huawei plugged into eeePC
Ethernet cable plugged into Ethernet port
other end of Ethernet cable plugged into the
Internetport of The Linksys
Ubuntu Setup:
- connect the Huawei to the Internet
- disconnect the wired connection (Auto Eth0) in network tray icon
- create new wired connection (Edit Connections... > Add, enter a name) and select
Shared To Other Computersfrom IPv4 settings tab. - connect to this new wired connection
- note down the settings for this connection under
Connection Information, and the DNS servers for the Huawei connection
Linksys Setup:
- connect a computer on the receiving side to the Linksys (wired or wireless)
- open a browser in this computer, navigate to Linksys (
192.168.1.1is default, user and password should be both admin) - Change
Internet Connection TypetoStatic IP - Under
Internet IP AddressI put the number that came after the eeePC's IP address for this connection (again, not the IP for the Huawei connection), this was just a guess as I'm pretty clueless about how this works. So, my Ubuntu machine had an IP of10.42.43.1, and I gave the Linksys10.42.43.2 Subnet Maskshould be same as the eeePC,255.255.255.0Default Gatewayshould be the eeePC's IP address,10.42.43.1in my case.DNS 1(etc.) should be the same as thePrimary DNS(etc.) used by the eeePC in the Huawei connection.- Click
Save Settings.
And now all machines on my LAN can connect to the eeePC's Internet via the linksys router. All is well.
1It's very easy. I use Norwegian, so the translations might not be correct, but I hope and believe you'll understand.
Click on the network icon and select "edit connections". Select wired connections in the first tab and select your network, usually something like "Auto eth0". Click the edit button on the right and in the new window, look at IP settings. There is a combobox there where you can choose "method" that includes DHCP, Static and Shared with other computers, among others. Choose "shared with other computers".
Now, simply connect your wired network connection on your PC to the uplink-port on your router (usually called WAN).
Finished. :)
2For Ubuntu 19.04, based on the answers provided by yuttadhammo and MountainX:
assuming you have a WiFi connection to internet and a LAN port on your laptop and a wireless router with an internet LAN port. Connect the Laptop's LAN port to the internet port of the Router using the routers LAN cable.
The challenge is that we are going to have a WiFi connection to the internet and our WiFi device on the laptop cannot become a hotspot and cannot connect to the WiFi of the router at the same time.
1- in Ubuntu, you need to run:
sudo apt-get install net-tools2- run
nm-connection-editor3- under ethernet I made a new one. In the tabs, IPv4 and IPv6, chose shared with other computers.
4- connect to the WiFi internet and make sure it works.
5- Ctrl+Alt+T opens terminal. Type down:
ifconfig6- notice the ip address and the Mask that your ethernet has. Also notice the name that it has chosen for you WiFi connection. Mine was wlp8s0, now type down the following to get the DNS address:
nmcli device show wlp8s0 | grep IP4.DNSNow you are ready to disconnect WiFi from the internet and connect to the wireless router to set it up according to yuttadhammo.