Compartir Internet por Ad‑Hoc

mar. 17, 2011·
Julio Batista Silva
Julio Batista Silva
· 1 min de lectura
  • En el Ordenador 1, conectado a Internet por cable:

     # ifconfig wlan0 down
     # iwconfig wlan0 mode Ad-Hoc
     # ifconfig wlan0 192.168.0.1 up
     # iwconfig wlan0 essid rede
     # iwconfig wlan0 key 123456789A
    
  • En el Ordenador 2:

    # ifconfig wlan0 down
    # iwconfig wlan0 mode Ad-Hoc
    # ifconfig wlan0 192.168.0.2 up
    # iwconfig wlan0 essid rede
    # iwconfig wlan0 key 123456789A
    # route add default gw 192.168.0.1
    # sh -c "echo 'nameserver 8.8.8.8' >> /etc/resolv.conf"
    

La red Ad‑Hoc ya está configurada. Ya puedes hacer ping entre ambas máquinas.

Para compartir Internet, necesitamos añadir algunas reglas al cortafuegos.

  1. Instala iptables:

    # pacman -S iptables
    
  2. Configura iptables:

    # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    # iptables -A FORWARD -i eth0 -o wlan0 -m state --state ESTABLISHED,RELATED -j ACCEPT
    # iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
    # sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
    # /etc/rc.d/iptables save
    # /etc/rc.d/iptables restart
    
Julio Batista Silva
Autores
Senior Cloud Developer
comments powered by Disqus