Use your laptop as a wifi router

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 and are mostly used in ADSL environments, I use the third IANA assigned block: (
ifconfig wlan0 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=,,12h --dhcp-option=option:router, --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 You are free to copy materials from, but you are required to link back to

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Leave a Reply