Compartilhar internet por Ad-Hoc

March 17, 2011    Ad-Hoc Internet Rede Wireless

  • No Computador1, ligado à internet por cabo:

    # ifconfig wlan0 down
    # iwconfig wlan0 mode Ad-Hoc
    # ifconfig wlan0 192.168.0.1 up
    # iwconfig wlan0 essid rede
    # iwconfig wlan0 key 123456789A
    
  • No Computador2:

    # 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"
    

A rede Ad-Hoc já está configurada. Você já pode enviar ping entre ambas as máquinas.

Para compartilhar a internet, precisamos adicionar algumas regras ao firewall.

  1. Instale o iptables:

    # pacman -S iptables
    
  2. Configure o 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
    


comments powered by Disqus