先说一下情况,我的宿主机是Ubuntu、虚拟机里的系统也是 Ubuntu,宿主机只有一个网口 enp8s0,IP网段是 192.168.0.1/24 这个范围。
目的能够在局域网内访问到宿主机和宿主机中的虚拟机
宿主机的 /etn/netplan/01-xxx.yaml 文件:
network:
version: 2
renderer: networkd
ethernets:
enp8s0:
dhcp4: false
bridges:
br0:
dhcp4: false
addresses:
- 192.168.0.110/24
nameservers:
addresses:
- 192.168.0.1
gateway4: 192.168.0.254
interfaces:
- enp8s0
virt 虚拟机使用桥接网络,填写br0,里面的虚拟机同样使用/etn/netplan/01-xxx.yaml 文件配置的是同网段的静态IP,虚拟机中的配置如下:
network:
ethernets:
enp1s0:
addresses:
- 192.168.0.102/24
routes:
- to: default
via: 192.168.0.254
nameservers:
addresses: [192.168.0.1]
version: 2
此时不需要关心linux桌面版界面显示的网络,因为即便通过界面关闭了所有网络,也还是可以访问通网络。以ifconfig命令返回的网络ip为准,如下:
enp8s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 40:b0:76:0c:8d:88 txqueuelen 1000 (Ethernet)
RX packets 177147 bytes 92730359 (92.7 MB)
RX errors 0 dropped 17 overruns 0 frame 0
TX packets 76111 bytes 19083108 (19.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.110 netmask 255.255.255.0 broadcast 192.168.0.255
ether b2:fc:10:14:00:17 txqueuelen 1000 (Ethernet)
RX packets 93695 bytes 46142436 (46.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 59328 bytes 25469476 (25.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
了解 工作生活心情记忆 的更多信息
Subscribe to get the latest posts sent to your email.