Share Internet via Ad-Hoc
-
On Computer 1, connected to the internet via cable:
# ifconfig wlan0 down # iwconfig wlan0 mode Ad-Hoc # ifconfig wlan0 192.168.0.1 up # iwconfig wlan0 essid rede # iwconfig wlan0 key 123456789A
-
On Computer 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"
The Ad-Hoc network is already configured. You can now ping between both machines.
To share the internet, we need to add some rules to the firewall.
-
Install
iptables
:# pacman -S iptables
-
Configure 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