6

As part of an automated build process for Ubuntu 16.04 servers, I use nmcli to create network profiles, including wireless. This is on headless systems without window manager FWIW.

I have noticed that when I create a profile and activate it, if the access point (AP) is not there at activation it will never auto-connect, regardless if it is available subsequently.

I've tried to narrow down the cause of the problem and believe it might be something to do with dbus registration.

Profile creation:

sudo nmcli con add con-name "aNetwork" ifname wlp2s0 type wifi ssid "aNetwork"
sudo nmcli con modify "aNetwork" wifi-sec.key-mgmt wpa-psk
sudo nmcli con modify "aNetwork" wifi-sec.psk aPassword
sudo nmcli con up id "aNetwork"

From syslog, it seems it adds it correctly and sets it to scanning:

ug 12 08:55:06 bacer-104 NetworkManager[585]: <info>  [1565600106.4111] Config: added 'ssid' value 'aNetwork'
Aug 12 08:55:06 bacer-104 NetworkManager[585]: <info>  [1565600106.4111] Config: added 'scan_ssid' value '1'
Aug 12 08:55:06 bacer-104 NetworkManager[585]: <info>  [1565600106.4112] Config: added 'key_mgmt' value 'WPA-PSK'
Aug 12 08:55:06 bacer-104 NetworkManager[585]: <info>  [1565600106.4112] Config: added 'psk' value '<omitted>'
Aug 12 08:55:06 bacer-104 NetworkManager[585]: <info>  [1565600106.4128] sup-iface[0x1b0ff90,wlp2s0]: config: set interface ap_scan to 1

However after I make the AP visible, it never scans/connects, but when the connection is activated when the ESSID was present at creation, I get the following entry:

NetworkManager[489]: <debug> [1565287017.8330] device[0x1fb95f0] (wlp2s0): add_pending_action (3): 'scan'

But when the connection is activated *and the ESSID was not present at creation I get this:

NetworkManager[489]: <debug> [1565287064.3891] device[0x1fb95f0] (wlp2s0): add_pending_action (1): 'scan'
NetworkManager[489]: <debug> [1565287065.4580] device[0x1fb95f0] (wlp2s0): remove_pending_action (0): 'scan'

The contents of /etc/NetworkManager/system-connection/aNetwork are:

[connection]
id=aNetwork
uuid=6f24046b-b265-46d5-b89f-59ec802ce0af
type=wifi
interface-name=wlp2s0
permissions=
secondaries=

[wifi]
mac-address-blacklist=
mac-address-randomization=0
seen-bssids=
ssid=aNetwork

[wifi-security]
group=
key-mgmt=wpa-psk
pairwise=
proto=
psk=aPassword

[ipv4]
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

I have diffed the contents between profiles created where theESSID are both present and absent and there is no difference.

