Turn Linux Computer into Wi-Fi Access Point (Hotspot) Ranjan.info

In this article, we will show how to create a Wi-Fi access point (software AP) on any computer or laptop running Linux and equipped with a wireless adapter. You can use this access point (hotspot) to create a wireless local network in a small office or home, or to share mobile Internet with other devices. In this example, we are using a laptop running the latest version of Ubuntu.

First, make sure that your wireless Wi-Fi module supports Access Point (AP) mode. To do this, install iw package:

$ sudo apt install iw

iw Tool used to configure wireless interface (nl80211 driver) from command prompt. It supports all the new drivers recently added to the Linux kernel. Old iwconfig The tool, which uses the Wireless Extension Interface, is deprecated, so it is strongly recommended that you use the iw and nl80211 instead.

Run the command below:

$ iw list

iw: check supported wireless interface modes

In Supported Interface Modes section, search

This means that your Wi-Fi adapter supports operation in access point mode.

How to create Wi-Fi hotspot from Ubuntu GUI?

On newer with Ubuntu 20.04 LTS and GNOME (3.28+), you can run a wireless access point from a graphic interface. This is the easiest way for the average user.

Click on the network connection icon and select turn on wi-fi hotspot In WIFI settings,

Wi-Fi Settings in GNOME on Ubuntu

Enable Wi-Fi Hotspot on Ubuntu

Enter the name of the access point and the connection key (password)

Set the SSID (name) and password for the wireless access point

You should see a message that your access point is active. In the same window there is a QR code to connect to your Wi-Fi access point.

Generate Wi-Fi QR Code on Linux

Configure a Wireless Access Point with Network Manager (nmcli) on Linux

network manager Can be used to manage network connections in most modern Linux distros (Ubuntu, Debian, Mint, Fedora, CentOS, etc.). In this example, we will show how to create a software access point on Linux using Network Manager and nmcli command line tool.

First, you need to find out the name of your wireless adapter in the system.

$ nmcli d

get wireless adapter name on ubuntu linux

In our example, the name of the Wi-Fi adapter is wlp4s0b1,

If dnsmasq (a lightweight DHCP/DNS server) is installed on your computer, you will need to disable it. This will conflict with the dnsmasq plugin in NetworkManager.

to create an access point on wlp4s0b1 Interface with network name (SSID) WOSHubWiFi and a network key (password) maxpass21Run the commands below:

# nmcli con add type wifi ifname wlp4s0b1 mode ap con-name MyHomeWiFI ssid WOSHubWiFi
# nmcli con modify MyHomeWiFI 802-11-wireless.band bg
# nmcli con modify MyHomeWiFI 802-11-wireless.channel 1
# nmcli con modify MyHomeWiFI 802-11-wireless-security.key-mgmt wpa-psk
# nmcli con modify MyHomeWiFI 802-11-wireless-security.proto rsn
# nmcli con modify MyHomeWiFI 802-11-wireless-security.group ccmp
# nmcli con modify MyHomeWiFI 802-11-wireless-security.pairwise ccmp
# nmcli con modify MyHomeWiFI 802-11-wireless-security.psk MaxPass21
# nmcli con modify MyHomeWiFI ipv4.method shared

Start your hotspot:
# nmcli con up WOSHubWiFi

Use nmcli on ubuntu to start wireless hotspot

If you want the access point to operate on 5GHz and use a higher channel, change the corresponding command to:

# nmcli con modify MyHomeWiFI 802-11-wireless.band a
# nmcli con modify MyHomeWiFI 802-11-wireless.channel 35

By default, the built-in DHCP server in NetworkManager assigns clients IP addresses from the 10.42.0.x/24 range (and 10.24.0.1 is the address of your hotspot interface). You can change the DCHP range:

# nmcli con modify MyHomeWiFI ipv4.addr 192.168.31.1/24

To disable the access point, run this command:

# nmcli con down MyHomeWiFI

To completely remove Software Hotspot on Linux:

# nmcli con delete MyHomeWiFI

Using Hostpad to Set Up a Virtual WiFi Access Point on Linux

A popular tool for creating Wi-Fi access points on Linux computers is yoga package. Install it:

$ sudo apt install hostapd

Copy the original configuration file (/etc/hostapd/hostapd.conf). Add the following configuration to hostapd.conf:

$ sudo nano /etc/hostapd/hostapd.conf

interface= wlp4s0b1
# The nl80211 driver is suitable for most Wi-Fi adapters
driver=nl80211
# Your access point name
ssid=MyHomeAP
# The number of your Wi-Fi channel (1 to 13)
channel=11
#Select a mode for your access point (a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE 802.11g)
hw_mode=g
# 1=wpa, 2=wep, 3=both
auth_algs=1
# Allow connections from all MAC addresses except those in the blacklist
macaddr_acl=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
#Set a password for your access point
wpa_passphrase=MyPass321
if you want to use 802.11n mode, change below:

ieee80211n=1
ht_capab=[HT40-][SHORT-GI-40]

Unmask the hostapd service:

$ sudo systemctl unmask hostapd

Then specify the path of your configuration file in DAEMON_CONF Parameters of /etc/default/hostapd file:

$ sudo nano /etc/default/hostapd

DAEMON_CONF="/etc/hostapd/hostapd.conf"

configure hostapd on linux

Then configure your wireless network interface. Set up a static IP address, DNS, mode, and other options. Edit /etc/network/interfaces file and add the following:

# nano /etc/network/interfaces

auto wlp3s0
iface wlp3s0 inet static
address 10.10.0.1
netmask 255.255.255.0

You’ll also need it to prevent NetworkManager from interfering with the Wi-Fi interface. Restart your computer after saving the settings.

Then all you have to do is configure a DHCP server that will provide IP addresses to devices connecting to your Linux access point. In our example, we’ll use a lightweight dnsmasq,

$ sudo apt install dnsmasq

Edit dnsmasq.conf. Specify that dnsmasq will run on the wlp4s0b1 interface and assign IP addresses from the 10.10.0.x range. In the simplest case, you can have the following configuration:

$ sudo nano /etc/dnsmasq/dnsmasq.conf

interface=wlp4s0b1
dhcp-range=10.10.0.2,10.10.0.100,12h
#Set DNS servers
server=/www.google.com/8.8.8.8

IP addresses in the DHCP range must belong to the same network that your WLAN adapter is connected to.

In order for your Linux host to be able to route packets between Wi-Fi clients and external Internet connections, you need to enable routing and add the relevant rule to iptables:

sysctl net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o enp3s0 -j MASQUERADE

You can also use the bridge interface to provide Internet access to clients from your local network (we’ll skip this to keep the article short).

Start these services:

# systemctl start dnsmasq.service
# systemctl start hosapd

Now you can connect to your access point from any client, check that it has received an IP address from the specified DHCP range and can access the Internet.

Leave a Comment