Last week, I was snowboarding with my family in Scheffau, Austria. In the appartment, there was one single cat-5 cable, while 5 of us wanted to use the internet. So I figured out how to build a ad-hoc wifi network with my laptop in order to share the network connection.
My configuration
On my laptop, I'm running Fedora 13 with dnsmasq installed. All other software is pretty standard. My wifi driver creates a wlan0, but other laptops may create wmaster0 interfaces etcetera.
Step 1: Enable routing
We set up IP forwarding:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -I FORWARD -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
For a permanent situation, you may want to be a little more picky in what to forward and what not.
Step 2: Set up the wifi
First, we switch from managed mode to ad-hoc mode:
/sbin/iwconfig wlan0 mode Ad-Hoc
Then we choose a name for the new network. I chose my own name:
/sbin/iwconfig wlan0 essid "David"
I use WEP, which is pretty insecure, but is just good enough to keep neighbours from connecting by accident. (I would not use this for a network that stays up for more than an hour.):
iwconfig wlan0 key 1351351350
And we set the wifi channel to "automatically select a channel":
iwconfig wlan0 channel auto
Step 3: Configure the network
Then we must configure an IP. Since 192.168.0.0/16 and 10.0.0.0/8 are mostly used in ADSL environments, I use the third IANA assigned block: 172.16.0.0/12 (172.16.0.0-172.31.255.255):
ifconfig wlan0 172.31.1.254 up
And allow incoming DHCP/DNS requests:
iptables -I INPUT -m udp -p udp --dport 67 -j ACCEPT
iptables -I INPUT -m udp -p udp --dport 53 -j ACCEPT
Then, finally, we start dnsmasq as a DHCP/DNS server:
dnsmasq --no-daemon --domain-needed --bogus-priv --interface=wlan0 --bind-interfaces --dhcp-range=172.31.1.50,172.31.1.100,12h --dhcp-option=option:router,172.31.1.254 --dhcp-authoritative --log-queries --log-dhcp
Step 4: Have fun!
We're done. Other laptops can now connect to your network and you're forwarding their packets.
© GeekLabInfo Use your laptop as a wifi router is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info