Looking at the output of nmcli con show aNetwork between the two shows a big difference:

  1. The output when disconnected, no ESSID at creation/activation is:

    connection.id:                          aNetwork
    connection.uuid:                        9dfacadb-f52a-453b-b6f1-2fbae6426d79
    connection.interface-name:              wlp2s0
    connection.type:                        802-11-wireless
    connection.autoconnect:                 yes
    connection.autoconnect-priority:        0
    connection.timestamp:                   0
    connection.read-only:                   no
    connection.permissions:
    connection.zone:                        --
    connection.master:                      --
    connection.slave-type:                  --
    connection.autoconnect-slaves:          -1 (default)
    connection.secondaries:
    connection.gateway-ping-timeout:        0
    connection.metered:                     unknown
    connection.lldp:                        -1 (default)
    802-11-wireless.ssid:                   aNetwork
    802-11-wireless.mode:                   --
    802-11-wireless.band:                   --
    802-11-wireless.channel:                0
    802-11-wireless.bssid:                  --
    802-11-wireless.rate:                   0
    802-11-wireless.tx-power:               0
    802-11-wireless.mac-address:            --
    802-11-wireless.cloned-mac-address:     --
    802-11-wireless.mac-address-blacklist:
    802-11-wireless.mac-address-randomization:default
    802-11-wireless.mtu:                    auto
    802-11-wireless.seen-bssids:
    802-11-wireless.hidden:                 no
    802-11-wireless.powersave:              default (0)
    802-11-wireless-security.key-mgmt:      wpa-psk
    802-11-wireless-security.wep-tx-keyidx: 0
    802-11-wireless-security.auth-alg:      --
    802-11-wireless-security.proto:
    802-11-wireless-security.pairwise:
    802-11-wireless-security.group:
    802-11-wireless-security.leap-username: --
    802-11-wireless-security.wep-key0:      <hidden>
    802-11-wireless-security.wep-key1:      <hidden>
    802-11-wireless-security.wep-key2:      <hidden>
    802-11-wireless-security.wep-key3:      <hidden>
    802-11-wireless-security.wep-key-flags: 0 (none)
    802-11-wireless-security.wep-key-type:  0 (unknown)
    802-11-wireless-security.psk:           <hidden>
    802-11-wireless-security.psk-flags:     0 (none)
    802-11-wireless-security.leap-password: <hidden>
    802-11-wireless-security.leap-password-flags:0 (none)
    ipv4.method:                            auto
    ipv4.dns:
    ipv4.dns-search:
    ipv4.dns-options:                       (default)
    ipv4.dns-priority:                      0
    ipv4.addresses:
    ipv4.gateway:                           --
    ipv4.routes:
    ipv4.route-metric:                      -1
    ipv4.ignore-auto-routes:                no
    ipv4.ignore-auto-dns:                   no
    ipv4.dhcp-client-id:                    --
    ipv4.dhcp-timeout:                      0
    ipv4.dhcp-send-hostname:                yes
    ipv4.dhcp-hostname:                     --
    ipv4.dhcp-fqdn:                         --
    ipv4.never-default:                     no
    ipv4.may-fail:                          yes
    ipv4.dad-timeout:                       -1 (default)
    ipv6.method:                            auto
    ipv6.dns:
    ipv6.dns-search:
    ipv6.dns-options:                       (default)
    ipv6.dns-priority:                      0
    ipv6.addresses:
    ipv6.gateway:                           --
    ipv6.routes:
    ipv6.route-metric:                      -1
    ipv6.ignore-auto-routes:                no
    ipv6.ignore-auto-dns:                   no
    ipv6.never-default:                     no
    ipv6.may-fail:                          yes
    ipv6.ip6-privacy:                       -1 (unknown)
    ipv6.addr-gen-mode:                     stable-privacy
    ipv6.dhcp-send-hostname:                yes
    ipv6.dhcp-hostname:                     --
    
  2. The output when disconnected, and the ESSID is present at creation/activation is:

    connection.id:                          aNetwork
    connection.uuid:                        10d2d80a-4f64-4466-9e4e-6190e4628d45
    connection.interface-name:              wlp2s0
    connection.type:                        802-11-wireless
    connection.autoconnect:                 yes
    connection.autoconnect-priority:        0
    connection.timestamp:                   1565600053
    connection.read-only:                   no
    connection.permissions:
    connection.zone:                        --
    connection.master:                      --
    connection.slave-type:                  --
    connection.autoconnect-slaves:          -1 (default)
    connection.secondaries:
    connection.gateway-ping-timeout:        0
    connection.metered:                     unknown
    connection.lldp:                        -1 (default)
    802-11-wireless.ssid:                   aNetwork
    802-11-wireless.mode:                   --
    802-11-wireless.band:                   --
    802-11-wireless.channel:                0
    802-11-wireless.bssid:                  --
    802-11-wireless.rate:                   0
    802-11-wireless.tx-power:               0
    802-11-wireless.mac-address:            --
    802-11-wireless.cloned-mac-address:     --
    802-11-wireless.mac-address-blacklist:
    802-11-wireless.mac-address-randomization:default
    802-11-wireless.mtu:                    auto
    802-11-wireless.seen-bssids:            9A:9B:CB:54:C4:5A
    802-11-wireless.hidden:                 no
    802-11-wireless.powersave:              default (0)
    802-11-wireless-security.key-mgmt:      wpa-psk
    802-11-wireless-security.wep-tx-keyidx: 0
    802-11-wireless-security.auth-alg:      --
    802-11-wireless-security.proto:
    802-11-wireless-security.pairwise:
    802-11-wireless-security.group:
    802-11-wireless-security.leap-username: --
    802-11-wireless-security.wep-key0:      <hidden>
    802-11-wireless-security.wep-key1:      <hidden>
    802-11-wireless-security.wep-key2:      <hidden>
    802-11-wireless-security.wep-key3:      <hidden>
    802-11-wireless-security.wep-key-flags: 0 (none)
    802-11-wireless-security.wep-key-type:  0 (unknown)
    802-11-wireless-security.psk:           <hidden>
    802-11-wireless-security.psk-flags:     0 (none)
    802-11-wireless-security.leap-password: <hidden>
    802-11-wireless-security.leap-password-flags:0 (none)
    ipv4.method:                            auto
    ipv4.dns:
    ipv4.dns-search:
    ipv4.dns-options:                       (default)
    ipv4.dns-priority:                      0
    ipv4.addresses:
    ipv4.gateway:                           --
    ipv4.routes:
    ipv4.route-metric:                      -1
    ipv4.ignore-auto-routes:                no
    ipv4.ignore-auto-dns:                   no
    ipv4.dhcp-client-id:                    --
    ipv4.dhcp-timeout:                      0
    ipv4.dhcp-send-hostname:                yes
    ipv4.dhcp-hostname:                     --
    ipv4.dhcp-fqdn:                         --
    ipv4.never-default:                     no
    ipv4.may-fail:                          yes
    ipv4.dad-timeout:                       -1 (default)
    ipv6.method:                            auto
    ipv6.dns:
    ipv6.dns-search:
    ipv6.dns-options:                       (default)
    ipv6.dns-priority:                       0
    ipv6.addresses:
    ipv6.gateway:                            --
    ipv6.routes:
    ipv6.route-metric:                       -1
    ipv6.ignore-auto-routes:                 no
    ipv6.ignore-auto-dns:                    no
    ipv6.never-default:                      no
    ipv6.may-fail:                           yes
    ipv6.ip6-privacy:                        -1 (unknown)
    ipv6.addr-gen-mode:                      stable-privacy
    ipv6.dhcp-send-hostname:                 yes
    ipv6.dhcp-hostname:                      --
    GENERAL.NAME:                            aNetwork
    GENERAL.UUID:                            10d2d80a-4f64-4466-9e4e-6190e4628d45
    GENERAL.DEVICES:                         wlp2s0
    GENERAL.STATE:                           activated
    GENERAL.DEFAULT:                         no
    GENERAL.DEFAULT6:                        no
    GENERAL.VPN:                             no
    GENERAL.ZONE:                            --
    GENERAL.DBUS-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/15
    GENERAL.CON-PATH:                        /org/freedesktop/NetworkManager/Settings/11
    GENERAL.SPEC-OBJECT:                     /org/freedesktop/NetworkManager/AccessPoint/12
    GENERAL.MASTER-PATH:                     --
    IP4.ADDRESS[1]:                          192.168.179.29/24
    IP4.GATEWAY:                             192.168.179.1
    IP4.DNS[1]:                              192.168.179.1
    DHCP4.OPTION[1]:                         dhcp_rebinding_time = 18900
    DHCP4.OPTION[2]:                         requested_domain_search = 1
    DHCP4.OPTION[3]:                         requested_host_name = 1
    DHCP4.OPTION[4]:                         requested_time_offset = 1
    DHCP4.OPTION[5]:                         requested_domain_name = 1
    DHCP4.OPTION[6]:                         requested_rfc3442_classless_static_routes = 1
    DHCP4.OPTION[7]:                         requested_broadcast_address = 1
    DHCP4.OPTION[8]:                         requested_wpad = 1
    DHCP4.OPTION[9]:                         requested_netbios_scope = 1
    DHCP4.OPTION[10]:                        next_server = 192.168.179.1
    DHCP4.OPTION[11]:                        expiry = 1565621653
    DHCP4.OPTION[12]:                        requested_interface_mtu = 1
    DHCP4.OPTION[13]:                        requested_subnet_mask = 1
    DHCP4.OPTION[14]:                        routers = 192.168.179.1
    DHCP4.OPTION[15]:                        dhcp_message_type = 5
    DHCP4.OPTION[16]:                        ip_address = 192.168.179.29
    DHCP4.OPTION[17]:                        broadcast_address = 192.168.179.255
    DHCP4.OPTION[18]:                        requested_static_routes = 1
    DHCP4.OPTION[19]:                        dhcp_renewal_time = 10800
    DHCP4.OPTION[20]:                        requested_domain_name_servers = 1
    DHCP4.OPTION[21]:                        requested_ms_classless_static_routes = 1
    DHCP4.OPTION[22]:                        domain_name_servers = 192.168.179.1
    DHCP4.OPTION[23]:                        subnet_mask = 255.255.255.0
    DHCP4.OPTION[24]:                        dhcp_lease_time = 21600
    DHCP4.OPTION[25]:                        requested_ntp_servers = 1
    DHCP4.OPTION[26]:                        requested_netbios_name_servers = 1
    DHCP4.OPTION[27]:                        ntp_servers = 192.168.179.1
    DHCP4.OPTION[28]:                        network_number = 192.168.179.0
    DHCP4.OPTION[29]:                        requested_routers = 1
    DHCP4.OPTION[30]:                        dhcp_server_identifier = 192.168.179.1
    IP6.ADDRESS[1]:                          fd00::1:79ff:2a88:6b89:f5a3/64
    IP6.ADDRESS[2]:                          fd00::1:53f4:ea8b:a2c6:88bc/64
    IP6.ADDRESS[3]:                          fe80::42af:506a:16:1256/64
    IP6.GATEWAY:
    IP6.ROUTE[1]:                            dst = fd00:0:0:1::/64, nh = fe80::9a9b:cbff:fe54:c457, mt = 600
    IP6.DNS[1]:                              fd00::1:9a9b:cbff:fe54:c457
    DHCP6.OPTION[1]:                         requested_dhcp6_domain_search = 1
    DHCP6.OPTION[2]:                         dhcp6_name_servers = fd00::1:9a9b:cbff:fe54:c457
    DHCP6.OPTION[3]:                         dhcp6_server_id = 0:3:0:1:98:9b:cb:54:c4:57
    DHCP6.OPTION[4]:                         requested_dhcp6_client_id = 1
    DHCP6.OPTION[5]:                         requested_dhcp6_name_servers = 1
    DHCP6.OPTION[6]:                         dhcp6_client_id = 0:4:cd:4c:df:d9:4d:62:c6:97:e1:a2:ed:b7:68:6a:be:9c
    

