- 环境
- 步骤
- 查看虚机当前ip (enp0s5-->inet)
- 查看虚机当前路由
- 修改网络配置
- 应用配置文件
- 测试网络
- 出现问题记录
- 问题:gateway4报错
- 问题: ping: connect: 网络不可达 或 域名解析失败
主机:macbookpro2021
虚机:Ubuntu 22.04 LTS
软件:Parallels Desktop 17 for Mac
fabric@fabric:~/桌面$ ifconfig enp0s5: flags=4163查看虚机当前路由mtu 1500 inet 10.211.55.10 netmask 255.255.255.0 broadcast 10.211.55.255 inet6 fe80::21c:42ff:fef5:3526 prefixlen 64 scopeid 0x20 ether 00:1c:42:f5:35:26 txqueuelen 1000 (以太网) RX packets 550 bytes 90899 (90.8 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1511 bytes 175404 (175.4 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (本地环回) RX packets 1607 bytes 136590 (136.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1607 bytes 136590 (136.5 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
fabric@fabric:/etc/netplan$ route -n 内核 IP 路由表 目标 网关 子网掩码 标志 跃点 引用 使用 接口 0.0.0.0 10.211.55.1 0.0.0.0 UG 100 0 0 enp0s5 10.211.55.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s5 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s5修改网络配置
fabric@fabric:/etc/netplan$ sudo vi 00-installer-config.yaml
修改前文件内容
network:
ethernets:
enp0s5:
dhcp4: true
version: 2
修改成
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s5:
dhcp4: no
dhcp6: no
addresses: [10.211.55.10/24]
routes:
- to: default
via: 10.211.55.1
nameservers:
addresses: [8.8.8.8,114.114.114.114]
保存退出
应用配置文件fabric@fabric:/etc/netplan$ sudo netplan apply
查看修改结果
fabric@fabric:/etc/netplan$ ifconfig enp0s5: flags=4163mtu 1500 inet 10.211.55.10 netmask 255.255.255.0 broadcast 10.211.55.255 inet6 fe80::21c:42ff:fef5:3526 prefixlen 64 scopeid 0x20 ether 00:1c:42:f5:35:26 txqueuelen 1000 (以太网) RX packets 660 bytes 102937 (102.9 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1752 bytes 202251 (202.2 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (本地环回) RX packets 1692 bytes 144569 (144.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1692 bytes 144569 (144.5 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
fabric@fabric:/etc/netplan$ route -n 内核 IP 路由表 目标 网关 子网掩码 标志 跃点 引用 使用 接口 0.0.0.0 10.211.55.1 0.0.0.0 UG 100 0 0 enp0s5 10.211.55.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s5 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s5测试网络
虚机ping百度
fabric@fabric:/etc/netplan$ ping baidu.com PING baidu.com (220.181.38.148) 56(84) bytes of data. 64 bytes from 220.181.38.148: icmp_seq=1 ttl=128 time=39.9 ms
虚机ping主机
fabric@fabric:/etc/netplan$ ping 主机ip 64 bytes from 112.32.24.194: icmp_seq=1 ttl=128 time=34.4 ms 64 bytes from 112.32.24.194: icmp_seq=2 ttl=128 time=22.7 ms 64 bytes from 112.32.24.194: icmp_seq=3 ttl=128 time=25.0 ms 64 bytes from 112.32.24.194: icmp_seq=4 ttl=128 time=25.1 ms 64 bytes from 112.32.24.194: icmp_seq=5 ttl=128 time=59.8 ms
主机ping虚机
主机@192 ~ % ping 10.211.55.10 PING 10.211.55.10 (10.211.55.10): 56 data bytes 64 bytes from 10.211.55.10: icmp_seq=0 ttl=64 time=0.952 ms 64 bytes from 10.211.55.10: icmp_seq=1 ttl=64 time=0.946 ms 64 bytes from 10.211.55.10: icmp_seq=2 ttl=64 time=0.892 ms 64 bytes from 10.211.55.10: icmp_seq=3 ttl=64 time=0.893 ms 64 bytes from 10.211.55.10: icmp_seq=4 ttl=64 time=0.986 ms出现问题记录 问题:gateway4报错
fabric@fabric:/etc/netplan$ sudo netplan apply ** (generate:15158): WARNING **: 20:49:17.450: `gateway4` has been deprecated, use default routes instead. See the 'Default routes' section of the documentation for more details. ** (process:15156): WARNING **: 20:49:17.568: `gateway4` has been deprecated, use default routes instead. See the 'Default routes' section of the documentation for more details.
原因
初次修改代码
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s5:
dhcp4: no
dhcp6: no
addresses: [10.211.55.10/24]
gateway4: 10.211.55.1
nameservers:
addresses: [8.8.8.8,114.114.114.114]
解决
将gateway4改为routes
刚开始gateway4报错,直接删除ping会报错,因此,gateway4不可删除



