Skip to main content

WLAN Konfiguration mit NetworkManager

Konfigurieren der WLAN Verbindung

RaspiOS benötigt die Einstelung der WiFi localisation in raspi-config vor hinzufügen der Verbindung!

Die verwendeten Befehle:

nmcli c add type <network type> con-name <connection name> ifname <interface> ssid <ssid>
nmcli con modify <connection name> wifi-sec.key-mgmt wpa-psk
nmcli con modify <connection name> wifi-sec.psk ptclptcl
nmcli con up <connection name>
nmcli con show <connection name>

Der Wert connection.autoconnect-retries gibt an wieviele Verbindungsversuche durchgeführt werden. Ist der Wert -1 werden vier Versuche durchgeführt. Bei 0 werden unendliche Versuche durchgeführt.

nmcli connection modify CONNECTION NAME connection.autoconnect-retries 0
Verbindung hinzufügen:
nmcli c add type wifi con-name CONNECTION NAME ifname INTERFACE ssid SSID

Let’s break it down:

c object stands for connection

add signifies that we’re adding a connection

type indicates the type of connection we’re adding, such as “wifi“

con-name lets us set a custom name for the network that we’d see in the connections list

ifname lets us choose the network interface to use

ssid is the name of the access point that we are connecting to

In our case, the network type would be “wifi” and the interface would be the interface for our wireless card. We can easily get our interface name by issuing the ifconfig command.

Alternatively, we can also type nmcli to see a detailed list of our network interfaces:

$ nmcli
wlp61s0:
        "Intel 8265 / 8275"
        wifi (iwlwifi), 20:79:18:BD:97:32, hw, mtu 1500
        ip4 default
...

In addition to that, we can also use nmcli to get the list of available SSIDs in real-time:

$ nmcli dev wifi
IN-USE  BSSID              SSID             MODE   CHAN  RATE        SIGNAL  BA>
        00:27:19:28:B2:F4  Tplink           Infra  6     54 Mbit/s   72      ▂▄>
        E0:28:61:E6:6C:10  SAK75            Infra  10    270 Mbit/s  39      ▂▄>
        18:52:82:F5:53:D5  PTCL-BB          Infra  2     130 Mbit/s  35      ▂▄>

However, the SSID of the hidden wireless access points wouldn’t show in the list because a hidden network doesn’t broadcast its SSID. For that reason, we need to get the SSID from the Wi-Fi router’s control panel. Once we have our interface name and SSID, we can use the above command to add the hidden Wi-Fi network:

$ nmcli c add type wifi con-name home-wifi ifname wlp61s0 ssid z
Connection 'home-wifi' (0dfc98e2-be00-480c-bf1f-674b9b3403d8) successfully added.
Setting Up Credentials

After the network is added, we can add credentials for the network. However, before we set the credentials, we should know the type of the credentials. We can get this information from the control panel of our router. Of course, the process would differ for different routers, so we can check our router’s manual for the instructions.

Once we have the password key type, we can add it to our network:

$ nmcli con modify home-wifi wifi-sec.key-mgmt wpa-psk

The modify verb lets us configure an existing connection. Next, we specify the actual password for our Wi-Fi:

$ nmcli con modify home-wifi wifi-sec.psk ptclptcl

With our credentials added, we’re now ready to connect to the network.

Connecting to the Network

We can connect to the network with the up verb:

$ nmcli con up home-wifi

Let’s test our connectivity with ping:

$ ping -c 1 baeldung.com
PING baeldung.com (172.66.40.248): 56 data bytes
64 bytes from 172.66.40.248: icmp_seq=0 ttl=56 time=49.470 ms
--- baeldung.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 49.470/49.470/49.470/0.000 ms
Deleting the Connection

We can remove the connection from the system using the delete verb:

$ nmcli con delete home-wifi
Connection 'home-wifi' (0dfc98e2-be00-480c-bf1f-674b9b3403d8) successfully deleted.
Connecting to Hidden Network With a Single Command

Once we have a basic understanding of using nmcli, we can quickly connect to a hidden network with a single command:

$ nmcli dev wifi connect z password ptclptcl hidden yes

Here, the hidden switch is necessary. If we omit this, Network Manager will complain.


Disable IPv6

To disable IPv6 using nmcli, find your connection's name, modify it to ipv6.method "disabled", and then reconnect using nmcli connection up. This permanently disables IPv6 for that specific connection until it is manually re-enabled. 


Steps to disable IPv6


List your network connections to find the name of the connection you want to modify.

$ nmcli connection show


Modify the connection to disable IPv6. Replace Example with the name of your connection.

$ nmcli connection modify Example ipv6.method "disabled"


Restart the connection to apply the changes.

$ nmcli connection up Example