Wi-Fi AP and hostapd ============================= .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Learnings in this section ` * :ref:`Version Info ` * :ref:`Steps to run hostapd in AP mode ` * :ref:`STEP 1: Remove old packages ` * :ref:`STEP 2: Download hostapd package ` * :ref:`STEP 3: Install required libraries ` * :ref:`STEP 4: Stop ongoing wireless activities ` * :ref:`STEP 5: Check wireless interface status before connection ` * :ref:`STEP 6: Check ifconfig interface status before connection ` * :ref:`STEP 7: Extract hostapd ` * :ref:`STEP 8: Compile hostapd ` * :ref:`STEP 9: Create run_hostapd.conf ` * :ref:`STEP 10: Turn on wifi on client ` * :ref:`STEP 11: Run hostapd ` * :ref:`STEP 12: Check ps status and confirm hostapd process is running ` * :ref:`STEP 13: Check connection status using hostapd_cli ` * :ref:`STEP 14: Check wireless interface status after connection ` * :ref:`STEP 15: Assign Static IP address to station ` * :ref:`STEP 16: Assign Static IP address to AP ` * :ref:`STEP 17: Ping STA ` .. _barelinux_x86-64_wi-fi_ap_and_hostapd_0: .. tab-set:: .. tab-item:: Learnings in this section * In this section, you are going to learn .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to run hostapd in AP mode .. _barelinux_x86-64_wi-fi_ap_and_hostapd_1: .. tab-set:: .. tab-item:: Version Info =============================== ======================================= # Version =============================== ======================================= Ubuntu Ubuntu 22.04 64 bit Linux Kernel 6.9.0 Hostapd Hostapd 2.9 =============================== ======================================= .. _barelinux_x86-64_wi-fi_ap_and_hostapd_2: .. tab-set:: .. tab-item:: Steps to run hostapd in AP mode .. _barelinux_x86-64_wi-fi_ap_and_hostapd_3: .. tab-set:: .. tab-item:: Remove old packages * STEP 1: Remove if any old packages of wpa_supplicant or hostapd is present .. code-block:: shell test:~$ cd $HOME test:~$ pwd /home/test test:~$ rm -rf hostap* wpa_supp* .. _barelinux_x86-64_wi-fi_ap_and_hostapd_4: .. tab-set:: .. tab-item:: STEP 2: Download hostapd package * Make sure internet is available in laptop to download hostapd package .. code-block:: shell test:~$ sudo wget http://w1.fi/releases/hostapd-2.9.tar.gz .. _barelinux_x86-64_wi-fi_ap_and_hostapd_5: .. tab-set:: .. tab-item:: STEP 3: Install required libraries * Make sure internet is available in laptop to download hostapd package .. code-block:: shell test:~$ sudo apt install libnl-genl-3-dev libnl-3-dev libdbus-glib-1-dev .. _barelinux_x86-64_wi-fi_ap_and_hostapd_6: .. tab-set:: .. tab-item:: STEP 4: Stop ongoing wireless activities * Internet is cut-off after this ! .. code-block:: shell 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_7: .. tab-set:: .. tab-item:: STEP 5: Check wireless interface status before connection * wlan0 is the name of wireless interface on this laptop .. code-block:: shell 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_8: .. tab-set:: .. tab-item:: STEP 6: Check ifconfig interface status before connection * wlan0 is the name of wireless interface on this laptop .. code-block:: shell test:~$ sudo ifconfig wlan0 wlan0: flags=4099 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_9: .. tab-set:: .. tab-item:: STEP 7: Extract hostapd * tar -xvf command extracts zipped hostapd package .. code-block:: shell test:~$ sudo tar -xzvf hostapd-2.9.tar.gz .. _barelinux_x86-64_wi-fi_ap_and_hostapd_10: .. tab-set:: .. tab-item:: STEP 8: Extract hostapd * Change to hostapd-2.9/hostapd directory * Copy defconfig to .config file * .config file is required for make to start compilation of hostapd .. code-block:: shell test:~$ cd hostapd-2.9/hostapd test:~/hostapd-2.9/hostapd$ cp defconfig .config test:~/hostapd-2.9/hostapd$ make .. _barelinux_x86-64_wi-fi_ap_and_hostapd_11: .. tab-set:: .. tab-item:: STEP 9: Create run_hostapd.conf * ssid in ./run_hostapd.conf should be used by clients while connecting to AP .. code-block:: shell 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_12: .. tab-set:: .. tab-item:: STEP 10: Turn on wifi on client * 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_13: .. tab-set:: .. tab-item:: STEP 11: Run hostapd * AP-STA-CONNECTED indicates successful connection of STA .. code-block:: shell 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_14: .. tab-set:: .. tab-item:: STEP 12: Check ps status and confirm hostapd process is running .. code-block:: shell test:~/hostapd-2.9/hostapd$ ps -N | grep -i hostapd 36261 pts/3 00:00:00 hostapd .. _barelinux_x86-64_wi-fi_ap_and_hostapd_15: .. tab-set:: .. tab-item:: STEP 13: Check connection status using hostapd_cli * aid=1 is assigned to connected station. Check output of all_sta .. code-block:: shell test:~/hostapd-2.9/hostapd$ sudo ./hostapd_cli -i wlan0 hostapd_cli v2.9 Copyright (c) 2004-2019, Jouni Malinen and contributors This software may be distributed under the terms of the BSD license. See README for more details. Interactive mode .. _barelinux_x86-64_wi-fi_ap_and_hostapd_16: .. tab-set:: .. tab-item:: STEP 14: Check wireless interface status after connection * Mode field in iwconfig should show master .. code-block:: shell 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_17: .. tab-set:: .. tab-item:: STEP 15: Assign Static IP address to station * Station and AP should be in same IP subnet. * Assign 192.168.3.10 to station i.e mobile client/laptop client .. _barelinux_x86-64_wi-fi_ap_and_hostapd_18: .. tab-set:: .. tab-item:: STEP 16: Assign Static IP address to AP * Station and AP should be in same IP subnet. * Assign 192.168.3.1 to AP .. code-block:: shell test:~/hostapd-2.9/hostapd$ sudo ifconfig wlan0 192.168.3.1 up test:~/hostapd-2.9/hostapd$ sudo ifconfig wlan0 wlan0: flags=4163 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 .. _barelinux_x86-64_wi-fi_ap_and_hostapd_19: .. tab-set:: .. tab-item:: STEP 17: Ping STA * 192.168.3.10 is IP address of Station .. code-block:: shell 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