Wi-Fi AP and hostapd

  • In this section, you are going to learn

  • How to run hostapd in AP mode

#

Version

Ubuntu

Ubuntu 22.04 64 bit

Linux Kernel

6.9.0

Hostapd

Hostapd 2.9

  • STEP 1: Remove if any old packages of wpa_supplicant or hostapd is present

test:~$ cd $HOME
test:~$ pwd
/home/test

test:~$ rm -rf hostap* wpa_supp*
  • Make sure internet is available in laptop to download hostapd package

test:~$ sudo wget http://w1.fi/releases/hostapd-2.9.tar.gz
  • Make sure internet is available in laptop to download hostapd package

test:~$ sudo apt install libnl-genl-3-dev libnl-3-dev libdbus-glib-1-dev
  • Internet is cut-off after this !

test:~$ sudo killall wpa_supplicant

test:~$ sudo killall wpa_cli

test:~$ sudo killall hostapd

test:~$ sudo killall hostapd_cli

test:~$ sudo killall dhclient

test:~$ sudo systemctl stop NetworkManager.service

test:~$ sudo rfkill list all
0: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no
1: dell-wifi: Wireless LAN
        Soft blocked: no
        Hard blocked: no
2: dell-bluetooth: Bluetooth
        Soft blocked: no
        Hard blocked: no
3: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
4: phy1: Wireless LAN
        Soft blocked: no
        Hard blocked: no
5: phy2: Wireless LAN
        Soft blocked: no
        Hard blocked: no

test:~$  sudo rfkill unblock all

test:~$ sudo ifconfig wlan0 up
  • wlan0 is the name of wireless interface on this laptop

test:~$ sudo iwconfig wlan0
wlan0     IEEE 802.11  ESSID:off/any
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
  • wlan0 is the name of wireless interface on this laptop

test:~$ sudo ifconfig wlan0
wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 02:00:00:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • tar -xvf command extracts zipped hostapd package

test:~$ sudo tar -xzvf hostapd-2.9.tar.gz
  • Change to hostapd-2.9/hostapd directory

  • Copy defconfig to .config file

  • .config file is required for make to start compilation of hostapd

test:~$ cd hostapd-2.9/hostapd

test:~/hostapd-2.9/hostapd$ cp defconfig .config

test:~/hostapd-2.9/hostapd$ make
  • ssid in ./run_hostapd.conf should be used by clients while connecting to AP

test:~/hostapd-2.9/hostapd$ sudo vim ./run_hostapd.conf

ctrl_interface=/run/hostapd
interface=wlan0
driver=nl80211
ssid=test_wpa2
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
group_cipher=CCMP
  • Turn on wifi on your mobile client/laptop client

  • wifi name is ssid in ./run_hostapd.conf

  • wifi password is wpa_passphrase in ./run_hostapd.conf

  • AP-STA-CONNECTED indicates successful connection of STA

test:~/hostapd-2.9/hostapd$ sudo ./hostapd ./run_hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
Using interface wlan0 with hwaddr 02:00:00:00:00:00 and ssid "test_wpa2"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
test:~/hostapd-2.9/hostapd$ ps -N | grep -i hostapd
36261 pts/3    00:00:00 hostapd
  • aid=1 is assigned to connected station. Check output of all_sta

test:~/hostapd-2.9/hostapd$ sudo ./hostapd_cli -i wlan0
hostapd_cli v2.9
Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.

Interactive mode
  • Mode field in iwconfig should show master

test:~/hostapd-2.9/hostapd$ sudo iwconfig
wlan0     IEEE 802.11  Mode:Master  Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on

test:~/hostapd-2.9/hostapd$ sudo iw dev
phy#1
        Interface wlan0
                ifindex 5
                wdev 0x100000001
                addr 02:00:00:00:00:00
                ssid test_wpa2
                type AP
                channel 6 (2437 MHz), width: 20 MHz (no HT), center1: 2437 MHz
                txpower 20.00 dBm
  • Station and AP should be in same IP subnet.

  • Assign 192.168.3.10 to station i.e mobile client/laptop client

  • Station and AP should be in same IP subnet.

  • Assign 192.168.3.1 to AP

test:~/hostapd-2.9/hostapd$ sudo ifconfig wlan0 192.168.3.1 up

test:~/hostapd-2.9/hostapd$ sudo ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.1  netmask 255.255.255.0  broadcast 192.168.3.255
        ether 02:00:00:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 61  bytes 11085 (11.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 130  bytes 25688 (25.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 192.168.3.10 is IP address of Station

test:~/hostapd-2.9/hostapd$ sudo ping 192.168.3.10
PING 192.168.3.10 (192.168.3.10) 56(84) bytes of data.
64 bytes from 192.168.3.10: icmp_seq=1 ttl=64 time=0.092 ms
64 bytes from 192.168.3.10: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.3.10: icmp_seq=3 ttl=64 time=0.094 ms
64 bytes from 192.168.3.10: icmp_seq=4 ttl=64 time=0.105 ms
64 bytes from 192.168.3.10: icmp_seq=5 ttl=64 time=0.094 ms