Thursday, May 12, 2011

How to share 3G internet in a local area network

Let's аssume that you have a computer connected to the Internet via 3G modem, and you want to share it to another computer connected in a Ethernet local network.

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 Internet
eth0 - connected to LAN

and eth0 in PC2

Customize PC1

Set up the Ethernet card (eth0) as follows:
or type in the console:
ifconfig eth0 netmask
ifconfig eth1 up

Allow the packets

To do this, edit /etc/sysctl.conf: insert a line
net.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

Netmask / Mask:
Gateway / Gateway:

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)

1 comment:

  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.