为什么Vagrant定义的网络没有效果?

为什么Vagrant定义的网络没有效果?

我正在尝试配置两个可以互相发送流量的虚拟机,但我在使用 Vagrant 实现此操作时遇到了麻烦。在我的Vagrantfile我有:

Vagrant.configure("2") do |config|
  config.vm.box = "base"

  config.vm.define "machine_a" do |machine_a|
    machine_a.vm.box = "fedora/36-cloud-base"
    machine_a.vm.network "private_network", ip: "192.168.33.10"
    machine_a.vm.hostname = "machine-a"
    machine_a.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
    end
  end

  config.vm.define "machine_b" do |machine_b|
    machine_b.vm.box = "fedora/36-cloud-base"
    machine_b.vm.network "private_network", ip: "192.168.33.11"
    machine_b.vm.hostname = "machine-b"
    machine_b.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
    end
  end

end

然而,当我ifconfig跑进机器_a虚拟机,我得到:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::c108:7157:9132:af74  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:56:a8:b4  txqueuelen 1000  (Ethernet)
        RX packets 1063  bytes 120984 (118.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 976  bytes 141524 (138.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.110  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a92f:2b09:ddc3:1fa2  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:72:bd:cf  txqueuelen 1000  (Ethernet)
        RX packets 48  bytes 15724 (15.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38  bytes 3474 (3.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 8  bytes 648 (648.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 648 (648.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

除非我遗漏了什么,否则这个专用网络上既没有对 machine_b 的引用,也没有对我在Vagrantfile(192.168.33.10192.168.33.11) 中指定的两个 IP 的引用。

任何关于我做错了什么的指导将不胜感激。谢谢!

答案1

我面临着类似的问题。我的问题变体是访客自动从 Vagrant 获取 172.16.-地址,并且我的私有 IP 地址定义没有显示在纳米克利在组装好的盒子上。

我发现的一种解决方法:如果我将框更改为基于generic/centos9s两个 eth 接口,则会获得 IP 地址。

您有/etc/sysconfig/network-scripts/ifcfg-eth?问题接口的文件吗?我有,但不知何故它没有被系统/nmcli/whatnot“拾取”。

相关内容