1.切换root
sudo su

2.禁用 Cloud-Init 的网络配置
创建99-disable-network-config.cfg
vi /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}

3.查看网卡名称
ip a

4.移除50-cloud-init.yaml ,创建 00-installer-config.yaml
网卡名称从上面获取,根据实际情况修改, ip和网关根据规划修改
进入目录: cd /etc/netplan
root@yd101:/etc/netplan# cat 00-installer-config.yaml network: version: 2 ethernets: ens3: dhcp4: no addresses: - 192.168.5.2/24 gateway4: 192.168.5.1 nameservers: addresses: [8.8.8.8, 114.114.114.114]
5. 生效配置
部分告警忽略
root@yd101:/etc/netplan# netplan apply ** (generate:2929): WARNING **: 06:50:34.523: `gateway4` has been deprecated, use default routes instead. See the 'Default routes' section of the documentation for more details. WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running. ** (process:2927): WARNING **: 06:50:34.797: `gateway4` has been deprecated, use default routes instead. See the 'Default routes' section of the documentation for more details. ** (process:2927): WARNING **: 06:50:34.956: `gateway4` has been deprecated, use default routes instead. See the 'Default routes' section of the documentation for more details. ** (process:2927): WARNING **: 06:50:34.956: `gateway4` has been deprecated, use default routes instead. See the 'Default routes' section of the documentation for more details.
6.确认ip地址

通过其他方式远程连接服务器验证
ssh 用户@ip
补充:
1. 查看网口是否启动
ip link show eth0 | grep -o "LOWER_UP"
2.强制启动接口
ip link set dev <网卡名> up
3.重启网络
systemctl restart systemd-networkd