I have two wired connections of which the first has internet via static IPv4 and gateway and the second connects to another network.
I want to share internet from first connection over second connection with a different IP-address.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
I managed to solve this myself. Here are the steps:
eth0 configured like this
eth1 configured like this:
Open terminal and run:
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward' sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT sudo bash -c 'iptables-save > /etc/iptables/rules.v4' sudo bash -c 'iptables-restore < /etc/iptables/rules.v4'
/etc/sysctl.conf (for example using
sudoedit /etc/sysctl.conf) and search for the following lines:
# Uncomment the next line to enable packet forwarding for IPv4 #net.ipv4.ip_forward=1
net.ipv4.ip_forward=1 by removing the
# at the start of the line:
# Uncomment the next line to enable packet forwarding for IPv4 net.ipv4.ip_forward=1
Or, to do this in a one line command:
sudo sysctl -w net.ipv4.ip_forward=1
You could've done it easier than this. If your internet connection is established via some sort of routing device you can just make a VLAN for the connection you want to share internet with to make it to have access to the router subnet.
You can do this in Network Manager GUI easily. Afaik it is available outta box.
Parent device is the interface you want to share internet with. After that go to IPv4 settings and set an IP address for it from the router DHCP range. Voila. You got yourself a shared internet connection.