There are a few decent tutorials on how to setup hotspot on Linux, which I will share below, but this tutorial will focus on adversities that you without doubt will face while setting up your AP.
For AP setup we will need:
- Hostapd utility
- Some dhcp utility
- A bit of patience (that was for my case)
In terminal type sudo iw list
this command will show info about your wifi interfaces. Look for Supported interface entry, if AP
is in it, that means your Wifi devices support hotspot mode.
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point
* P2P-client
* P2P-GO
Running sudo rfkill list
usually the first thing I was running to troubleshoot WiFi.
Command will output something like this:
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: yes
1: acer-wireless: Wireless LAN
Soft blocked: yes
Hard blocked: no
hard blocked
Usually means that you are screwed WiFi is disabled physically.
- Try toggle WiFi button
- Try enabling WiFi in BIOS
There is a chance that your Linux drivers can't handle WiFi button events properly, so try booting into Windows and enable WiFi from there.
soft blocked
Means that some software is blocking WiFi interface.
- In most cases you can solve this by running
sudo rfkill unblock %blocked_device_name_as_listed_in_rfkill_list%
- If solution above not working consider checking for a driver problem, see link for more details.
- If the problem persists after every reboot consider removing your WiFi interface from Network Manager.
Network Manager is a super annoying service that is aimed to automate network configuration, unfortunately it might also cause problems with networking. At the sight of any uneven issues perform the steps below to remove your interface from Network Manager.
-
Open
/etc/NetworkManager/NetworkManager.conf
and add lines[main] plugins=ifupdown,keyfile [ifupdown] managed=false [keyfile] unmanaged-devices=mac:ff:ff:ff:ff:ff:ff
instead of mac:ff:ff:ff:ff:ff:ff type in your real device mac
-
Restart Network Manager
sudo service network-manager restart
-
Open Network Manager GUI and check that you can't manage device your device
Now we can continue with hotspot set up.
-
Install hostapd utility
sudo apt-get install hostapd
-
Create
hostapd.conf
in /etc/hostapdtouch /etc/hostapd/hostapd.conf
-
Add lines below to
hostapd.conf
. Meaning of most of them is obviousinterface=wlan0 channel=6 ieee80211n=1 hw_mode=g ssid=TEST wpa=2 wpa_passphrase=p@$$w0rd wpa_key_mgmt=WPA-PSK rsn_pairwise=CCMP auth_algs=1
Be carefull with ieee80211n=1 parameter. In most tutorials you will see driver=nl80211 , but parameter diver didn't work for me, presumably because I have atheros driver, but it might work for you if you have nl.
-
Now you can check if your hotspot works properly run the command
sudo hostapd -d /etc/hostapd/hostapd.conf
-d
enables full command output so if there are errors, you will see them.The issues that you can run into at this point are:
- Hostapd is already running.
Check that hostapd is already running in the system.nl80211: Could not configure driver mode nl80211 driver initialization failed. hostapd_free_hapd_data: Interface wlan0 wasn't started
If command above returned anything stop the service.ps ax | grep hostapd
orsudo /etc/init.d/hostapd stop
sudo service hostapd stop
- WiFi interface was soft blocked
This problem was described in the beginning of the article, so try runningConfiguration file: /etc/hostapd/hostapd.conf rfkill: WLAN soft blocked wlan0: Could not connect to kernel driver Using interface wlan0 with hwaddr ff:ff:ff:ff:ff:ff and ssid "TEST" Failed to set beacon parameters wlan0: Could not connect to kernel driver Interface initialization failed wlan0: interface state UNINITIALIZED->DISABLED wlan0: AP-DISABLED wlan0: Unable to setup interface. hostapd_free_hapd_data: Interface wlan0 wasn't started
Also you can try restarting WiFisudo rfkill unblock wlan
sudo nmcli radio wifi off sudo nmcli radio wifi on
- Hostapd is already running.
If hostapd
started you will see that it is constanly writing log to terminal. You should be able to discover you AP with another device, but you won't be able to connect to it yet.
Now close the window with runnig service and check its status. There are few ways to do this:
sudo services hostapd status
sudo /etc/init.d/hostapd status
If service is stopped you can run it on background as a daemon with one of this commands:
sudo services hostapd start
sudo /etc/init.d/hostapd start
Now you need to make your hotspot give all connected devices IP address for hotspot network. This can be achieved with DHCP service, I prefer isc-dhcp-server
.
- Install isc-dhcp-server
sudo apt-get install isc-dhcp-server
- Open dhcp config
vim /etc/dhcp/dhcpd.conf
. It contains a lot of entries with comments, but in most basic set up you will need to add lines specified below:
ddns-update-style none;
authoritative;
subnet 192.168.0.0 netmask 255.255.255.0 {
interface wlan0; # your interface name here
range 192.168.0.5 192.168.0.8; # desired ip range
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;
}
- Save config and check it with command
dhcpd -t /etc/dhcp/dhcpd.conf
- Start service
service isc-dhcp-server start
and check if devices that are connected to hostpot can obtain IP addresses.
dhcp -t /etc/dhcp/dhcpd.conf
should bedhcp -t -cf /etc/dhcp/dhcpd.conf
so that "/etc/dhcp/dhcpd.conf" is not used as the interface file but as a configuration file (found via https://www.braindisconnect.com/wiki/index.php/Linux_DHCP_Server)