【ubuntu】ubuntu使用nmcli设置静态ip或者dhcp
1. 查看网络设备
root@orangepizero3:~# nmcli connection show
NAME UUID TYPE DEVICE
Wired connection 1 172bcc78-4a39-3ec6-8a15-f9fab51aa248 ethernet eth0
2. 根据name值设置静态ip
sudo nmcli con mod "Wired connection 1" \
ipv4.addresses "10.168.1.168/24" \
ipv4.gateway "10.168.1.1" \
ipv4.dns "8.8.8.8" \
ipv4.method "manual"
###### 或者增加子网掩码
sudo nmcli con mod "有线连接 1" \
ipv4.addresses "10.168.1.169/24" \
ipv4.gateway "10.168.1.1" \
ipv4.dns "8.8.8.8" \
ipv4.method "manual"
3. 修改为dhcp自动获取
sudo nmcli connection modify "Wired connection 1" ipv4.method auto
4. 查看当前网络ip是什么方式
sudo nmcli connection show "有线连接 1" | grep "ipv4.method"