作为 Ubuntu 16.04 服务器自动构建过程的一部分,我使用它nmcli
来创建网络配置文件,包括无线。这是在没有窗口管理器的无头系统上进行的。
我注意到,当我创建一个配置文件并激活它时,如果接入点(AP)在激活时不存在,它将永远不会自动连接,无论随后是否可用。
我试图缩小问题的原因并相信它可能与 dbus 注册有关。
个人资料创建:
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"
从系统日志来看,它似乎正确添加了它并将其设置为扫描:
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
然而,在我使 AP 可见之后,它永远不会扫描/连接,但是当连接被激活时当 ESSID 在创建时存在时,我得到以下条目:
NetworkManager[489]: <debug> [1565287017.8330] device[0x1fb95f0] (wlp2s0): add_pending_action (3): 'scan'
但是当连接被激活并且 ESSID 在创建时不存在时,我得到了以下信息:
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'
其内容/etc/NetworkManager/system-connection/aNetwork
为:
[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
我已经diff
编辑了 ESSID 存在和不存在时创建的配置文件之间的内容,并且没有区别。
观察nmcli con show aNetwork
两者的输出可以发现很大的不同:
断开连接时的输出,不创建/激活时的 ESSID 是:
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: --
断开连接时的输出,以及ESSID 存在创建/激活时:
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
注意所有GENERAL.
条目,包括GENERAL.STATE Activated
和条目DBUS-PATH
,所以CON-PATH
我相信这就是导致连接无法自动连接的原因,但我真的不知道从这里该去哪里。
我需要:
- 能够在网络范围之外创建配置文件
- 当它处于范围内时自动连接。
- 使用 NetworkManager
我下一步该怎么做?
答案1
我遇到了同样的问题,尝试调试了一段时间后,我进入了网络管理器 IRC 频道并直接询问他们。对于 Wi-Fi 网络,这是有意为之,限制来自以下检查:
https://github.com/NetworkManager/NetworkManager/blob/master/src/devices/wifi/nm-device-wifi.c#L999
引用支票上方的评论:
/* 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.
*/
理由值得怀疑,但事实就是如此。如果你查看/var/lib/NetworkManager/timestamps
,你会发现对于它从未连接到的网络,时间戳值为0
。据我所知,没有办法从 D-Bus/nmcli 更改此值,因此你必须编辑该文件并最终重新启动 NetworkManager(不知道该文件是在更改时运行还是定期运行)。
就我而言,我们正在为嵌入式发行版构建网络管理器,并有机会在此过程中对其进行修补,因此我注释掉了检查,它会自动连接到以前从未连接过的网络。