How to forward an Internet connection to another network?
This is how I worked it out...
- Create a new wireless network (aka hotspot) using the network manager.
- Enable IP forwarding by executing the command below:
echo 1| sudo tee /proc/sys/net/ipv4/ip_forward
- Identify the device which connects your computer to Internet, by using ifconfig command. (My one is ppp0, because it has an IP address.)
- Finally tell iptables to forward ppp0's internet traffic to everywhere!
sudo iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE
Disconnect & reconnect the Wifi connection(Hotpsot) you made earlier.
Internet should be flowing to the wireless network now!
If you did it correctly, the output of sudo iptables -L should be similar to this:
Chain FORWARD (policy ACCEPT)
target.....prot opt.....source....................destination
ACCEPT.....all ---........ anywhere.............10.42.43.0/24.........state RELATED,ESTABLISHED
ACCEPT.....all ---........ 10.42.43.0/24......anywhere
An external guide is available here.
Thanks to web-E...!
Related videos on Youtube
Naveen
Updated on September 18, 2022Comments
-
Naveen almost 2 years
Can somebody please make a short & sweet tutorial telling how to forward an Internet connection to different network interfaces in Ubuntu...?
This is the idea:I'm using a 3G usb modem to get Internet on my laptop ,which is:
ppp0 IP=10.225.174.70
My Wifi device is:
wlan0 MAC=78:e4:00:d4:3d:85
These devices are determined from ifconfig command.
I want to share ppp0's internet connection with wlan0 device, so I can connect any other device to wlan0 and browse internet from that device.
Making a Hotspot using Network settings GUI doesn't do the trick because the other device won't receive Internet, it just connects to wlan0.
I heard iptables can do this, but I'm totally confused by the alien commands seen online. I'm no expert in networking. Please compose a clear & simple answer using the above devices. This is a huge annoying problem for iPhone & tablet users came to Ubuntu from Windows.
-
Web-E almost 12 yearsI have already written a tut , hopefully this will solve your doubts. This tut is for setting up wi-fi access point. You can jump to
Setup internet connection settings
area -
Web-E almost 12 yearsSee the tut was for creating wireless access point. You can create adhoc network and share it. See the
Setup internet connection settings
- this section does the forwarding. You can look here, a simpler step by step info.
-
-
Naveen almost 12 yearsSorry it doesn't work, because I'm using a usb modem..
-
Naveen almost 12 yearsIt doesn't matter if my ip gets shared.
-
ElMudo over 11 yearsno matter if you use usb modem. the ip which is the other must share the outgoing exit either lan or wlan
-
Manny265 over 8 yearsworked like a charm. I just exchange ppp0 to eth1 (my usb modem) and the network to my local address. thanks