Notice all the GENERAL. entries, including GENERAL.STATE Activated and entries for DBUS-PATH and CON-PATH so I'm lead to believe this is what is causing the connection to not auto-connect, but I don't really know where to go from here.

I need to:

  • be able to create the profile out of range of the network
  • have it auto-connect when it's in range.
  • use NetworkManager

How do i proceed from here?

3
  • thanks for the tidyup @Fabby In theory I could set a cron job to constantly try and bring the connection up using nmcli but in reality not practical. These are boxes with no active user login where the wifi(as a hotspot) comes to them with a support engineer. Another workaround of course is to make sure the ESSID is there at build time, again there are reasons of practicality why this cannot be ensured. Ideally I'd like to identify the root cause though, but failing that I will look at any and all workarounds
    – cim
    Commented Aug 13, 2019 at 6:22
  • @Fabby Ah right. That is exactly what I do. The nmcli commands from the profile creation above are taken from an ansible playbook that is used to build. The problem is the same, if the ESSID is not present at build (which it is not) then they will not connect when it is available.
    – cim
    Commented Aug 13, 2019 at 12:53
  • Answer and comments deleted. No further ideas, sorry.
    – Fabby
    Commented Aug 19, 2019 at 17:49

1 Answer 1

4

I ran into the same issue and after trying to debug it for a while, I went on Network Manager IRC channel and asked them directly. For Wi-Fi networks, this is intentional, the restriction comes from this check:

https://github.com/NetworkManager/NetworkManager/blob/master/src/devices/wifi/nm-device-wifi.c#L999

Quoting the comments just above the check:

    /* Don't autoconnect to networks that have been tried at least once
     * but haven't been successful, since these are often accidental choices
     * from the menu and the user may not know the password.
     */

The reasoning is questionable but that's what it is. If you look at /var/lib/NetworkManager/timestamps, you'll see that for the network it never connected to the timestamp value is 0. As far as I know, there is no way to change this value from D-Bus/nmcli, so you'll have to edit the file and eventually restart NetworkManager (no idea if the file is run when changed or on a periodic basis).

In my case, we're building Network Manager for an embedded distribution and have a chance to patch it in the process, so I commented out the check and it auto-connects to networks it never connected to before.

3
  • Just wanted to add...finally got around to testing this and it works like a charm, thanks again
    – cim
    Commented Nov 11, 2019 at 17:21
  • I'm sad to see that there is not any configuration to change this behaviour. Commented Mar 30, 2020 at 12:44
  • Just for the record, this behavior was reverted in 835175e. Commented Jun 22, 2020 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .