I came across this script after a long struggle to set up a hotspot using my computer’s internet service, wired or wirelss. Create_ap script uses hostapd + dnsmasq + iptables to create a NATed Access Point OR hostapd + brctl + dhclient to create a bridged Access Point. The default behavior is a NATed Access Point,see here or github.
Requirement and Eligibility Check
You need a nl80211 compatible wireless device, which supports the AP operating mode. Check with the following:
1 2 3 |
iw list |grep AP |
You should see something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Device supports AP-side u-APSD. * AP * AP/VLAN * AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0 * AP/VLAN: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0 * AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0 * AP/VLAN: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0 * wake up on EAP identity request * AP/VLAN * #{ managed } <= 1, #{ AP, P2P-client, P2P-GO } <= 1, #{ P2P-device } <= 1, Driver supports full state transitions for AP/GO clients Driver/device bandwidth changes during BSS lifetime (AP/GO mode) |
To check whether you can use your wifi (instead of ethernet) as access point (a wireless repeater). I do use this feature so that I can use my VPN service from my laptop instead of setting up VPN on my phone to save my phone battery.
1 2 3 4 5 6 7 8 9 |
iw list |grep -A 4 "interface\ combinations" --------------------------------------------- valid interface combinations: * #{ managed } <= 1, #{ AP, P2P-client, P2P-GO } <= 1, #{ P2P-device } <= 1, total <= 3, #channels <= 2 HT Capability overrides: * MCS: ff ff ff ff ff ff ff ff ff ff |
The constraint #channels <= 1 means that your software AP must operate on the same channel as your Wi-Fi client connection;
1 2 3 4 5 6 7 8 |
lspci -k | grep -A 3 -i "network" -------------------------------- 08:00.0 Network controller: Intel Corporation Wireless 8260 (rev 3a) Subsystem: Intel Corporation Device 1010 Kernel driver in use: iwlwifi Kernel modules: iwlwifi |
Now get the interface details of your wireless driver by,
1 2 3 |
modinfo <whatever-kernel-> | grep 'depend' |
Install and Config Software Access Point with create_ap
You can install it manually,
1 2 3 4 5 |
git clone https://github.com/oblique/create_ap cd create_ap make install |
Or, install the distro package for Arch.
1 2 3 |
pacman -S create_ap |
Retrieve the interface info;
1 2 3 |
ip link # to list info |
Cross your finger, toes and heart, and let create_ap do the magic. Use your phone to log into your new wifi hotspot. If it does not work, dig through here for some clues.
1 2 3 |
sudo create_ap <--hidden> wlan0 eth0 SSID Passphrase |
Here is what I got. If you want to run it as a background service then add –daemon argument (see discussed here).
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Config dir: /tmp/create_ap.wlp8s0.conf.Pg172rWP PID: 32479 Network Manager found, set ap1 as unmanaged device... DONE wlp8s0 is already associated with channel 6 (2437 MHz), fallback to channel 6 Creating a virtual WiFi interface... ap1 created. Sharing Internet using method: nat hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlp8s0.conf.Pg172rWP/hostapd_ctrl Configuration file: /tmp/create_ap.wlp8s0.conf.Pg172rWP/hostapd.conf Using interface ap1 with hwaddr a4:34:d9:51:17:66 and ssid "ARCH" ap1: interface state UNINITIALIZED->ENABLED ap1: AP-ENABLED |
Finishing up
Run it as a system service
-
Modifying conf file accordingly:
12345678910111213141516171819202122232425262728293031sudo nano /etc/create_ap.conf--------------------------------------HANNEL=defaultGATEWAY=10.0.0.1WPA_VERSION=2ETC_HOSTS=0DHCP_DNS=gatewayNO_DNS=0HIDDEN=0 #change to 1 if you do not want to broadcast your SSIDMAC_FILTER=0MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.acceptISOLATE_CLIENTS=0SHARE_METHOD=natIEEE80211N=0IEEE80211AC=0HT_CAPAB=[HT40+]VHT_CAPAB=DRIVER=nl80211NO_VIRT=0COUNTRY=FREQ_BAND=2.4NEW_MACADDR=DAEMONIZE=0NO_HAVEGED=0WIFI_IFACE=wlp8s0INTERNET_IFACE=enp9s0SSID=SSIDPASSPHRASE=PassphraseUSE_PSK=0 -
Start service immediately:
123systemctl start create_ap -
I want the hotspot to be on when the system start; however, create_ap has to wait until the system is up and running. If create_ap fires before a valid network is established, it will unmanage/disable the interface and results in failed network. You have to delete the line in NetworkManager.conf,
123456789sudo nano /etc/NetworkManager/NetworkManager.conf-------------------------------------------------[main]plugins=keyfile[keyfile]unmanaged-devices=interface-name:ap1and restart the NetworkManager.service to regain its functionality.
123sudo systemctl restart NetworkManager.service -
Here is what I did to make it work.
First, enable NetworkManager-wait-online.service if not already.
123sudo systemctl status NetworkManager-wait-online.serviceNext, I increase the network load time from 30s to 60s.
123456789sudo nano /usr/lib/systemd/system/network-online.target.wants/NetworkManager-wait-online.service----------------------------------------[Service]Type=oneshotExecStart=/usr/bin/nm-online -s -q --timeout=60RemainAfterExit=yes... -
Add hook to run create_ap service after a successful connection from NetworkManager.
123456789sudo nano /usr/lib/systemd/system/create_ap.service---------------------------------------[uit]Description=Create AP ServiceAfter=network-online.targetRequires=network-online.target... -
Start on boot,
1234systemctl enable create_apsytemctl status create_ap
Run it on demand with a command
-
create a shell script
123456nano ~/usr/bin/hotspot-------------------------#!/bin/bashsudo create_ap <--hidden> <--daemon> wlp8s0 enp9s0 SSID Passphrase -
make it executable and elevate it to a system command
1234$ chmod a+x ./hotspot# sudo ln -sfv `readline -f ./htospot` /bin/hotspot -
start your hotspot at will
123hotspot - Reboot and enjoy your hotspot!
MAR
About the Author:
Beyond 8 hours - Computer, Sports, Family...