How to share internet with just 3 simple commands.

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
Galbi
Posts: 1098
Joined: Wed 21 Sep 2011, 22:32
Location: Bs.As. - Argentina.

How to share internet with just 3 simple commands.

#1 Post by Galbi »

How to share internet with just 3 simple commands.
(Versión en español al final).

The basic idea is to provide internet to another PC with just 3 commands without using a proxy.

The net architecture is this:

PC-1: Running Puppy Linux (or any other Linux).
* Two net interfaces:
- wlan0: Wifi interface that recives internet from a wifi router.
- eth0: Wired net interface which bounds to PC-2.

PC-2: Running whatever O.S. (even , Windows).
* Just one net interface:
- eth0: wired net interface that bounds to PC-1.

Wifi router:
* The router must have DHCP ON (that is, automatically supplies net parameters when is asked to).

Schematically is like this:

Router| )))((( | wlan0 PC-1 eth0|-------UTP wire-------------|eth0 PC-2 |


In PC-1 we should be able to surf internet via wifi as normal, now let's see the configuration of the net interfaces:

PC-1: -wlan0: gets its ip and other parameters by DHCP (i.e. 192.168.1.102 to know this we must use the command #ifconfig in one terminal).
-eth0: we must provide an static ip (192.168.1.10 netmask 255.255.255.0).

PC-2: -eth0: we must provide an static ip (192.168.1.40 netmask 255.255.255.0 gateway 192.168.1.102).

Here is important to note that the Gateway of PC-2, is the ip of the wifi interface of PC-1.

Now, in PC-1, we run this 3 simple commands in one terminal:

Code: Select all

#modprobe iptable_nat
#iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
#echo 1 > /proc/sys/net/ipv4/ip_forward

At this point, we should be able to surf internet in PC-2 without problems.

Some notes:

-IMPORTANT: PC-1 must have disabled any firewall (if has one).
-Either, ip values and net interfaces names shown here are just an example and may vary from one sistem to another.
-The UTP wire that bounds both PCs could be direct if, at least, one of the net interfaces is fairly modern and of Gigabit type. If both net interfaces are rather old, in that case, it must be a crossover wire. We must ensure that both PCs "see" each other through the UTP wire pinging from one to the other (being in PC-2 we should do #ping 192.168.1.102 and #ping 192.168.1.10 and in both cases we must see that the connection is right).


(Critics, suggestions, correction are welcome. Here, or to gaenal[at]gmail.com)
-----------------------------------------------------------------------------------------------------

Cómo compartir Internet con 3 simples commandos.

La idea básica es proveer internet a otra PC con sólo 3 comandos y sin utlizar un proxy.
La arquitectura de red es la sgte:

PC-1: Corriendo Puppy Linux (o cualquier otro Linux).
* Dos placas de red:
- wlan0: Placa wifi por la que recibe internet inalámbrica desde un router (wifi, obviamente).
- eth0: Placa de red cableada que se conecta a la PC-2.

PC-2: Corriendo cualquier S.O.
* Una única placa de red:
- eth0: Placa de red cableada que se conecta a la PC-1.

Router Wifi:
* El router tiene DHCP ON (o sea, suministra los parametros de red automaticamente cuando se le solicita).

Esquematicamente sería así:

Router| )))((( | wlan0 PC-1 eth0|------cable UTP--------------|eth0 PC-2 |


En la PC-1 deberíamos poder navegar por internet via wifi normalmente, ahora veamos como quedaría la configuración de las interfaces de red:

PC-1: -wlan0: toma la ip y otros parámetros por DHCP (p.ej 192.168.1.102 ésto se averigua con el comando #ifconfig en una consola).
-eth0: le asignamos una ip estática (192.168.1.10 netmask 255.255.255.0)

PC-2: -eth0: le asignamos ip estática (192.168.1.40 netmask 255.255.255.0 gateway 192.168.1.102).

Observese que lo importante aquí es que la Puerta de Enlace(gateway) de la PC-2, es la ip de la placa wifi de la PC-1.

En la PC-1 corremos éstos 3 simples comandos en una consola:

Code: Select all

#modprobe iptable_nat
#iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE          
#echo 1 > /proc/sys/net/ipv4/ip_forward
y ahora la PC-2 debería poder navegar sin problemas.


Algunas aclaraciones:
-IMPORTANTE: La PC-1 debe tener deshabilitado el firewall (si es que lo tiene).
-Tanto los valores de ip como los nombres de las interfaces de red aquí consignados, son sólo a modo de ejemplo y pueden variar de un sistema a otro.
-El cable UTP que une ambas PCs puede ser directo si una de las placas es medianamente moderna y es del tipo Gigabit. Si ambas placas son mas antiguas entonces debe ser un cable cruzado. Se debe corroborar que ambas máquinas se "vean" via el cable UTP haciendo ping. (estando en la PC-2 debemos poder hacer #ping 192.168.1.102 y #ping 192.168.1.10 y en ambos casos debe haber conexión).


(Críticas, sugerencias, correcciones son bienvenidas. Aquí ó a gaenal[at]gmail.com)

Post Reply