nmcli connection add 可以创建新连接
ARGUMENTS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- ([+|-]<setting>.<property> <value>)+]
COMMON_OPTIONS:
type <type>
ifname <interface name> | "*"
[con-name <connection name>]
[autoconnect yes|no]
[save yes|no]
[master <master (ifname, or connection UUID or name)>]
[slave-type <master connection type>]
nmcli connection add
等效nmcli c a
sudo nmcli c a con-name 'ens33ConnTest001' ifname 'ens33' type ethernet ipv4.method 'manual' ipv4.addresses "192.168.168.224/24 , 192.168.168.225/24,192.168.168.226/24" +ipv4.address '192.168.168.227/24' +ipv4.a '192.168.168.228/24' +ipv4.addre '192.168.168.229/24 , 192.168.168.230/24 , 192.168.168.231/24' +ipv4.addr "192.168.168.232/24" +ipv4.ad '192.168.168.233/24' +ipv4.a 192.168.168.234/24,192.168.168.235/24 ipv4.gate 192.168.168.2 ipv4.dns 192.168.168.2,119.29.29.29,180.76.76.76,223.6.6.6,8.8.4.4,114.114.115.115 +ipv4.dns '223.5.5.5 , 8.8.8.8 , 1.1.1.1 , 114.114.114.114' +ipv4.dns 101.226.4.6,123.125.81.6 ipv4.ignore-auto-dns true ipv4.dns-search qq.com
ipv4.a
(ipv4.addresses)可以设置多个(,逗号分隔,可以有空格),但只能出现一次, +ipv4.a
(+ipv4.addresses)可以设置多个(,逗号分隔)可以出现多次
网关ipv4.g
(ipv4.gateway)只能有一个, (在图形界面也只能设置一个)
ipv4.dns
不能简写,可一次设置多个, +ipv4.dns
可多次设置多个
ipv4.dns-search
可简写为ipv4.dns-s
, 搜索域
ipv4.ignore-auto-dns
取值 true
|fasle
是否跳过自动域名 , 最简只能写成ipv4.ignore-auto-d
上面的nmcli控制台语句会在/etc/NetworkManager/system-connections/
目录生成 con-name
指定的名称加上 .nmconnection
后缀的配置文件, 如果同名文件已存在, 就会再加一个UID
上面的nmcli控制台语句生成的对应的配置文件的内容为
[connection]
id=ens33ConnTest001
uuid=47b1917a-5eea-4160-b56f-680654c338c9
type=ethernet
interface-name=ens33
[ethernet]
[ipv4]
address1=192.168.168.224/24,192.168.168.2
address2=192.168.168.225/24
address3=192.168.168.226/24
address4=192.168.168.227/24
address5=192.168.168.228/24
address6=192.168.168.229/24
address7=192.168.168.230/24
address8=192.168.168.231/24
address9=192.168.168.232/24
address10=192.168.168.233/24
address11=192.168.168.234/24
address12=192.168.168.235/24
dns=192.168.168.2;119.29.29.29;180.76.76.76;223.6.6.6;8.8.4.4;114.114.115.115;223.5.5.5;8.8.8.8;1.1.1.1;114.114.114.114;101.226.4.6;123.125.81.6;
dns-search=qq.com;
ignore-auto-dns=true
method=manual
[ipv6]
addr-gen-mode=stable-privacy
method=auto
[proxy]
netplan
可以从配置文件创建连接, NetworkManager
暂时不知可否从配置文件创建连接,只能从图形界面或nmtui
或nmcli c a
创建新连接, nmcli c load
只能加载已创建连接的配置文件, 不能加载自己添加的配置文件
添加一个简洁的,可当基础模板
sudo nmcli connection add con-name 'Concise' ifname 'ens33' type 'ethernet' ipv4.method 'manual' ipv4.addresses "192.168.168.224/24" ipv4.gateway '192.168.168.2' ipv4.dns '192.168.168.2' ipv4.ignore-auto-dns false ipv4.dns-search google.cn
con-name
, ifname
, type
没法简写 , 区分大小写
可以添加几个连接可用于做试验,或者方便快速切换
sudo nmcli c a con-name 'con-name' ifname 'ens33' type 'EtherneT' ipv4.me 'manual' ipv4.a 192.168.168.224/24 ipv4.g 192.168.168.2
EtHeRnEt 不区分大小写 , 到配置文件会变为小写 ethernet
sudo nmcli c a con-name 'ens33自动获取IP' ifname 'ens33' type EtHeRnEt ipv4.me auto
ipv4.xxx 也不区分大小写, 到配置文件都变小写
sudo nmcli c a con-name '阿里dns' ifname ens33 type ethernet IpV4.me ManuaL iPV4.A 192.168.168.224/24 IPv4.g 192.168.168.2 ipv4.ignore-auto-dns true ipv4.dns 223.6.6.6,223.5.5.5
sudo nmcli c m '阿里dns' iPv4.iGnore-aUto-dNs true Ipv4.dnS 223.6.6.6,223.5.5.5 iPv4.dNs-SeArCh alibaba.com,aliyun.com,taobao.com
con-name
, ifname
, type
没法简写 , 而且区分大小写
sudo nmcli c a con-name '谷歌dns' ifname ens33 type ETHERnet iPV4.mE mANuAl IpV4.aDDr 192.168.168.224/24 ipV4.GAte 192.168.168.2 IpV4.IgNorE-AUto-DnS TruE ipV4.dNS 8.8.4.4,8.8.8.8 ipV4.DnS-sEaRcH google.cn
sudo nmcli c a con-name 百度dns ifname ens33 type ethernet ipv4.me manual ipv4.a 192.168.168.224/24 ipv4.g 192.168.168.2 ipv4.ignore-auto-dns true ipv4.dns 180.76.76.76 ipv4.dns-search baidu.com
单引号
sudo nmcli c a con-name '腾讯dns' ifname 'ens33' type 'ethernet' ipv4.me 'manual' ipv4.a '192.168.168.224/24' ipv4.g '192.168.168.2' ipv4.ignore-auto-dns 'true' ipv4.dns '119.29.29.29' ipv4.dns-search 'qq.com'
双引号
sudo nmcli c a con-name "114dns" ifname "ens33" type "ethernet" ipv4.me "manual" ipv4.a "192.168.168.224/24" ipv4.g "192.168.168.2" ipv4.ignore-auto-dns "true" ipv4.dns "114.114.114.114,114.114.115.115"
大写
sudo nmcli c a con-name 'IBMdns' ifname 'ens33' type 'ethernet' IPV4.ME manual IPV4.A 192.168.168.224/24 IPV4.G 192.168.168.2 IPV4.IGNORE-AUTO-DNS true IPV4.DNS '9.9.9.9'
全名大写
sudo nmcli c a con-name 'CNNICdns' ifname 'ens33' type 'ethernet' IPV4.METHOD 'manual' IPV4.ADDRESSES 192.168.168.224/24 IPV4.GATEWAY 192.168.168.2 IPV4.IGNORE-AUTO-DNS 'true' IPV4.DNS '1.2.4.8,210.2.4.8' IPV4.DNS-SEARCH 'baidu.com,google.cn'
全名小写
sudo nmcli c a con-name 'CloudflareDNS' ifname 'ens33' type 'ethernet' ipv4.method 'manual' ipv4.addresses '192.168.168.224/24' ipv4.gateway '192.168.168.2' ipv4.ignore-auto-dns 'true' ipv4.dns '1.1.1.1,1.0.0.1' ipv4.dns-search 'baidu.com,google.cn'
sudo nmcli c a con-name "360电信移动铁通dns" ifname "ens33" type "ethernet" ipv4.method "manual" ipv4.addresses "192.168.168.224/24" ipv4.gateway "192.168.168.2" ipv4.ignore-auto-dns "true" ipv4.dns "101.226.4.6 , 218.30.118.6" ipv4.dns-search "360.com"
sudo nmcli c a con-name 360联通dns ifname ens33 type ethernet ipv4.method manual ipv4.addresses 192.168.168.224/24 ipv4.gateway 192.168.168.2 ipv4.ignore-auto-dns true ipv4.dns 123.125.81.6,140.207.198.6 ipv4.dns-search "360.com"
sudo nmcli c a con-name 微软dns ifname ens33 type ethernet ipv4.me manual ipv4.a 192.168.168.224/24 ipv4.g 192.168.168.2 ipv4.ignore-auto-dns true ipv4.dns 4.2.2.1,4.2.2.2 ipv4.dns-s bing.com
sudo nmcli c a con-name OpenDNS ifname ens33 type ethernet ipv4.me manual ipv4.a 192.168.168.224/24 ipv4.g 192.168.168.2 ipv4.ignore-auto-dns true ipv4.dns 208.67.222.222,208.67.220.220 ipv4.dns-s bing.com
修改为手动DNS
sudo nmcli c m 'ens33ConnTest001' ipv4.ignore-auto-dns true
修改自动DNS
sudo nmcli c m 'ens33ConnTest001' ipv4.ignore-auto-dns false
resolvectl
命令可以查看 dns