Sharing an active internet connection—such as a wired Ethernet connection or a 4G/5G mobile broadband modem—from a Linux computer to nearby mobile devices, test boards, or secondary laptops is frequently required in server rooms, field test environments, and home labs. While graphical desktop environments like GNOME and KDE provide one-click hotspot toggles, systems running minimal installations, embedded operating systems, or headless server instances must manage wireless access points directly through the command line. Using NetworkManager’s native command-line tool, nmcli, you can create, secure, and manage robust Wi-Fi hotspots with complete control over routing and encryption.
Following this command-line procedure allows you to configure WPA2-Personal wireless access points, inspect active client leases, and manage persistent wireless profiles directly from the Linux terminal.
Verifying Wireless Interface and Access Point Capabilities
Before creating a hotspot, verify that your wireless network card is recognised by the operating system and supports Access Point (AP) operational mode:
- List all physical and virtual network interfaces detected by NetworkManager:
nmcli device status
- Identify the name of your wireless interface (typically designated as
wlan0,wlp2s0, orwlp3s0). - Query the wireless regulatory subsystem using the
iwutility to verify that the wireless chipset supports Master/AP mode:
iw list | grep "Supported interface modes" -A 8
- Confirm that AP appears within the list of supported modes. If your card only lists Client, Managed, or Monitor modes, the hardware cannot broadcast an access point.
Creating an Instant Wi-Fi Hotspot with a Single Command
NetworkManager includes a streamlined shortcut command that builds a temporary access point, assigns IP addresses, and binds routing automatically:
- Execute the hotspot initialization command, specifying your wireless interface, network name (SSID), and a secure pre-shared key:
nmcli device wifi hotspot ifname wlan0 ssid "LinuxHotspot" password "SecureKey2026!"
- NetworkManager performs several automated tasks in the background:
- Creates a dedicated hotspot connection profile.
- Initialises an internal DHCP server instance via
dnsmasq-base. - Assigns the static gateway IP
10.42.0.1/24to your wireless interface. - Configures iptables / nftables network address translation (NAT) to route traffic through your default internet connection.
- Connect your client phone or computer to the “LinuxHotspot” wireless network using the specified password to test internet reachability.
Building a Persistent, Customised Hotspot Connection Profile
If you require a permanent hotspot that can be toggled on demand without re-typing authentication credentials every session, build a dedicated connection profile:
- Create a new wireless connection profile configured for AP mode:
sudo nmcli connection add type wifi ifname wlan0 con-name "LabHotspot" autoconnect no ssid "LabHotspot"
- Configure the wireless band and channel parameters (e.g. 2.4 GHz band
bgor 5 GHz banda):
sudo nmcli connection modify "LabHotspot" 802-11-wireless.mode ap 802-11-wireless.band bg
- Apply WPA-PSK security encryption:
sudo nmcli connection modify "LabHotspot" wifi-sec.key-mgmt wpa-psk
sudo nmcli connection modify "LabHotspot" wifi-sec.psk "EnterprisePasscode2026"
- Configure IPv4 sharing mode to activate the internal DHCP pool and disable IPv6 if not required:
sudo nmcli connection modify "LabHotspot" ipv4.method shared
sudo nmcli connection modify "LabHotspot" ipv6.method ignore
Enabling Kernel Packet Forwarding
To ensure incoming data packets from connected Wi-Fi clients are successfully forwarded out through your upstream Ethernet or mobile network interface, enable IPv4 packet forwarding in the Linux kernel:
- Enable forwarding immediately in the running kernel:
sudo sysctl -w net.ipv4.ip_forward=1
- To ensure this setting persists across system reboots, write the directive into a sysctl configuration file:
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ip-forwarding.conf
Activating, Monitoring, and Disabling the Hotspot
Manage the lifecycle of your wireless hotspot directly through simple connection commands:
- Start the hotspot broadcast:
nmcli connection up "LabHotspot"
- To inspect IP addresses and MAC addresses assigned to connected client devices, inspect the active DHCP leases database:
cat /var/lib/misc/dnsmasq.leases
- When you finish sharing your connection, cleanly terminate the broadcast:
nmcli connection down "LabHotspot"