debian10.0设置永久IP(与界面配置相同,请注意你的系统版本,其它版本未测试,此仅供参考)
注意:此配置和/etc/network/interfaces下永久配置同时只有一个会生效,如果/etc/network/interfaces配置了,当前界面配置的会默认失效。配置时尽量网线插好。
1.查看网卡uuid
#nmcli con
NAME UUID TYPE DEVICE
network1 02d47e45-a303-370a-bb18-b506f16a6fbc ethernet enp1s0
network2 cb0acc94-b3f7-38cd-b99f-9d405799a98d ethernet enp2s0
2.查看网卡信息(目前物理网卡为)
#ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 84:c9:b2:73:f3:86 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.50/8 brd 192.168.1.255 scope global noprefixroute enp1s0
valid_lft forever preferred_lft forever
inet6 fe80::93a1:4f15:8d67:a0fb/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether bc:30:5b:c7:67:59 brd ff:ff:ff:ff:ff:ff
inet 2.168.1.50/24 brd 2.255.255.255 scope global noprefixroute enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::1593:279a:aee1:9e60/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3.查看当前配置
# cat /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
[ifupdown]
managed=false
# ls /etc/NetworkManager/system-connections/
network1.nmconnection network2.nmconnection
4.添加网卡配置
# vi /etc/NetworkManager/system-connections/network1.nmconnection
[connection]
id=network1 (可自定义命令,保持与network1.nmconnection的前缀相同)
uuid=02d47e45-a303-370a-bb18-b506f16a6fbc
type=ethernet
autoconnect-priority=-999
permissions=
timestamp=1579046993
[ethernet]
mac-address=84:c9:b2:73:f3:86 (手动添加要修改为正确的网卡MAC地址,和uuid对应即可)
mac-address-blacklist=
[ipv4]
address1=192.168.1.50/24,192.168.1.254 (IP/掩码(8-255.0.0.0,24-255.255.255.0),网关IP)
dns=192.168.0.8;(DNS IP,分号";"不要缺少)
dns-search=
method=manual
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto
5.保存重启即可。