Skip to content

Instantly share code, notes, and snippets.

@narate
Last active July 21, 2024 09:30
Show Gist options
  • Save narate/d3f001c97e1c981a59f94cd76f041140 to your computer and use it in GitHub Desktop.
Save narate/d3f001c97e1c981a59f94cd76f041140 to your computer and use it in GitHub Desktop.
Create Wi-Fi Hotspot on Linux using nmcli

Create a Wi-Fi hotspot on Linux using nmcli

Original post : https://unix.stackexchange.com/a/310699

nmcli con add type wifi ifname wlan0 con-name Hostspot autoconnect yes ssid Hostspot
nmcli con modify Hostspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify Hostspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hostspot wifi-sec.psk "veryveryhardpassword1234"
nmcli con up Hostspot

Note

If after reboot nmcli con up Hotspot doesn't work

Use this command instead to start Hotspot

UUID=$(grep uuid /etc/NetworkManager/system-connections/Hotspot | cut -d= -f2)
nmcli con up uuid $UUID
@mohamad-supangat
Copy link

yes, you can create without it

@Vllben
Copy link

Vllben commented Jun 22, 2024

(I hope this is not annoying) Is it possible to run the hotspot on a rasbperry pi 5, and then connect to it? I can host the hotspot just fine, but when I try to connect it refuses because the hotspot has no internet. (It has no internet, not the network is not found.) Is there a way that you can connect to a network without internet using Raspbian lite?

@flesser
Copy link

flesser commented Jul 5, 2024

@Vllben had the same problem on a raspberry pi 4 with Raspbian 12 (bookworm) and had to setup the nftables firewall accordingly for the client to be able to use the raspberry's internet connection:

sudo nft add table nat
sudo nft 'add chain nat postrouting { type nat hook postrouting priority 100 ; }'
sudo nft add rule nat postrouting masquerade

See https://wiki.nftables.org/wiki-nftables/index.php/Performing_Network_Address_Translation_(NAT)

@blackmatrixx
Copy link

blackmatrixx commented Jul 21, 2024

In archlinux to share the wired internet via wifi, the dnsmasq packet is required for the network to lift properly.

It is also possible to create the network in a single command.

$ IFNAME="wlan0" && CON_NAME="MATARIFE" && PASSWD="password" && nmcli c add type wifi ifname $IFNAME con-name $CON_NAME autoconnect yes ssid $CON_NAME 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared wifi-sec.key-mgmt wpa-psk wifi-sec.psk "$PASSWD"

And then just lift the network.

$ nmcli con up $CON_NAME

We check that the wired network is sharing the internet via wifi.

$ nmcli d s | grep ^$IFNAME
wlan0          wifi      connected     MATARIFE

I also have a script that automates the procedure. For more information I also have a post on my Telegram channel dedicated to the topic.

I tried this method I reached till lift the network but when I run this command "nmcli con up $CON_NAME" I got an error saying -

Error: Connection activation failed: No suitable device found for this connection (device eno1 not available because profile is not compatible with device (mismatching interface name)).

Can you please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment