Skip to content

Instantly share code, notes, and snippets.

@narate
Last active May 2, 2026 17:33
Show Gist options
  • Select an option

  • Save narate/d3f001c97e1c981a59f94cd76f041140 to your computer and use it in GitHub Desktop.

Select an option

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
@sp00ck

sp00ck commented Aug 28, 2022

Copy link
Copy Markdown

this is wep (very weak encryptions)
how using WPA3 ?

@CEMoreno

Copy link
Copy Markdown

I never ran into any problems with Ubuntu on a Pi. This week I've been transitioning to an Asus Tinker board S R2.0 running Debian 10 kernel 4.4.194 and it has been frustrating.
wlan0 is up with the correct IP address: 10.42.0.1
Hotspot is up and SSID is there, advertised
Select SSID, try to login and then
Screen Shot 2022-09-16 at 5 20 02 PM

UUID is correct,... basically everything seems correct. I don't know what I am missing
Any help will be appreciated

@funnywwh

funnywwh commented Oct 5, 2022

Copy link
Copy Markdown

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.

greate on rk3568 debian

@cracktorio

Copy link
Copy Markdown

All my experiments with this didnt work, i think this is because of the security type specified.
If you have the networkmanager applet in some way or another, for example the xfce one, then you can just create new network and then after making it if you want to start it a later time just do nmcli con up NETWORKNAME

@opeolluwa

opeolluwa commented Jul 8, 2023

Copy link
Copy Markdown

Is there any shell scripts which could automate this.

I need a way to bundle it all up in a bash script, which I can just call once, to get me the ifname and create hotspot

@cracktorio

Copy link
Copy Markdown

I made one, it's very easy once you get to know the basics of shell. You'll need to know "read", variables, "case" if you want to get fancy, "echo", and obviously nmcli. For example, with a variable it would be nmcli con up $VARIABLENAME

@opeolluwa

Copy link
Copy Markdown

@Blokheck011 that's the challenge, I'm not quite great with Shell scripting and It's a lot to put on hold, the wifi file sharing application I'm building, and go on learning shell, I need something I can plug and play

@opeolluwa

Copy link
Copy Markdown

Plus, I still need to reimplement the solution in Rust

@abhishekmj303

abhishekmj303 commented Sep 8, 2023

Copy link
Copy Markdown

@CEMoreno @Blokheck011 This worked for me in when I was facing security type issue.

nmcli con modify Hotspot 802-11-wireless-security.pmf 1

Source: AskUbuntu

@gkucmierz

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

I have this error, when I try to up hotspot.

@TriMoon

TriMoon commented Nov 8, 2023

Copy link
Copy Markdown

Please see: https://unix.stackexchange.com/a/760947/550161
Where i ask for a non-AP mode solution... 🤝

@shubham-kshetre

Copy link
Copy Markdown

this is wep (very weak encryptions) how using WPA3 ?

I'm also trying to use same security type (WPA3) glad to know if you succeeded for it?

@lalvesl

lalvesl commented Feb 19, 2024

Copy link
Copy Markdown

Thank you all, especially abhishekmj303 for this argument (802-11-wireless-security.pmf 1)

@arrio464

Copy link
Copy Markdown

Excellent!
In some cases, you may need:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

@mohamad-supangat

Copy link
Copy Markdown

reference on https://owlhowto.com/how-to-create-a-wifi-hotspot-on-debian-12/

using this to auto create hotspot on boot

nmcli con mod Hostspot connection.autoconnect yes

@opeolluwa

Copy link
Copy Markdown

reference on https://owlhowto.com/how-to-create-a-wifi-hotspot-on-debian-12/

using this to auto create hotspot on boot

nmcli con mod Hostspot connection.autoconnect yes

Let me get this, it's possible to create hotspot without being connected to a WiFi?

@mohamad-supangat

Copy link
Copy Markdown

yes, you can create without it

@Vllben

Vllben commented Jun 22, 2024

Copy link
Copy Markdown

(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

flesser commented Jul 5, 2024

Copy link
Copy Markdown

@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)

@krishiv-v

krishiv-v commented Jul 21, 2024

Copy link
Copy Markdown

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

@wuseman

wuseman commented Jul 23, 2024

Copy link
Copy Markdown

Thanks! :-)

@haouarihk

haouarihk commented Sep 29, 2024

Copy link
Copy Markdown

as an improvement for that command

IFNAME="wlan0" && CON_NAME="wifi name" && PASSWD="12345678" && 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"

if the wifi name has spaces it will work

same goes for the second command

nmcli con up "$CON_NAME"

@0827MK

0827MK commented Sep 30, 2024

Copy link
Copy Markdown

I'm using a macbook.
When I try to connect to Hostspot, I keep getting prompted that WPA password is required.
Even though I used the correct password, the display does not disappear.

@jacobq

jacobq commented Oct 3, 2024

Copy link
Copy Markdown

Correct me if I'm wrong, but I think adding the following uses WPA2:

nmcli con modify Hostspot wifi-sec.group ccmp
nmcli con modify Hostspot wifi-sec.pairwise ccmp

and for WPA3 maybe something like this:

nmcli con modify Hostspot wifi-sec.key-mgmt sae

(Note: intentional misspelling of hotspot as Hostspot to match OP)

@ConzZah

ConzZah commented Mar 16, 2025

Copy link
Copy Markdown

for those who can create their hotspot but don't have internet through it:
symlink iptables to /sbin/iptables
and it should work.

@ingenium-lidar-admin

Copy link
Copy Markdown

Whenever I try the first line, I get
Error: Failed to add 'Hostspot' connection: failure adding connection: keyfile writer produces an invalid connection: cannot access file: No such file or directory
I'm on Ubuntu Core. Any help would be much appreciated.

@TriMoon

TriMoon commented Aug 24, 2025

Copy link
Copy Markdown

Maybe the connection name should be "Hotspot" instead of "Hostspot"

@ConzZah

ConzZah commented Sep 17, 2025

Copy link
Copy Markdown

i made a tool to set up a hotspot automatically
pls try it, review the code and create issues.
i'd like feedback, since this is a passion project of mine
https://github.com/conzzah/hsm

hsm

@mymirai-nikki

mymirai-nikki commented Nov 13, 2025

Copy link
Copy Markdown

I tried nmcli dev wifi hotspot but it didn't provide Internet connection.

is it possible to replicate Windows' hotspot behavior? where the hotspot has internet connection from the same wireless network card that being used as hotspot as well.

I'm looking for networkmanager-only solution to avoid installing another dependency.

EDIT:
problem solved, thanks to this comment, I ended up using create_ap from linux-wifi-hotspot instead of networkmanager' nmcli.

I just need to specify the channel

create_ap -c <channel-number> <iface-name-for-hotspot> <iface-name-for-internet-source> <ssid-name> <password>

the appropriate channel number can be found by:

iw dev <iface-name-for-hotspot> info

@rwb196884

Copy link
Copy Markdown

This created the connection and other devices can see the SSID, but nothing can connect to it.

In journalctl I see

Dec 17 02:49:39 kestrel wpa_supplicant[693]: wlan0: AP-STA-CONNECTED 04:34:f6:04:3f:8e
Dec 17 02:49:39 kestrel wpa_supplicant[693]: wlan0: EAPOL-4WAY-HS-COMPLETED 04:34:f6:04:3f:8e
Dec 17 02:49:56 kestrel wpa_supplicant[693]: wlan0: AP-STA-DISCONNECTED 04:34:f6:04:3f:8e

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