需要将网络端口从本地计算机桥接到Vagrant VM

时间:2017-03-09 18:54:28

标签: networking vagrant vagrantfile

在我的开发机器上,我可以在eth1端口上看到以下DHCP流量:

sudo tcpdump -i eth1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
09:51:58.785056 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, 
Request from 00:06:31:c7:1e:23 (oui Unknown), length 315
09:51:58.785384 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, 
Request from 00:06:31:c7:1e:23 (oui Unknown), length 315
09:51:59.786677 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, 
Request from 00:06:31:c7:1e:23 (oui Unknown), length 315

我希望在我的Vagrant VM中看到相同的流量。所以我想将我的开发机器上的eth1端口桥接到我的Vagrant VM上的某个端口。我还希望能够将来自我的Vagrant VM的网络流量发送回eth1。

使用以下问题中的答案: https://superuser.com/questions/752954/need-to-do-bridged-adapter-only-in-vagrant-no-nat

我将此添加到我的Vagrantfile:

config.vm.provision "shell",
run: "always",
inline: "route -A inet6 add deault gw fc00::1 eth1"

但我真的不知道这是做什么的,除了它似乎只是路由ipv6流量?有人可以帮助解释如何将eth1桥接到我的Vagrant VM上的端口吗?

我还在我的Vagrantfile中尝试了以下内容:

Vagrant::Config.run do |config|
  config.vm.network :bridged
end

但是在我再次进行流浪之后,我仍然没有在我的VM中看到任何具有DHCP流量的端口(使用ifconfig)。

1 个答案:

答案 0 :(得分:0)

在阅读了Vagrant之后,我发现了一个对我有用的解决方案。

首先,我在主机上运行以下命令: sudo ip route add 192.168.1.0/24 dev eth1

我的理解是,这会将来自eth1物理端口的流量路由到192.168.1.0 IP地址。

然后,在我的Vagrantfile中,我在Vagrant.configure(2) do |config|下添加了以下内容: config.vm.network “public_network”, bridge: “eth1” config.vm.network “public_network”, ip: “192.168.1.0”

在做了流浪汉摧毁和流浪之后,我现在在我的流浪汉VM(enp0s8)中看到一个新端口,如果我执行tcpdump,我会看到到达我的eth1端口的DHCP流量(和其他流量)主机。

不确定这是否是最佳解决方案,因为我对vagrant和VirtualBox仍然是一个新手,但这对我有用。

相关问题