有时候我们做了一个系统镜像,要适配很多个设备,这些设备的网口有不同的uuid和MAC地址,可能会导致网络的设置无法生效,这时候可以选择在启动的时候使用命令行来设置
-
- nmcli con show
-
- for con in `ls /etc/NetworkManager/system-connections` ;
- do
- nmcli con del $con
- done
-
- rm -rf /etc/NetworkManager/system-connections/*
-
-
- # dhcp
- nmcli con add con-name eth0 type Ethernet ifname eth0
-
- #modify
- nmcli con mod eth0 connection.autoconnect-priority 10 ipv4.may-fail no ipv4.dhcp-timeout 8
-
- # static
- nmcli con add con-name eth0 type Ethernet ifname eth0
- nmcli con modify eth0 ipv4.address 10.0.0.1/24 \
- ipv4.gateway 192.168.1.1 \
- ipv4.dns 114.114.114.114 \
- ipv4.method manual
-
- nmcli con up eth0
-
-