How can I define network settings with vagrant

前端 未结 3 718
没有蜡笔的小新
没有蜡笔的小新 2021-02-10 09:02

I am running Ubuntu inside vagrant, here is the Vagrantfile:

# Vagrantfile API/syntax version. Don\'t touch unless you know what you\'re doing!
VAGRANTFILE_API_V         


        
3条回答
  •  春和景丽
    2021-02-10 09:40

    From the vagrant book

    NAT Requirement As the First Network Interface With VirtualBox,

    Vagrant requires the first network device attached to the virtual machine to be a NAT device. The NAT device is used for port forwarding, which is how Vagrant gets SSH access to the virtual machine.

    Therefore, any host-only or bridged networks will be added as additional network devices and exposed to the virtual machine as “eth1,” “eth2,” and so on. “eth0” or “en0” is generally always the NAT device.

    It isn’t currently possible to override this requirement, but it is important to understand that it is in place.

    so what you're reporting is this NAT.

    Also eth1 is not defined as you set auto_config: false in your Vagrantfile so you're basically telling vagrant you'll do all the setup yourself. so you should turn this paramter to true (or remove) or set the etc/network/interfaces yourself

    You can look at vagrant public network and look if you can use the snippet example to remove the eth0 gateway from your config

      config.vm.network "public_network", ip: "192.168.0.17"
    
      # default router
      config.vm.provision "shell",
        run: "always",
        inline: "route add default gw 192.168.0.1"
    
      # default router ipv6
      config.vm.provision "shell",
        run: "always",
        inline: "route -A inet6 add default gw fc00::1 eth1"
    
      # delete default gw on eth0
      config.vm.provision "shell",
        run: "always",
        inline: "eval `route -n | awk '{ if ($8 ==\"eth0\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
    

提交回复
热议问题