用NetworkManager的 nmcli connection modify 连接的名称或UUID ipv4.address 来设置IPV4
用NetworkManager的 nmcli connection modify 连接的名称或UUID ipv4.address 来设置IP 的模板
只设置修改IP
覆盖原有设置: ipv4.addresses
或ipv4.addr
或ipv4.a
NameOrUuidOfConnection="连接名或UUID" #### 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.addresses "1.2.3.1/8 , 1.2.3.2/8, 1.2.3.3/8,1.2.3.4/8" ;
sudo nmcli connection down "${NameOrUuidOfConnection}"; sudo nmcli connection up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
只添加IP
在原有基础上添加:前面加加号 +ipv4.addresses
或+ipv4.addr
或+ipv4.a
NameOrUuidOfConnection="连接名或UUID" #### 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
+ipv4.addresses "1.2.3.1/8 , 1.2.3.2/8, 1.2.3.3/8,1.2.3.4/8" ;
sudo nmcli connection down "${NameOrUuidOfConnection}"; sudo nmcli connection up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
删除指定IP
在原有基础上添加:前面加减号 -ipv4.addresses
或-ipv4.addr
或-ipv4.a
NameOrUuidOfConnection="连接名或UUID" #### 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
-ipv4.addresses "1.2.3.1/8 , 1.2.3.2/8, 1.2.3.3/8,1.2.3.4/8" ;
sudo nmcli connection down "${NameOrUuidOfConnection}"; sudo nmcli connection up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
设置静态IP的模板1
NameOrUuidOfConnection="ba4afbc8-c846-3a49-b222-18ee39f8c6cc" #### 连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.method 'manual' \
ipv4.addresses "1.20.46.30/8 , 1.20.46.31/8, 1.20.46.32/8 ,1.20.46.33/8,1.20.46.34/8,1.20.46.35/8 ,1.2.3.4,5.6.7.8,1.2.3.4/6,5.6.7.8/6 , 192.168.3.3 , 192.168.3.3/8 , 192.168.3.3/16 , 192.168.3.3/24 , 192.168.3.3/32 " \
+ipv4.a 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
-ipv4.addr 1.20.46.30/8,1.20.46.37/8,1.20.46.39/8,1.20.46.40/8,1.20.46.41,1.20.46.42/8 \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114,114.114.115.115 , 4.2.2.1,4.2.2.2" \
ipv4.dns-search 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c down "${NameOrUuidOfConnection}"; sudo nmcli c up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
代码说明 , 不能直接粘贴使用, 反斜杠\之后必须换行, 空格都不能有
"${NameOrUuidOfConnection}"要加双引号,不加的话连接名称不能有空格
NameOrUuidOfConnection=“ba4afbc8-c846-3a49-b222-18ee39f8c6cc” ####
连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show
查看 sudo nmcli connection modify “KaTeX parse error: Expected 'EOF', got '#' at position 35: …tion}" \ #̲## nmcli connec…{NameOrUuidOfConnection}”; sudo nmcli c up
“${NameOrUuidOfConnection}”; #### nmcli connection dowan 和 nmcli
connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
简化名称
命令简写
NameOrUuidOfConnection="ba4afbc8-c846-3a49-b222-18ee39f8c6cc" #### 连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli c n "${NameOrUuidOfConnection}" \
ipv4.me 'manual' \
ipv4.a "1.20.46.30/8 , 1.20.46.31/8, 1.20.46.32/8 ,1.20.46.33/8,1.20.46.34/8,1.20.46.35/8 ,1.2.3.4,5.6.7.8,1.2.3.4/6,5.6.7.8/6 , 192.168.3.3 , 192.168.3.3/8 , 192.168.3.3/16 , 192.168.3.3/24 , 192.168.3.3/32 " \
+ipv4.a 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
-ipv4.a 1.20.46.30/8,1.20.46.37/8,1.20.46.39/8,1.20.46.40/8,1.20.46.41,1.20.46.42/8 \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114,114.114.115.115 , 4.2.2.1,4.2.2.2" \
ipv4.dns-search 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c d "${NameOrUuidOfConnection}"; sudo nmcli c u "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
简化内容
不要 +ipv4.addresses
, -ipv4.addresses
和搜索域 +ipv4.dns-search
NameOrUuidOfConnection="连接的名称或UUID" #### 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.method 'manual' \
ipv4.addresses "1.2.3.1/8 , 1.2.3.2/8, 1.2.3.3/8,1.2.3.4/8" \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114 , 114.114.115.115 , 4.2.2.1,4.2.2.2" \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli connection down "${NameOrUuidOfConnection}"; sudo nmcli connection up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
简化名称和内容
NameOrUuidOfConnection="连接的名称或UUID" #### 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli c m "${NameOrUuidOfConnection}" \
ipv4.me 'manual' \
ipv4.a "1.2.3.1/8 , 1.2.3.2/8, 1.2.3.3/8,1.2.3.4/8" \
ipv4.g "1.0.0.2" \
ipv4.ignore-auto-d 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114 , 114.114.115.115 , 4.2.2.1,4.2.2.2" \
ipv4.dns-s 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c d "${NameOrUuidOfConnection}"; sudo nmcli c u "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
测试演示
测试演示1
在 Ubuntu20.04.06下测试
NameOrUuidOfConnection="ba4afbc8-c846-3a49-b222-18ee39f8c6cc" #### 连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.method 'manual' \
ipv4.addresses "1.20.46.30/8 , 1.20.46.31/8, 1.20.46.32/8 ,1.20.46.33/8,1.20.46.34/8,1.20.46.35/8 ,1.2.3.4,5.6.7.8,1.2.3.4/6,5.6.7.8/6 , 192.168.3.3 , 192.168.3.3/8 , 192.168.3.3/16 , 192.168.3.3/24 , 192.168.3.3/32 " \
+ipv4.a 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
-ipv4.addr 1.20.46.30/8,1.20.46.37/8,1.20.46.39/8,1.20.46.40/8,1.20.46.41,1.20.46.42/8 \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114 , 114.114.115.115" \
ipv4.dns-search 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c down "${NameOrUuidOfConnection}"; sudo nmcli c up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
代码说明 , 不能直接粘贴使用, 反斜杠\之后必须换行, 空格都不能有
NameOrUuidOfConnection=“ba4afbc8-c846-3a49-b222-18ee39f8c6cc” ####
连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show
查看 sudo nmcli connection modify “KaTeX parse error: Expected 'EOF', got '#' at position 35: …tion}" \ #̲## nmcli connec…{NameOrUuidOfConnection}”; sudo nmcli c up
“${NameOrUuidOfConnection}”; #### nmcli connection dowan 和 nmcli
connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
上面的代码在 /etc/NetworkManager/system-connections
文件夹中生成了一个 以连接名开头的.nmconnection
文件
root@ud2046:/etc/NetworkManager/system-connections# ls
'Wired connection 3.nmconnection'
内容如下
[connection]
id=Wired connection 3
uuid=ba4afbc8-c846-3a49-b222-18ee39f8c6cc
type=ethernet
autoconnect-priority=-999
interface-name=ens38
permissions=
timestamp=1718738263[ethernet]
mac-address-blacklist=[ipv4]
address1=1.20.46.31/8,1.0.0.2
address2=1.20.46.32/8
address3=1.20.46.33/8
address4=1.20.46.34/8
address5=1.20.46.35/8
address6=1.2.3.4/32
address7=5.6.7.8/32
address8=1.2.3.4/6
address9=5.6.7.8/6
address10=192.168.3.3/32
address11=192.168.3.3/8
address12=192.168.3.3/16
address13=192.168.3.3/24
address14=1.20.46.36/8
address15=1.20.46.38/8
dns=180.76.76.76;223.6.6.6;119.29.29.29;223.5.5.5;1.1.1.1;8.8.8.8;114.114.114.114;114.114.115.115;
dns-search=baidu.com;
ignore-auto-dns=true
method=manual[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto[proxy]
执行 ip a|grep 'inet '
的结果
root@ud2046:/home/z# ip a|grep 'inet 'inet 127.0.0.1/8 scope host loinet 1.128.0.4/8 brd 1.255.255.255 scope global dynamic noprefixroute ens33inet 1.128.0.21/8 brd 1.255.255.255 scope global dynamic noprefixroute ens37inet 1.20.46.31/8 brd 1.255.255.255 scope global noprefixroute ens38inet 1.2.3.4/32 scope global noprefixroute ens38inet 5.6.7.8/32 scope global noprefixroute ens38inet 1.2.3.4/6 brd 3.255.255.255 scope global noprefixroute ens38inet 5.6.7.8/6 brd 7.255.255.255 scope global noprefixroute ens38inet 192.168.3.3/32 scope global noprefixroute ens38inet 192.168.3.3/8 brd 192.255.255.255 scope global noprefixroute ens38inet 192.168.3.3/16 brd 192.168.255.255 scope global noprefixroute ens38inet 192.168.3.3/24 brd 192.168.3.255 scope global noprefixroute ens38inet 1.20.46.32/8 brd 1.255.255.255 scope global secondary noprefixroute ens38inet 1.20.46.33/8 brd 1.255.255.255 scope global secondary noprefixroute ens38inet 1.20.46.34/8 brd 1.255.255.255 scope global secondary noprefixroute ens38inet 1.20.46.35/8 brd 1.255.255.255 scope global secondary noprefixroute ens38inet 1.20.46.36/8 brd 1.255.255.255 scope global secondary noprefixroute ens38inet 1.20.46.38/8 brd 1.255.255.255 scope global secondary noprefixroute ens38
可看出
- ip可设置多个, 不像Windows那样限制为1个
- 不设置子网掩码的ip, 子网掩码为32,
1.2.3.4
等效1.2.3.4/32
- 相同ip不同子网掩码的条目被视为不同, 会分别添加
- 相同ip相同子网掩码的条目被视为相同, 不会重复添加
- 不存在的ip也可以写在
-ipv4.addresses
后面,不会报错,也没有影响. (24.04会出错,无法up连接) - 多个DNS的分隔,在
nmcli c m
命令中是逗号, 在连接名.nmconnection
文件中是分号 - 执行后, 继续执行
sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ;
并没有生效, 生效的方法是 -
- 重启系统
-
- 或者注销重新登录
-
- 或者在图形桌面右上角设置中关闭再打开对应的网络连接
-
- 或者执行
nmcli connection down 连接名称或UUID
再执行nmcli connection up 连接名称或UUID
- 或者执行
-
-
nmcli connection down
可简写为nmcli c d
-
-
-
nmcli connection up
可简写为nmcli c u
-
测试演示2
还是在 Ubuntu20.04下测试
NameOrUuidOfConnection="Wired connection 3" #### 连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.method 'manual' \
ipv4.addresses "1.20.46.30/8 , 1.20.46.31/8, 1.20.46.32/8 ,1.20.46.33/8,1.20.46.34/8,1.20.46.35/8 ,1.2.3.4,5.6.7.8,1.2.3.4/6,5.6.7.8/6 , 192.168.3.3 , 192.168.3.3/8 , 192.168.3.3/16 , 192.168.3.3/24 , 192.168.3.3/32 " \
+ipv4.a 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
+ipv4.addr 1.20.46.45/8,1.20.46.46/8,1.20.46.47/8,1.20.46.48/8,1.20.46.49/8,1.20.46.50/8 \
+ipv4.address 1.20.46.55/8,1.20.46.56/8,1.20.46.57/8,1.20.46.58/8,1.20.46.59/8,1.20.46.60/8 \
+ipv4.addresses 1.20.46.65/8,1.20.46.66/8,1.20.46.67/8,1.20.46.68/8,1.20.46.69/8,1.20.46.70/8 \
-ipv4.a 1.20.46.30/8,1.20.46.37/8,1.20.46.39/8,1.20.46.40/8,1.20.46.41,1.20.46.42/8 \
-ipv4.addr 1.20.46.45/8,1.20.46.46/8 \
-ipv4.address 1.20.46.47/8,1.20.46.48/8 \
-ipv4.addresses 1.20.46.49/8,1.20.46.50/8 \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114,114.114.115.115 , 4.2.2.1,4.2.2.2" \
ipv4.dns-search 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c down "${NameOrUuidOfConnection}"; sudo nmcli c up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
在 /etc/NetworkManager/system-connections
中生成的.nmconnection
文件内容如下
[connection]
id=Wired connection 3
uuid=ba4afbc8-c846-3a49-b222-18ee39f8c6cc
type=ethernet
autoconnect-priority=-999
interface-name=ens38
permissions=
timestamp=1718753140[ethernet]
mac-address-blacklist=[ipv4]
address1=1.20.46.31/8,1.0.0.2
address2=1.20.46.32/8
address3=1.20.46.33/8
address4=1.20.46.34/8
address5=1.20.46.35/8
address6=1.2.3.4/32
address7=5.6.7.8/32
address8=1.2.3.4/6
address9=5.6.7.8/6
address10=192.168.3.3/32
address11=192.168.3.3/8
address12=192.168.3.3/16
address13=192.168.3.3/24
address14=1.20.46.36/8
address15=1.20.46.38/8
address16=1.20.46.55/8
address17=1.20.46.56/8
address18=1.20.46.57/8
address19=1.20.46.58/8
address20=1.20.46.59/8
address21=1.20.46.60/8
address22=1.20.46.65/8
address23=1.20.46.66/8
address24=1.20.46.67/8
address25=1.20.46.68/8
address26=1.20.46.69/8
address27=1.20.46.70/8
dns=180.76.76.76;223.6.6.6;119.29.29.29;223.5.5.5;1.1.1.1;8.8.8.8;114.114.114.114;114.114.115.115;4.2.2.1;4.2.2.2;
dns-search=baidu.com;
ignore-auto-dns=true
method=manual[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto[proxy]
但同样的代码到 Ubuntu24.04中却执行不了了, 没法识别 ipv4.a
, 因为新版本增加了以a开头的命令, 最短要用ipv4.ad
上面同样的代码在CentOS7中可以执行, 也可以用 ipv4.a
, 但没有在 /etc/NetworkManager/system-connections
中生成.nmconnection
文件 , 而是在/etc/sysconfig/network-scripts
下生成了
ifcfg-有线连接_2
文件, 也可能是其它名称, 内容如下
HWADDR=00:0C:29:5E:80:51
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=1.20.46.31
PREFIX=8
IPADDR1=1.20.46.32
PREFIX1=8
IPADDR2=1.20.46.33
PREFIX2=8
IPADDR3=1.20.46.34
PREFIX3=8
IPADDR4=1.20.46.35
PREFIX4=8
IPADDR5=1.2.3.4
PREFIX5=32
IPADDR6=5.6.7.8
PREFIX6=32
IPADDR7=1.2.3.4
PREFIX7=6
IPADDR8=5.6.7.8
PREFIX8=6
IPADDR9=192.168.3.3
PREFIX9=32
IPADDR10=192.168.3.3
PREFIX10=8
IPADDR11=192.168.3.3
PREFIX11=16
IPADDR12=192.168.3.3
PREFIX12=24
IPADDR13=1.20.46.36
PREFIX13=8
IPADDR14=1.20.46.38
PREFIX14=8
IPADDR15=1.20.46.55
PREFIX15=8
IPADDR16=1.20.46.56
PREFIX16=8
IPADDR17=1.20.46.57
PREFIX17=8
IPADDR18=1.20.46.58
PREFIX18=8
IPADDR19=1.20.46.59
PREFIX19=8
IPADDR20=1.20.46.60
PREFIX20=8
IPADDR21=1.20.46.65
PREFIX21=8
IPADDR22=1.20.46.66
PREFIX22=8
IPADDR23=1.20.46.67
PREFIX23=8
IPADDR24=1.20.46.68
PREFIX24=8
IPADDR25=1.20.46.69
PREFIX25=8
IPADDR26=1.20.46.70
PREFIX26=8
GATEWAY=1.0.0.2
DNS1=180.76.76.76
DNS2=223.6.6.6
DNS3=119.29.29.29
DNS4=223.5.5.5
DNS5=1.1.1.1
DNS6=8.8.8.8
DNS7=114.114.114.114
DNS8=114.114.115.115
DNS9=4.2.2.1
DNS10=4.2.2.2
DOMAIN=baidu.com
DEFROUTE=yes
PEERDNS=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=$'\746\634\611\747\672\677\750\677\636\746\616\645 2'
UUID=c3f172fc-f403-3380-9c1d-94533d978c96
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
但同样的代码到 Ubuntu24.04中却执行不了了, 没法识别 ipv4.a
, 因为新版本增加了以a开头的命令, 最短要用ipv4.ad
,改为 ipv4.ad
后可以执行, 但没有在 /etc/NetworkManager/system-connections
中生成.nmconnection
文件 , 而是在/etc/netplan
下生成了90-NM-09d97ac1-b4e0-3111-a994-60b64f6f6b98.yaml
文件, 09d97ac1-b4e0-3111-a994-60b64f6f6b98对应连接的UUID, 内容如下
network:version: 2ethernets:ens35:renderer: NetworkManagermatch: {}addresses:- "1.20.46.31/8"- "1.20.46.32/8"- "1.20.46.33/8"- "1.20.46.34/8"- "1.20.46.35/8"- "1.2.3.4/32"- "5.6.7.8/32"- "1.2.3.4/6"- "5.6.7.8/6"- "192.168.3.3/32"- "192.168.3.3/8"- "192.168.3.3/16"- "192.168.3.3/24"- "1.20.46.36/8"- "1.20.46.38/8"- "1.20.46.55/8"- "1.20.46.56/8"- "1.20.46.57/8"- "1.20.46.58/8"- "1.20.46.59/8"- "1.20.46.60/8"- "1.20.46.65/8"- "1.20.46.66/8"- "1.20.46.67/8"- "1.20.46.68/8"- "1.20.46.69/8"- "1.20.46.70/8"nameservers:addresses:- 180.76.76.76- 223.6.6.6- 119.29.29.29- 223.5.5.5- 1.1.1.1- 8.8.8.8- 114.114.114.114- 114.114.115.115- 4.2.2.1- 4.2.2.2networkmanager:uuid: "09d97ac1-b4e0-3111-a994-60b64f6f6b98"name: "netplan-ens35"passthrough:connection.timestamp: "1718758772"ipv4.address1: "1.20.46.31/8,1.0.0.2"ipv4.dns-search: "baidu.com;"ipv4.ignore-auto-dns: "true"ipv4.method: "manual"proxy._: ""
但 nmcli c down
后,没法 nmcli c up
启动连接
原因是 不能用-inet4.addresses
去移除不存在的ip,
于是将脚本改成, 增加的和删除的一样,
另外, IP冲突也可能有莫名其妙的影响, 关掉多余系统, 更换IP
NameOrUuidOfConnection="netplan-ens35" #### 连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.method 'manual' \
ipv4.addresses "1.24.4.30/8 , 1.24.4.31/8, 1.24.4.32/8 ,1.24.4.33/8,1.24.4.34/8,1.24.4.35/8 ,1.2.3.4,5.6.7.8,1.2.3.4/6,5.6.7.8/6 , 192.168.3.3 , 192.168.3.3/8 , 192.168.3.3/16 , 192.168.3.3/24 , 192.168.3.3/32 " \
+ipv4.ad 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
+ipv4.addr 1.20.46.45/8,1.20.46.46/8,1.20.46.47/8,1.20.46.48/8,1.20.46.49/8,1.20.46.50/8 \
+ipv4.address 1.20.46.55/8,1.20.46.56/8,1.20.46.57/8,1.20.46.58/8,1.20.46.59/8,1.20.46.60/8 \
+ipv4.addresses 1.20.46.65/8,1.20.46.66/8,1.20.46.67/8,1.20.46.68/8,1.20.46.69/8,1.20.46.70/8 \
-ipv4.ad 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
-ipv4.addr 1.20.46.45/8,1.20.46.46/8,1.20.46.47/8,1.20.46.48/8,1.20.46.49/8,1.20.46.50/8 \
-ipv4.address 1.20.46.55/8,1.20.46.56/8,1.20.46.57/8,1.20.46.58/8,1.20.46.59/8,1.20.46.60/8 \
-ipv4.addresses 1.20.46.65/8,1.20.46.66/8,1.20.46.67/8,1.20.46.68/8,1.20.46.69/8,1.20.46.70/8 \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114,114.114.115.115 , 4.2.2.1,4.2.2.2" \
ipv4.dns-search 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c down "${NameOrUuidOfConnection}"; sudo nmcli c up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
执行 netplan -get
命令到生成的yaml为
network:version: 2renderer: NetworkManagerethernets:ens33:dhcp4: trueens34:dhcp4: trueens35:renderer: NetworkManagermatch:name: "ens35"addresses:- "1.24.4.30/8"- "1.24.4.31/8"- "1.24.4.32/8"- "1.24.4.33/8"- "1.24.4.34/8"- "1.24.4.35/8"- "1.2.3.4/32"- "5.6.7.8/32"- "1.2.3.4/6"- "5.6.7.8/6"- "192.168.3.3/32"- "192.168.3.3/8"- "192.168.3.3/16"- "192.168.3.3/24"nameservers:addresses:- 180.76.76.76- 223.6.6.6- 119.29.29.29- 223.5.5.5- 1.1.1.1- 8.8.8.8- 114.114.114.114- 114.114.115.115- 4.2.2.1- 4.2.2.2dhcp4: truenetworkmanager:uuid: "09d97ac1-b4e0-3111-a994-60b64f6f6b98"name: "netplan-ens35"passthrough:connection.timestamp: "1718763322"ipv4.address1: "1.24.4.30/8,1.0.0.2"ipv4.dns-search: "baidu.com;"ipv4.ignore-auto-dns: "true"ipv4.method: "manual"proxy._: ""
更多IP尝试
NameOrUuidOfConnection="netplan-ens35" #### 连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.method 'manual' \
ipv4.addresses "1.24.4.30/8 , 1.24.4.31/8, 1.24.4.32/8 ,1.24.4.33/8,1.24.4.34/8,1.24.4.35/8 , " \
+ipv4.address "1.244.35.0/8,1.244.35.1/8,1.244.35.2/8,1.244.35.3/8,1.244.35.4/8,1.244.35.5/8,1.244.35.6/8,1.244.35.7/8,1.244.35.8/8,1.244.35.9/8,1.244.35.10/8,1.244.35.11/8,1.244.35.12/8,1.244.35.13/8,1.244.35.14/8,1.244.35.15/8,1.244.35.16/8,1.244.35.17/8,1.244.35.18/8,1.244.35.19/8,1.244.35.20/8,1.244.35.21/8,1.244.35.22/8,1.244.35.23/8,1.244.35.24/8,1.244.35.25/8,1.244.35.26/8,1.244.35.27/8,1.244.35.28/8,1.244.35.29/8,1.244.35.30/8,1.244.35.31/8,1.244.35.32/8,1.244.35.33/8,1.244.35.34/8,1.244.35.35/8,1.244.35.36/8,1.244.35.37/8,1.244.35.38/8,1.244.35.39/8,1.244.35.40/8,1.244.35.41/8,1.244.35.42/8,1.244.35.43/8,1.244.35.44/8,1.244.35.45/8,1.244.35.46/8,1.244.35.47/8,1.244.35.48/8,1.244.35.49/8,1.244.35.50/8,1.244.35.51/8,1.244.35.52/8,1.244.35.53/8,1.244.35.54/8,1.244.35.55/8,1.244.35.56/8,1.244.35.57/8,1.244.35.58/8,1.244.35.59/8,1.244.35.60/8,1.244.35.61/8,1.244.35.62/8,1.244.35.63/8,1.244.35.64/8,1.244.35.65/8,1.244.35.66/8,1.244.35.67/8,1.244.35.68/8,1.244.35.69/8,1.244.35.70/8,1.244.35.71/8,1.244.35.72/8,1.244.35.73/8,1.244.35.74/8,1.244.35.75/8,1.244.35.76/8,1.244.35.77/8,1.244.35.78/8,1.244.35.79/8,1.244.35.80/8,1.244.35.81/8,1.244.35.82/8,1.244.35.83/8,1.244.35.84/8,1.244.35.85/8,1.244.35.86/8,1.244.35.87/8,1.244.35.88/8,1.244.35.89/8,1.244.35.90/8,1.244.35.91/8,1.244.35.92/8,1.244.35.93/8,1.244.35.94/8,1.244.35.95/8,1.244.35.96/8,1.244.35.97/8,1.244.35.98/8,1.244.35.99/8, " \
+ipv4.ad 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
+ipv4.addr 1.20.46.45/8,1.20.46.46/8,1.20.46.47/8,1.20.46.48/8,1.20.46.49/8,1.20.46.50/8 \
+ipv4.address 1.20.46.55/8,1.20.46.56/8,1.20.46.57/8,1.20.46.58/8,1.20.46.59/8,1.20.46.60/8 \
+ipv4.addresses 1.20.46.65/8,1.20.46.66/8,1.20.46.67/8,1.20.46.68/8,1.20.46.69/8,1.20.46.70/8 \
-ipv4.ad 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
-ipv4.addr 1.20.46.45/8,1.20.46.46/8,1.20.46.47/8,1.20.46.48/8,1.20.46.49/8,1.20.46.50/8 \
-ipv4.address 1.20.46.55/8,1.20.46.56/8,1.20.46.57/8,1.20.46.58/8,1.20.46.59/8,1.20.46.60/8 \
-ipv4.addresses 1.20.46.65/8,1.20.46.66/8,1.20.46.67/8,1.20.46.68/8,1.20.46.69/8,1.20.46.70/8 \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114,114.114.115.115 , 4.2.2.1,4.2.2.2" \
ipv4.dns-search 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c down "${NameOrUuidOfConnection}"; sudo nmcli c up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
应用成功
NameOrUuidOfConnection="netplan-ens35" #### 连接名或UUID 连接的名称或UUID可用 nmcli c 或 nmcli c s 或 nmcli connection show 查看
sudo nmcli connection modify "${NameOrUuidOfConnection}" \
ipv4.method 'manual' \
ipv4.addresses "1.24.4.30/8 , 1.24.4.31/8, 1.24.4.32/8 ,1.24.4.33/8,1.24.4.34/8,1.24.4.35/8 , " \
+ipv4.address "1.244.35.0/8,1.244.35.1/8,1.244.35.2/8,1.244.35.3/8,1.244.35.4/8,1.244.35.5/8,1.244.35.6/8,1.244.35.7/8,1.244.35.8/8,1.244.35.9/8,1.244.35.10/8,1.244.35.11/8,1.244.35.12/8,1.244.35.13/8,1.244.35.14/8,1.244.35.15/8,1.244.35.16/8,1.244.35.17/8,1.244.35.18/8,1.244.35.19/8,1.244.35.20/8,1.244.35.21/8,1.244.35.22/8,1.244.35.23/8,1.244.35.24/8,1.244.35.25/8,1.244.35.26/8,1.244.35.27/8,1.244.35.28/8,1.244.35.29/8,1.244.35.30/8,1.244.35.31/8,1.244.35.32/8,1.244.35.33/8,1.244.35.34/8,1.244.35.35/8,1.244.35.36/8,1.244.35.37/8,1.244.35.38/8,1.244.35.39/8,1.244.35.40/8,1.244.35.41/8,1.244.35.42/8,1.244.35.43/8,1.244.35.44/8,1.244.35.45/8,1.244.35.46/8,1.244.35.47/8,1.244.35.48/8,1.244.35.49/8,1.244.35.50/8,1.244.35.51/8,1.244.35.52/8,1.244.35.53/8,1.244.35.54/8,1.244.35.55/8,1.244.35.56/8,1.244.35.57/8,1.244.35.58/8,1.244.35.59/8,1.244.35.60/8,1.244.35.61/8,1.244.35.62/8,1.244.35.63/8,1.244.35.64/8,1.244.35.65/8,1.244.35.66/8,1.244.35.67/8,1.244.35.68/8,1.244.35.69/8,1.244.35.70/8,1.244.35.71/8,1.244.35.72/8,1.244.35.73/8,1.244.35.74/8,1.244.35.75/8,1.244.35.76/8,1.244.35.77/8,1.244.35.78/8,1.244.35.79/8,1.244.35.80/8,1.244.35.81/8,1.244.35.82/8,1.244.35.83/8,1.244.35.84/8,1.244.35.85/8,1.244.35.86/8,1.244.35.87/8,1.244.35.88/8,1.244.35.89/8,1.244.35.90/8,1.244.35.91/8,1.244.35.92/8,1.244.35.93/8,1.244.35.94/8,1.244.35.95/8,1.244.35.96/8,1.244.35.97/8,1.244.35.98/8,1.244.35.99/8, " \
+ipv4.ad 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
+ipv4.addr 1.20.46.45/8,1.20.46.46/8,1.20.46.47/8,1.20.46.48/8,1.20.46.49/8,1.20.46.50/8 \
+ipv4.address 1.20.46.55/8,1.20.46.56/8,1.20.46.57/8,1.20.46.58/8,1.20.46.59/8,1.20.46.60/8 \
+ipv4.addresses 1.20.46.65/8,1.20.46.66/8,1.20.46.67/8,1.20.46.68/8,1.20.46.69/8,1.20.46.70/8 \
-ipv4.ad 1.20.46.35/8,1.20.46.36/8,1.20.46.37/8,1.20.46.38/8,1.20.46.39/8,1.20.46.40/8 \
-ipv4.addr 1.20.46.45/8,1.20.46.46/8,1.20.46.47/8,1.20.46.48/8,1.20.46.49/8,1.20.46.50/8 \
-ipv4.address 1.20.46.55/8,1.20.46.56/8,1.20.46.57/8,1.20.46.58/8,1.20.46.59/8,1.20.46.60/8 \
-ipv4.addresses 1.20.46.65/8,1.20.46.66/8,1.20.46.67/8,1.20.46.68/8,1.20.46.69/8,1.20.46.70/8 \
ipv4.gateway "1.0.0.2" \
ipv4.ignore-auto-dns 'true' \
ipv4.dns "180.76.76.76 , 223.6.6.6 , 119.29.29.29, 223.5.5.5 1.1.1.1,8.8.8.8,114.114.114.114,114.114.115.115 , 4.2.2.1,4.2.2.2" \
ipv4.dns-search 'baidu.com' ; \
# sudo systemctl reload NetworkManager ; sudo systemctl restart NetworkManager ; #### 重启NetworkManager, 好像没效果, 要关闭再打开连接或重启系统,才生效
sudo nmcli c down "${NameOrUuidOfConnection}"; sudo nmcli c up "${NameOrUuidOfConnection}"; #### nmcli connection dowan 和 nmcli connection up 效果如同图形界面桌面右上角网络设置的开启和关闭
Connection 'netplan-ens35' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
root@z-VMware20-1:~# ip a|grep 'inet 'inet 127.0.0.1/8 scope host loinet 1.244.33.0/8 brd 1.255.255.255 scope global noprefixroute ens33inet 1.244.33.1/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.2/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.3/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.4/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.5/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.6/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.7/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.8/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.244.33.9/8 brd 1.255.255.255 scope global secondary noprefixroute ens33inet 1.128.0.24/8 brd 1.255.255.255 scope global dynamic noprefixroute ens34inet 1.24.4.30/8 brd 1.255.255.255 scope global noprefixroute ens35inet 1.24.4.31/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.24.4.32/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.24.4.33/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.24.4.34/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.24.4.35/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.0/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.1/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.2/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.3/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.4/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.5/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.6/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.7/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.8/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.9/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.10/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.11/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.12/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.13/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.14/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.15/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.16/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.17/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.18/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.19/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.20/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.21/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.22/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.23/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.24/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.25/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.26/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.27/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.28/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.29/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.30/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.31/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.32/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.33/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.34/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.35/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.36/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.37/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.38/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.39/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.40/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.41/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.42/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.43/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.44/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.45/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.46/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.47/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.48/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.49/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.50/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.51/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.52/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.53/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.54/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.55/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.56/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.57/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.58/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.59/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.60/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.61/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.62/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.63/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.64/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.65/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.66/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.67/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.68/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.69/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.70/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.71/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.72/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.73/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.74/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.75/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.76/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.77/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.78/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.79/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.80/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.81/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.82/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.83/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.84/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.85/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.86/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.87/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.88/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.89/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.90/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.91/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.92/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.93/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.94/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.95/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.96/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.97/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.98/8 brd 1.255.255.255 scope global secondary noprefixroute ens35inet 1.244.35.99/8 brd 1.255.255.255 scope global secondary noprefixroute ens35
netplan get
查看生成的yaml
network:version: 2renderer: NetworkManagerethernets:ens33:renderer: NetworkManagermatch:name: "ens33"addresses:- "1.244.33.0/8"- "1.244.33.1/8"- "1.244.33.2/8"- "1.244.33.3/8"- "1.244.33.4/8"- "1.244.33.5/8"- "1.244.33.6/8"- "1.244.33.7/8"- "1.244.33.8/8"- "1.244.33.9/8"nameservers:addresses:- 180.76.76.76- 223.6.6.6- 119.29.29.29- 223.5.5.5- 1.1.1.1- 8.8.8.8- 114.114.114.114- 114.114.115.115- 4.2.2.1- 4.2.2.2dhcp4: truenetworkmanager:uuid: "14f59568-5076-387a-aef6-10adfcca2e26"name: "netplan-ens33"passthrough:connection.timestamp: "1718762948"ipv4.address1: "1.244.33.0/8,1.0.0.2"ipv4.dns-search: "baidu.com;"ipv4.ignore-auto-dns: "true"ipv4.method: "manual"proxy._: ""ens34:dhcp4: trueens35:renderer: NetworkManagermatch:name: "ens35"addresses:- "1.24.4.30/8"- "1.24.4.31/8"- "1.24.4.32/8"- "1.24.4.33/8"- "1.24.4.34/8"- "1.24.4.35/8"- "1.244.35.0/8"- "1.244.35.1/8"- "1.244.35.2/8"- "1.244.35.3/8"- "1.244.35.4/8"- "1.244.35.5/8"- "1.244.35.6/8"- "1.244.35.7/8"- "1.244.35.8/8"- "1.244.35.9/8"- "1.244.35.10/8"- "1.244.35.11/8"- "1.244.35.12/8"- "1.244.35.13/8"- "1.244.35.14/8"- "1.244.35.15/8"- "1.244.35.16/8"- "1.244.35.17/8"- "1.244.35.18/8"- "1.244.35.19/8"- "1.244.35.20/8"- "1.244.35.21/8"- "1.244.35.22/8"- "1.244.35.23/8"- "1.244.35.24/8"- "1.244.35.25/8"- "1.244.35.26/8"- "1.244.35.27/8"- "1.244.35.28/8"- "1.244.35.29/8"- "1.244.35.30/8"- "1.244.35.31/8"- "1.244.35.32/8"- "1.244.35.33/8"- "1.244.35.34/8"- "1.244.35.35/8"- "1.244.35.36/8"- "1.244.35.37/8"- "1.244.35.38/8"- "1.244.35.39/8"- "1.244.35.40/8"- "1.244.35.41/8"- "1.244.35.42/8"- "1.244.35.43/8"- "1.244.35.44/8"- "1.244.35.45/8"- "1.244.35.46/8"- "1.244.35.47/8"- "1.244.35.48/8"- "1.244.35.49/8"- "1.244.35.50/8"- "1.244.35.51/8"- "1.244.35.52/8"- "1.244.35.53/8"- "1.244.35.54/8"- "1.244.35.55/8"- "1.244.35.56/8"- "1.244.35.57/8"- "1.244.35.58/8"- "1.244.35.59/8"- "1.244.35.60/8"- "1.244.35.61/8"- "1.244.35.62/8"- "1.244.35.63/8"- "1.244.35.64/8"- "1.244.35.65/8"- "1.244.35.66/8"- "1.244.35.67/8"- "1.244.35.68/8"- "1.244.35.69/8"- "1.244.35.70/8"- "1.244.35.71/8"- "1.244.35.72/8"- "1.244.35.73/8"- "1.244.35.74/8"- "1.244.35.75/8"- "1.244.35.76/8"- "1.244.35.77/8"- "1.244.35.78/8"- "1.244.35.79/8"- "1.244.35.80/8"- "1.244.35.81/8"- "1.244.35.82/8"- "1.244.35.83/8"- "1.244.35.84/8"- "1.244.35.85/8"- "1.244.35.86/8"- "1.244.35.87/8"- "1.244.35.88/8"- "1.244.35.89/8"- "1.244.35.90/8"- "1.244.35.91/8"- "1.244.35.92/8"- "1.244.35.93/8"- "1.244.35.94/8"- "1.244.35.95/8"- "1.244.35.96/8"- "1.244.35.97/8"- "1.244.35.98/8"- "1.244.35.99/8"nameservers:addresses:- 180.76.76.76- 223.6.6.6- 119.29.29.29- 223.5.5.5- 1.1.1.1- 8.8.8.8- 114.114.114.114- 114.114.115.115- 4.2.2.1- 4.2.2.2dhcp4: truenetworkmanager:uuid: "09d97ac1-b4e0-3111-a994-60b64f6f6b98"name: "netplan-ens35"passthrough:connection.timestamp: "1718766061"ipv4.address1: "1.24.4.30/8,1.0.0.2"ipv4.dns-search: "baidu.com;"ipv4.ignore-auto-dns: "true"ipv4.method: "manual"proxy._: ""
命令简写
con
可以写成c
到connection
之间的字段mod
可以写成m
到modify
之间的字段nmcli connection modify nmcli connect modify nmcli connec modify nmcli conne modif nmcii conn modi nmcli con mod nmcli co mo nmcli c m nmcli c modify nmcli connection m nmcli connect modify nmcli connection modify
ipv4.
可以接 [method, dns, dns-search, dns-options, dns-priority, addresses, gateway, routes, route-metric, route-table, routing-rules, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-iaid, dhcp-timeout, dhcp-send-hostname, dhcp-hostname, dhcp-fqdn, dhcp-hostname-flags, never-default, may-fail, required-timeout, dad-timeout, dhcp-vendor-class-identifier, dhcp-reject-servers] 。-
ipv4.method
最简可写成ipv4.me
-
ipv4.addresses
在Ubuntu20.04中最简可写成ipv4.a
, 在24.04中却不能,因为新版本添加了a开头的命令
-
ipv4.gateway
能简写为ipv4.g
(ipv4.gateway)只能有一个, (在图形界面也只能设置一个), 如果没设置网关就不能上网,但只要有ip地址,就能让网段内其它主机访问,比如ssh连接,没有网关就是能进不能出
-
ipv4.dns
不能简写,可一次设置多个,+ipv4.dns
可多次设置多个
-
ipv4.dns-search
可简写为ipv4.dns-s
, 搜索域
-
ipv4.ignore-auto-dns
取值true
|fasle
, 最简只能写成ipv4.ignore-auto-d