- Connect to the Internet. In this recipe, we are assuming that the primary wired network connection, eth0, is connected to the Internet. Change it according to your setup.
- Using your distro's network management tool, create a new ad hoc wireless connection with the following settings:
- IP address: 10.99.66.55
- Subnet mask: 255.255.0.0 (16)
- Use the following shell script to share the Internet connection:
#!/bin/bash
#filename: netsharing.sh
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -i $1 -o $2 \
-s 10.99.0.0/16 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate \
ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
- Run the script:
./netsharing.sh eth0 wlan0
Here eth0 is the interface that is connected to the Internet and wlan0 is the wireless interface that is supposed to share the Internet with other devices.
- Connect your devices to the wireless network you just created with the following settings:
- IP address: 10.99.66.56 (and so on)
- Subnet mask: 255.255.0.0
To make this more convenient, you might want to install a DHCP and DNS server on your machine, so it's not necessary to configure IPs on devices manually. A handy tool for this is dnsmasq, which performs both DHCP and DNS operations.