Introduction

It is easy to setup ad-hoc wifi router in Linux. The problem is, many devices e.g Android (currently) can not connect to it. Network Manager 0.9.8 brings AP-mode Hotspot. However, since it is not integrated into nm-applet or other easy tools, we will still have to wait some time for a seemless experience. Until then, we will have to rely on hostapd software.

Is your hardware supported ?

According to linuxwireless.org

As far as Linux is concerned, out of the old drivers you can only use HostAP, madwifi, prism54 drivers with hostapd. All new mac80211 based drivers that implement AP functionality are supported with hostapd’s nl80211 driver. Userspace programs like hostapd now use netlink (the nl80211 driver) to create a master mode interface for your traffic and a monitor mode interface for receiving and transmitting management frames.

Enough theory. You can find out if your card falls under one of these categories using following command.

In this particular example, I used DSL internet available through ppp0 as the source. If you have some other devices or interface that you want to use (e.g eth0 in case of direct connection) as the internet source, change ppp0 to appropriate device interface in all three places in above file. Make sure the essid matches the name that we used in /etc/hostapd/hostapd.conf, and finally the kernel module we discovered above for wifi (iwlwifi in this case) .

Note: Don’t forget to make this file executable using “chmod +x command”

$ chmod +x ~/bin/connecthostapd

For the sake of completion (dhcp), I suggest you restart your computer this one time.

From now on, you just have to remember only the last file. If you have been browsing the internet using wifi, and decide to use it as a router, you just need to disconnect wifi (don’t turn off), and run above file as root. Which would be something like this.

$ sudo ~/bin/connecthostapd

You can now connect to this device as a normal wifi. To disconnect, simply type “Ctrl + c ” in the terminal where connecthostapd is currently running.

Note: Due to its limitations (in my case) on failing to keep the connection for long time, this is not going to be a replacement for wifi router, in some of your cases. However in situations where wifi does not work, and you want to update some internet related services on devices that depend on wifi (e.g Android) you can do it easily, with above setup.

Conclusion

Sharing internet through wifi has recently got much attention. As a result, most newer hardware support this feature. Hope it works for you. One problem I have to note though is, the performance is rather limited than a dedicated wifi router.

Which would mean, that my card doesn’t support an AP mode. Also, following your post I have this error when trying to run hostapd:

wojtek@msi ~ $ sudo hostapd ~/hostapd-test.conf
Configuration file: /home/wojtek/hostapd-test.conf
Failed to update rate sets in kernel module
Could not connect to kernel driver.
Using interface wlan0 with hwaddr 00:1e:64:55:76:84 and ssid ‘testhostapd’
random: Only 18/20 bytes of strong random data available from /dev/random
random: Not enough entropy pool available for secure operations
WPA: Not enough entropy in random pool for secure operations – update keys later when the first station connects
Failed to set beacon parameters
Could not connect to kernel driver.

Do you have a clue what I’m doing wrong? I tried on Windows and my card can serve as AP there (using Connectify).

I don’t have a definite answer, but could you set different modes in the iwconfig command in the script. Could you try using “iwconfig wlan0 mode ad-hoc” from Morten Slott Hansen’s answer. Though, the whole point of this article was to avoid using ad-hoc (but since it works for Morten, may be it will work for you too). Looking at link 1 and link 2, I think it is mode problem. To find out different modes run “man iwconfig” and see the mode section.

Yes, apparently master mode is not supported. I can’t use ad-hoc mode (although it works), because my android device doesn’t show ad-hoc networks. Well, guess I’ll have to stick to windows then for these rare times I need wifi.

I had same problem (ad-hoc not supported in android). It looks like android 4.2 has ad-hoc support (http://www.networkworld.com/community/blog/why-android-422-important-update). Looking at this and this it looks like you need to have both master mode and ap for hostapd. This is the place to download the driver and copy it to /lib/firmware (if something has changed). Since you said it works in windows, you might have to investigate how it works in windows (what modes are used). E.g Do you need to specify specific frequency as Morten Slott Hansen did? Other than that, I don’t think I have any good answer.