hel*_*son 14 virtualbox 17.04 netplan
我正在运行带有 2 个网络适配器的 VirtualBox:标准 NAT (enp0s3) 和一个仅主机适配器 (enp0s8)。我使用 NAT 访问互联网,并使用 Host-only Adapter 从本地机器通过 SSH 访问。
盒子在启用两个适配器的情况下启动,都有 IP 地址,一切看起来都很好。
我可以通过仅主机适配器通过 SSH 进入这个盒子,那里没有问题。但是我不能用它上网。但是,如果我禁用仅主机适配器,那么我可以访问互联网(但显然我不能再通过本地隧道通过 SSH 进入它)。
最后,这是我的 netplan yaml 配置:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
dhcp6: yes
enp0s8:
dhcp4: no
dhcp6: no
addresses: [192.168.52.101/24]
gateway4: 192.168.52.101
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?似乎我所有的出站流量都以某种方式通过仅主机适配器进行路由。
编辑:附加输出ip route list以防万一。
default via 192.168.52.101 dev enp0s8 proto static
default via 10.0.2.2 dev enp0s3 proto dhcp src 10.0.2.15 metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
10.0.2.2 dev enp0s3 proto dhcp scope link src 10.0.2.15 metric 100
192.168.52.0/24 dev enp0s8 proto kernel scope link src 192.168.52.101
Run Code Online (Sandbox Code Playgroud)
小智 14
对我来说,gateway4从配置中删除就行了。配置它后,我也无法 ping 互联网。
如果它可以帮助其他人,这是我的 netPlan 配置。
注意: enp0s3 用于通过端口转发的 ssh,而 enp0s8 用于静态 ip
network:
ethernets:
enp0s3:
addresses: []
dhcp4: true
optional: true
enp0s8:
addresses: [192.168.10.20/24]
dhcp4: no
dhcp6: no
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
Run Code Online (Sandbox Code Playgroud)
小智 12
今天下午我发现这个问题做的完全一样。不知何故设法弄明白了,netplan 最终通过我的 VM 的 NAT 接口只创建了 1 个默认路由。就我而言,两个 IP 都是 192.168.56.101(仅限主机)和 10.0.3.x/24(NAT dhcp4)。我正在使用这个 netplan 文件:
network:
version: 2
renderer: networkd
ethernets:
enp0s8:
dhcp4: yes
dhcp6: yes
routes:
- to: 0.0.0.0/0
via: 10.0.3.2
metric: 0
enp0s3:
dhcp4: no
dhcp6: no
addresses: [192.168.56.101/24]
routes:
- to: 192.168.56.1/24
via: 192.168.56.1
metric: 100
Run Code Online (Sandbox Code Playgroud)
有了这个,我只有一个默认路由,它使用 NAT,因此它可以通过我的主机访问 Internet。
输出 ip r
default via 10.0.3.2 dev enp0s8 proto dhcp src 10.0.3.15 metric 100
10.0.3.0/24 dev enp0s8 proto kernel scope link src 10.0.3.15
10.0.3.2 dev enp0s8 proto dhcp scope link src 10.0.3.15 metric 100
192.168.56.0/24 dev enp0s3 proto kernel scope link src 192.168.56.10
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16773 次 |
| 最近记录: |