NetworkManagerでWi-Fiの優先順位を指定
自宅サーバを構築したとき、Wi-Fiアクセスポイントの優先順位の設定に失敗したので、その後調査しました。
nmcli connection modify ID connection.autoconnect-priorit N
というコマンドで自動接続時の優先順位を指定できます。「connection.autoconnect-priorit」については nm-settings(5) に説明があります。
The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority.
nm-settings(5)
IDの部分については nmcli(1) に説明があります。
The connection is identified by its name, UUID or D-Bus path. If ID is ambiguous, a keyword id, uuid or path can be used.
nmcli(1)
現在の状況を確認します。
# nmcli -f NAME,UUID,AUTOCONNECT,AUTOCONNECT-PRIORITY connection
NAME                             UUID                                  AUTOCONNECT  AUTOCONNECT-PRIORITY 
netplan-wlp1s0-my-ssid-1    37785b5a-4efd-39ce-bd60-449dfceed9fa  yes          0                    
netplan-wlp1s0-my-ssid-2    d6d63f96-1ec4-32a1-be37-43e8442e14cb  yes          0                    
netplan-wlp1s0-my-ssid-1-2  3dd3e85b-e1e0-3ced-8e75-bf95cfd370a4  yes          0 
my-ssid-1 を最優先、my-ssid-2 を次にします。
# nmcli connection modify netplan-wlp1s0-my-ssid-1  connection.autoconnect-priorit 100
# nmcli connection modify netplan-wlp1s0-my-ssid-2  connection.autoconnect-priorit 90
確認します。
# nmcli -f NAME,UUID,AUTOCONNECT,AUTOCONNECT-PRIORITY connection
NAME                             UUID                                  AUTOCONNECT  AUTOCONNECT-PRIORITY 
netplan-wlp1s0-my-ssid-1    37785b5a-4efd-39ce-bd60-449dfceed9fa  yes          100                    
netplan-wlp1s0-my-ssid-2    d6d63f96-1ec4-32a1-be37-43e8442e14cb  yes          90                    
netplan-wlp1s0-my-ssid-1-2  3dd3e85b-e1e0-3ced-8e75-bf95cfd370a4  yes          0 
なお、my-ssid-1 以外につながっていて、my-ssid-1 に接続し直したいときは以下のコマンドです。
# nmcli device wifi connect my-ssid-1
			