You are on page 1of 5

Connectify for Linux Wireless Hotspot | The ...

http://pritambaral.com/2012/05/connectify-for-lin...

The NitWit Express


Connectify for Linux Wireless Hotspot
Dont be confused, the popular wireless hotspot creation tool for the popular windows platform is not coming to Linux, at least not at the time of writing this. However, there are many open source tools to set-up and manage a wireless AP (Access Point.) One of them is hostapd, which I used, and shall be elaborating below. Requirements: Linux A supported Wireless card (more on this later) (wlan0 in my case, and in the discussions below) A LAN/PPPoE connection to share internet from (eth0 in my case, and in the discussions below) a dhcp server iptables (it should already be present on linux, but if your OS doesnt have it, get it from your distro) hostapd (Your distributions package, or compiled from sources: http://linuxwireless.org/en/users /Documentation/hostapd, http://w1.fi/hostapd/) Wireless card: Before we proceed, we must verify if your card supports AP mode, and the driver and hostapd can talk to each other. Switch on your wireless card first (obviously!) and run this command: iw list In among the many lines output, we need to see if the following lines are present: Supported interface modes: * IBSS * managed * AP * AP/VLAN * WDS * monitor Specifically, we are looking for AP among the Supported interface modes. If your card supports it, yay, you may create a hotspot! But wait. hostapd needs more than just that. We need a driver for hostapd (yes,

1 of 5

Sunday 29 September 2013 12:00 PM

Connectify for Linux Wireless Hotspot | The ...

http://pritambaral.com/2012/05/connectify-for-lin...

its own driver!) The most favorable among them is the nl80211 driver. To see if its supported, run: lsmod | grep 802 If the output contains cfg80211 and mac80211, congrats, you are lucky enough to use hostapd! (There are other drivers too, if this doesnt work. But if you have a broadcom wireless card and it fails the test above.. Well, you may look at the alternatives at the bottom.) UPDATE: Certain cards are known to be bad, like the Broadcom BCM4313, Intel Centrino series. Atheros chips seem good, till now. Do tell me if you manage to somehow get the aforementioned bad chips working. Hostapd Now that your card has passed the tests of fire and lighting, lets get started on that hostapd thingy. Install it from your distributions repo, or compile it yourself (I recommend compiling.) Hostapd is configured using a file (surprise, surprise!) http://linuxwireless.org/en/users/Documentation /hostapd#Configuring_hostapd has a detailed explanation of terms in the config file, nevertheless, Im including the configurations I use: interface=wlan0 driver=nl80211 ssid=<WiFi-Name> country_code=US hw_mode=g channel=1 macaddr_acl=0 wpa=2 wpa_passphrase=<at-least-8-letter-long-passsword> wpa_pairwise=TKIP CCMP Options of note: channel, hw_mode, ssid, and passphrase can be customized. I used g for hw_mode coz thats the highest my card supports, but yours might support n too, in which case you better use that, its faster! (How to know? The card makers must have flaunted it somewhere.. a/b/g ?) Also, hostapd supports a wide range of authentication mechanisms: WPA2, WEP even RADIUS! http://w1.fi/hostapd/ has the full list UPDATE: It seems Ubuntus packaging isnt quite clear where to put this file.. My suggestion: save hostapds config at /etc/hostapd/hostapd.conf and edit the following line in /etc/init.d/hostapd to match as given: DAEMON_CONF=/etc/hostapd/hostapd.conf

2 of 5

Sunday 29 September 2013 12:00 PM

Connectify for Linux Wireless Hotspot | The ...

http://pritambaral.com/2012/05/connectify-for-lin...

DHCP Now this is not really that important, but if you want your clients to have a smooth experience connecting to your WiFi, this can come in handy. If you dont know what DHCP is, its the one that assigns network addresses so you wont have to fill the IP, netmask, gateway etc. manually on every device. DHCP servers vary across distributions. My distro, Arch Linux, has a package dhcp4 that does the job for me. Newer Ubuntus have isc-dhcp-server, older have dhcp-server or something of that sort. The configuration file format is mostly same across distros though: default-lease-time 3600; max-lease-time 9000; authoritative; log-facility local7; subnet 192.168.0.0 netmask 255.255.255.0 { interface wlan0; range 192.168.0.2 192.168.0.255; option domain-name-servers 10.200.1.11; option routers 192.168.0.1; option broadcast-address 192.168.0.0; } This creates a Wireless LAN on the range 192.168.0.1-192.168.0.255, with my Vaio acting as the router for them. For this to work, my own wifi interface (, generally wlan0,) needs to have 192.168.0.1 as its IPv4 address. Which means, before the dhcp server is started, and before hostapd can play with the wlan0 interface, it needs to be assigned 192.168.0.1. IPTABLES Did I say my Vaio acting as the router? Router? Yeah, you need some kernel magic for that. Dont worry, its pretty simple, and just three lines! sudo sudo sudo sudo sudo iptables -D FORWARD -i wlan0 -j ACCEPT iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE sysctl -w net.ipv4.ip_forward=1 iptables -A FORWARD -i wlan0 -j ACCEPT iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

I said three right? Chill brah, the top two are just for being safe, you can skip it, but I wouldnt recommend it, for reasons cited below.

3 of 5

Sunday 29 September 2013 12:00 PM

Connectify for Linux Wireless Hotspot | The ...

http://pritambaral.com/2012/05/connectify-for-lin...

Putting it all together: So, our plan of action should be as follows: 1. Stop DHCP server if already running, and Hostapd too! 2. Bring down the wlan0 interface, it might be serving some different purpose already. (When I say bring down I mean in software, remember ifconfig?) 3. Remove our hotspot specific iptables rules, if already present (from a previous run, or something else, we dont want duplicate rules, do we?) 4. Enable ip_forward in the kernel 5. Set iptables rules for us to work as a router 6. Start hostapd 7. Start dhcp server Thats it! Heres a handy dandy script I use in Arch Linux, but you can modify it to suit your distro of choice #!/bin/bash # WiFi HotSpot sudo sudo sudo sudo sudo sudo sudo sudo sudo sudo sudo rc.d stop dhcp4 rc.d stop hostapd ifconfig wlan0 down iptables -D FORWARD -i wlan0 -j ACCEPT iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE ifconfig wlan0 192.168.0.1 netmask 255.255.255.0 up sysctl -w net.ipv4.ip_forward=1 iptables -A FORWARD -i wlan0 -j ACCEPT iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE rc.d start hostapd rc.d start dhcp4

Ubuntus equivalent of rc.d start <whatever> is service <whatever> start. Also, I have init scripts for both hostapd and dhcp4, you will have them too if you installed the packages; but if you compiled them, use whichever method you like to start and stop them. Alternatives: Hostapd has quite a few alternatives. Some even support web-based authentication! i havent used any; thankfully my Atheros card on my Vaio works so well with hostapd. But if anyone wants to look into hostapds alternatives, heres a list:

4 of 5

Sunday 29 September 2013 12:00 PM

Connectify for Linux Wireless Hotspot | The ...

http://pritambaral.com/2012/05/connectify-for-lin...

http://wiki.openwrt.org/doc/howto/wireless.hotspot
Like 3 1 Tweet 3

5 of 5

Sunday 29 September 2013 12:00 PM

You might also like