I use Ubuntu 14. I have two interfaces (eth0 and usb0) and two connections with manual settings. I want to use network manager. Eth0 is WAN. How can I create shared connection to other computers? If I create new connection (third one) and use eth0 as interface then it doesn't work. If I open existing connection (eth0) and change method from Manual
to Shared to other computers
then all my settings disappear.
2 Answers
To do it through network manager using gui
dnsmasq-base has to be installed:
sudo apt-get install dnsmasq-base
Remove dnsmasq because it conflicts with NetworkManager:
sudo apt-get remove dnsmasq
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:
Install dnsmasq on your computer. (On Ubuntu, you will want to install the dnsmasq-base
package. (apt-get install dnsmasq-base
is the easiest way)
Make sure your WAN connection (i.e. Internet-connected connection) is all configured (e.g. with DHCP or a static address) and working. Basically, make sure you can pull up web pages.
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.
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.
To do it through terminal
It's very simple to masquerade (internet connection sharing in Windows language ) on Linux with a few lines of iptables and ip_forward commands. First of all you have to flush and delete existing firewall rules. So flush rules by typing in terminal:
iptables -F
iptables -t nat -F
iptables -t mangle -F
Now delete these chains:
iptables -X
iptables -t nat -X
iptables -t mangle -X
Now it's time to save the iptables rules so type:
service iptables save
service iptables restart
Now all rules and chains have been cleared! Check it in /etc/sysconfig/iptables which has all default rules set to accept. Now open /etc/rc.d/rc.local and insert the line:
echo "1" > /proc/sys/net/ipv4/ip_forward
And then save and close the file. Now asuming that your internet interface is eth0, type:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
service iptables save
service iptables restart
Note: check if iptables is set to start during boot up. Or check the status of your iptables service:
chkconfig –list iptables
If level 5 is on then it's ok othewise start the service at level 5 or level 2345.
Citation:
https://jeremy.visser.name/2009/03/simple-internet-connection-sharing-with-networkmanager/
https://www.howtoforge.com/internet-connection-sharing-masquerading-on-linux

- 378
- 1
- 4
- 17
Since this question appears in the 1st line in google searches, I decided to write here.
As of 2023, under Ubuntu22.04 Sharing network connection to other client devices does work out-of-box, except one thing:
sudo ufw disable
If you don't disable your firewall, your device will get a local IP, and you can SSH between your Host PC and the Client, but the client will not be able to access public internet. Therefore, if we disable firewall, I verified on two different PC, this method works as of 2023.
10.42.0.1
to the shared interface, and then it assigns to other devices on a switch adresses from 10.42.0.255/24 range; if I want instead this connection to be192.168.0.177
and assign addresses in 192.168.0.255/24 range, there is no way to do it in Network Manager. – sdbbs Jan 16 '17 at 09:19