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.
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.
I managed to solve this myself. Here are the steps:
eth0
configured like this
ipv4=85.185.254.69,255.255.255.0,85.185.254.66,dns=4.2.2.4.
eth1
configured like this:
ipv4=185.185.185.1,255.255.255.0,85.185.254.69.
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'
Edit /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
And uncomment 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.
Step 2: Confitgure other computers on this network and test/ping. They will use NIC2 on computer 1 (185.185.185.1) as gateway.
Step 3) Now you need to forward packets between the two interfaces. Your computer does this based on its routing table. If that does not for check if ipforwarding is enabled. (sysctl net.ipv4.ip_forward should return 1. If it returns 0 then use
– Hennes Jun 07 '15 at 14:08echo 1 > /proc/sys/net/ipv4/ip_forward
orsysctl -w net.ipv4.ip_forward=1
).MASQUERADE
when you seem to have regular puplic IPs? – Hennes Jun 07 '15 at 17:41