1.sudo vi /etc/netplan/01-netcfg-init.yaml
network:
version: 2
renderer: networkd
ethernets:
ens2: #配置的网卡名称
dhcp4: no #dhcp4关闭
dhcp6: no #dhcp6关闭
addresses: [192.168.118.164/24] #设置本机IP及掩码
gateway4: 192.168.118.255 #设置网关
nameservers:
addresses: [114.114.114.114, 8.8.8.8] #设置DNS
2.sudo netplan apply # 可以让配置直接生效,不用重启
3.sudo reboot # 不放心可以重启看看有没成功
参考:https://blog.csdn.net/liuhaoy/article/details/101078932