大网数据广告活动
服务器运维问答

Get uuid of connection after adding it using nmcli

· 52CE 我爱测

I would like to add VPN connections to multiple machines and let them activate automatically when when using the default ethernet connection. However I need the UUID of the VPN connection I just added to configure the automatic c…

问题原文

原帖链接 · Septatrix · CC BY-SA 4.0

I would like to add VPN connections to multiple machines and let them activate automatically when when using the default ethernet connection. However I need the UUID of the VPN connection I just added to configure the automatic connection.

What I have so far is importing the VPN connection using:

$ sudo nmcli connection import type openvpn file some_dynamic_name.ovpn
Verbindung »some_dynamic_name« (0724d07e-4a31-488d-91e8-fd6031679dd6) erfolgreich hinzugefügt.

Where some_dynamic_name should be the connection.id and the uuid corresponds to the connection.uuid. Given this UUID I can now configure my target connection to automatically use the VPN using:

$ nmcli connection modify "Kabelgebundene Verbindung 1" connection.secondaries 0724d07e-4a31-488d-91e8-fd6031679dd6

Theoretically I could parse the output and pass it to the second command though I do not know if the output can be considered stable and I would like to add this to a script for unattended setup. Can I somehow specify the output format for the response? I know I can pass --get-values connection.uuid to the import command (directly after nmcli) though that does not change anything

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

Since you know the name of the connection, you can use -g / --get-values to get its UUID after it has been created.

# nmcli --get-values connection.uuid c show "some_dynamic_name"
0724d07e-4a31-488d-91e8-fd6031679dd6

You could do it in one shot with shell substitution, something like this:

# nmcli c mod "Kabelgebundene Verbindung 1" connection.secondaries $(nmcli -g connection.uuid c show "some_dynamic_name")

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-06-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。