Skip to content

Instantly share code, notes, and snippets.

@Semant1ka
Last active October 22, 2024 10:11
Show Gist options
  • Save Semant1ka/ee087c2bd1fbf6b0287c3307b8d4f291 to your computer and use it in GitHub Desktop.
Save Semant1ka/ee087c2bd1fbf6b0287c3307b8d4f291 to your computer and use it in GitHub Desktop.
How to set up WiFi hotspot and troubleshoot WiFi problems on Debian

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)

How do I know that my WiFi adapter supports AP mode?

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

Okay, WiFi supports AP mode but not working!

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.

Dealing with 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.

  1. 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

  2. Restart Network Manager

     sudo service network-manager restart
    
  3. Open Network Manager GUI and check that you can't manage device your device

Now we can continue with hotspot set up.

Setting up WiFi hotspot with hostapd

  1. Install hostapd utility

    sudo apt-get install hostapd
    
  2. Create hostapd.conf in /etc/hostapd

    touch /etc/hostapd/hostapd.conf
    
  3. Add lines below to hostapd.conf. Meaning of most of them is obvious

    interface=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.

  4. 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.
      nl80211: Could not configure driver mode
      nl80211 driver initialization failed.
      hostapd_free_hapd_data: Interface wlan0 wasn't started
      
      Check that hostapd is already running in the system.
      ps ax | grep hostapd
      
      If command above returned anything stop the service.
      sudo /etc/init.d/hostapd stop
      
      or
      sudo service hostapd stop
      
    • WiFi interface was soft blocked
      Configuration 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
      
      This problem was described in the beginning of the article, so try running
      sudo rfkill unblock wlan
      
      Also you can try restarting WiFi
      sudo nmcli radio wifi off
      sudo nmcli radio wifi on
      

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

Setting up DHCP

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.

Check this good article for more info about DHCP

@kimfom01
Copy link

Thank you for providing this comprehensive guide.

Is there a way to revert the changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment