![nmcli 在没有 DHCP 的情况下设置静态 IP 地址?](https://linux22.com/image/749566/nmcli%20%E5%9C%A8%E6%B2%A1%E6%9C%89%20DHCP%20%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E8%AE%BE%E7%BD%AE%E9%9D%99%E6%80%81%20IP%20%E5%9C%B0%E5%9D%80%EF%BC%9F.png)
我想为 eth0 接口分配一个静态 IP 地址,而不让 DHCP 分配动态地址。我尝试将方法设置为手动,但这没有帮助,最终我在接口上得到了 2 个 IP,一个是静态的,另一个是动态的。我想使用 nmcli 在接口上只有一个静态 IP
/etc/NetworkManager/system-connections/static.nmconnection:
[connection]
id=static
uuid=5da74c14-d9da-4e15-90c9-5f37913d5610
type=ethernet
interface-name=eth0
permissions=
timestamp=1584007539
[ethernet]
mac-address-blacklist=
[ipv4]
address1=172.17.1.222/24,172.17.0.1
dns=172.17.0.221;172.17.0.220;
dns-search=
method=manual
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=ignore
ip a:
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether dc:a6:32:3b:22:03 brd ff:ff:ff:ff:ff:ff
inet 172.17.1.222/24 brd 172.17.1.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 172.17.12.14/16 brd 172.17.255.255 scope global dynamic noprefixroute eth0
valid_lft 602857sec preferred_lft 527257sec
inet6 fe80::dea6:32ff:fe3b:2203/64 scope link
valid_lft forever preferred_lft forever
答案1
要配置静态 IP 配置并禁用 DHCP nmcli
,请尝试以 root 身份运行此命令:
nmcli con mod eth0 ipv4.addresses "172.17.1.222/24"
nmcli con mod eth0 ipv4.gateway "172.17.0.1"
nmcli con mod eth0 ipv4.dns "172.17.0.221 172.17.0.220"
nmcli con mod eth0 ipv4.method manual
nmcli con mod eth0 connection.autoconnect yes
然后重新启动计算机或重新network-manager
启动
systemctl restart NetworkManager