Skip to content

Instantly share code, notes, and snippets.

Last active May 16, 2024 04:35
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 :

nmcli con add type wifi ifname wlan0 con-name Hostspot autoconnect yes ssid Hostspot
nmcli con modify Hostspot 802-11-wireless.mode ap 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


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
Copy link

sp00ck commented Aug 28, 2022

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

Copy link

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:
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

Copy link

funnywwh commented Oct 5, 2022

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

Copy link

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

Copy link

opeolluwa commented Jul 8, 2023

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

Copy link

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

Copy link

@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

Copy link

Plus, I still need to reimplement the solution in Rust

Copy link

abhishekmj303 commented Sep 8, 2023

@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

Copy link

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.

Copy link

TriMoon commented Nov 8, 2023

Please see:
Where i ask for a non-AP mode solution... 🤝

Copy link

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?

Copy link

lalvesl commented Feb 19, 2024

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

Copy link

In some cases, you may need:

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

Copy link

reference on

using this to auto create hotspot on boot

nmcli con mod Hostspot connection.autoconnect yes

Copy link

reference on

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?

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