The scheme of the connection will be like this:
Internet ---> | PC1 (the gateway) | ---> PC2 (switch) .. etc
Initial conditions:
Both computers are connected over a network.We have 3G modem and Ethernet network card in PC1 :
ppp0 - connected to Interneteth0 - connected to LANand
eth0 in PC2Customize PC1
Set up the Ethernet card (eth0) as follows:IP: 192.168.0.1
Netmask: 255.255.255.0
or type in the console:
ifconfig eth0 192.168.0.1 netmask 255.255.255.0ifconfig eth1 upAllow the packets
To do this, edit/etc/sysctl.conf: insert a linenet.ipv4.ip_forward = 1Run the following line in the terminal:
sudo sysctl-w net.ipv4.ip_forward = "1"in order to apply this rule before reboot.
Install iptables.
sudo apt-get install iptablesType the following rule (for the transfer of Internet second computer) and save it.
iptables-t nat-A POSTROUTING-o ppp0-j MASQUERADEInstall
dnsmasqsudo apt-get install dnsmasqRun it:
sudo service dnsmasq startCustomize PC2
IP:192.168.0.2Netmask / Mask:
255.255.255.0Gateway / Gateway:
192.168.0.1DNS:
192.168.0.1Now the second computer should now be connected to the Internet.
If after restarting iptables rules are not restored, add
iptables-t nat-A POSTROUTING-o ppp0 -j MASQUERADEin any startup script (rc.local for example)