Create wireless access point and share internet connection with nmcli

62,828

Solution 1

I created a Hotspot with the GNOME Network-Manager. The problem was, that I can not configure the SSID and password in GUI. If you create the Hotspot with the Network-Manager GUI, it creates the file /etc/NetworkManager/system-connections/Hotspot. In that file it is possible to edit the SSID and the password.

sudo vim /etc/NetworkManager/system-connections/Hotspot

The content of the file looks like this:

[connection]
id=Hotspot
uuid=0bf627gd-8e34-48c6-865a-06f898b4y1hb
type=wifi
autoconnect=true
permissions=
secondaries=

[wifi]
hidden=false
mac-address=YOUR_WIFI_INTERFACE_MAC_ADDRESS
mac-address-blacklist=
mode=ap
seen-bssids=
ssid=SSID_NAME

[wifi-security]
group=ccmp;
key-mgmt=wpa-psk
pairwise=ccmp;
proto=rsn;
psk=YOUR_WIFI_AP_PASSWORD

[ipv4]
dns-search=
method=shared

[ipv6]
dns-search=
method=auto

I changed the ssid and the psk properties to my needs. To enable autostart you have to set the parameter autoconnect to true. Then I restarted my computer because the command: sudo systemctl restart NetworkManager for network restart seems not to work correctly, because in the Network-Manager GUI:

wireless settings gone

I have no wireless network settings anymore and also the following command worked not before the restart. After restart you can use the nmcli command to start the access point.

nmcli con up Hotspot ifname YOUR_WIFI_INTERFACE

YOUR_WIFI_INTERFACE you can find out with the command iwconfig.

I used Antergos / Arch Linux for the above solution and found the hint to this at the ask.fedoraproject.org site.

Solution 2

You can create a hotspot with:

nmcli dev wifi hotspot ifname wlp4s0 ssid test password "test1234"

where wlp4s0 is the name of your Wifi interface.

Solution 3

On a Centos 7 it looks like this.

Check if AP is possible at all:

iw list | less

and search for "AP" among supported interface modes.

Browse your devices to find the name:

nmcli d

And setup and start your hotspot.

Mind that wifi-device, connection-name and hotspot-ssid are specific to your system.

nmcli c add type wifi ifname wifi-device con-name connection-name autoconnect no ssid hotspot-ssid
nmcli connection modify connection-name 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli connection modify connection-name wifi-sec.key-mgmt wpa-psk
nmcli connection modify connection-name wifi-sec.psk "le password"
nmcli connection up connection-name

Check also:

Solution 4

I know this is an old question, but thought I would add my comments as this may help someone in the future.

The whole process is just three commands as @Dzik has correctly mentioned.

nmcli connection add type wifi ifname wlan0 con-name local-ap autoconnect yes ssid test-ap mode ap
nmcli connection modify con-name 802-11-wireless.mode ap 802-11-wireless-security.key-mgmt wpa-psk ipv4.method shared 802-11-wireless-security.psk 'PASSWORD'
nmcli connection up con-name

This will start an AP for you.

To verify, we can use:

nmcli dev wifi list

Solution 5

Just

nmcli dev wifi hotspot

will generate a password and start a hotspot with SSID Hotspot-<YOUR_HOSTNAME> on the default wifi interface.

To show the Wi-Fi name and password (and a QR code):

nmcli dev wifi show-password

From nmcli dev wifi --help:

ARGUMENTS := hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>]
                                         [band a|bg] [channel <channel>] [password <password>]

Create a Wi-Fi hotspot. Use 'connection down' or 'device disconnect'
to stop the hotspot.
Parameters of the hotspot can be influenced by the optional parameters:
ifname - Wi-Fi device to use
con-name - name of the created hotspot connection profile
ssid - SSID of the hotspot
band - Wi-Fi band to use
channel - Wi-Fi channel to use
password - password to use for the hotspot

Note: You need a DHCP server installed (e.g. dnsmasq), or you'll get

IP configuration could not be reserved (no available address, timeout, etc.).

For the "start on boot" part: see Autostarting page in ArchWiki for an overview.

(The first command here was intended as a comment to ysdx's answer, but I don't have enough rep)

Share:
62,828

Related videos on Youtube

GleasonK
Author by

GleasonK

Updated on September 18, 2022

Comments

  • GleasonK
    GleasonK over 1 year

    How can I create a Wi-Fi hotspot with the command line tool nmcli and share/bridge the ethernet internet connection with the wireless access point? Furthermore, how can I start this automatically at boot?

    Is this possible with nmcli?

    • GleasonK
      GleasonK over 8 years
      I'm searching for a solution with nmcli, if that is possible.
    • GleasonK
      GleasonK over 8 years
      I have version 1.0.6.
  • oidualc
    oidualc about 6 years
    Simplest answer, yet so effective. Thank you.
  • Guido
    Guido over 5 years
    Thank you so much for this answer, amazingly simple and works great.
  • Frederick Nord
    Frederick Nord almost 5 years
    does this do ip forwarding via a (cabled?) connection?
  • Michael Nikitochkin
    Michael Nikitochkin about 4 years
    > does this do ip forwarding via a (cabled?) connection? - Yes
  • Philipp Ludwig
    Philipp Ludwig over 3 years
    Does not work: Error: Connection activation failed: (5) IP configuration could not be reserved (no available address, timeout, etc.).
  • m4l490n
    m4l490n almost 3 years
    I can't connect to the hotspot resulting from executing this
  • zrajm
    zrajm almost 3 years
    I cannot connect to a hotspot created like this (on my Raspberry Pi 3) with my Android cellphone. (The phone attempts to connect, but times out after a while with the message "Connection to "Testing" timed out. Connection Failed.")
  • zrajm
    zrajm almost 3 years
    This worked for me (when the accepted answer did not) on Ubuntu 20.04. Unfortunately some additional setup is apparently required for the machine with the access point to also share its internet.