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.0
ifconfig eth1 up
Allow the packets
To do this, edit/etc/sysctl.conf
: insert a linenet.ipv4.ip_forward = 1
Run 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 iptables
Type the following rule (for the transfer of Internet second computer) and save it.
iptables-t nat-A POSTROUTING-o ppp0-j MASQUERADE
Install
dnsmasq
sudo apt-get install dnsmasq
Run it:
sudo service dnsmasq start
Customize PC2
IP:192.168.0.2
Netmask / Mask:
255.255.255.0
Gateway / Gateway:
192.168.0.1
DNS:
192.168.0.1
Now 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 MASQUERADE
in any startup script (rc.local for example)
Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
ReplyDelete