0

I used Vagrantfile to create CentOS 7 VM:

config.vm.define "endpoint" do |machine|
    machine.vm.box = "centos/7" # for all available boxes go to https://app.vagrantup.com/boxes/search
    # machine.vm.box_url = "http://vagrant.com/some.box"
    machine.vm.network :private_network, ip: "192.168.56.10"
    machine.vm.network :private_network, ip: "10.0.2.10",
                       :netmask => "255.255.255.0"
    machine.vm.hostname = "endpoint"
    machine.vm.provider :virtualbox do |v|
      v.customize ["modifyvm", :id, "--memory", 512]
      v.cpus = 2
    end
  end

After machine is created, I have following in VirtualBox:

All is fine at this point, i can access to the internet

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        ether 52:54:00:8a:fe:e6  txqueuelen 1000  (Ethernet)
        RX packets 133  bytes 65603 (64.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 117  bytes 10305 (10.0 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.10  netmask 255.255.255.0  broadcast 192.168.56.255
        ether 08:00:27:36:76:a8  txqueuelen 1000  (Ethernet)
        RX packets 1577  bytes 152692 (149.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1017  bytes 184289 (179.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.10  netmask 255.255.255.0  broadcast 10.0.2.255
        ether 08:00:27:71:b3:d0  txqueuelen 1000  (Ethernet)
        RX packets 28  bytes 2542 (2.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 369  bytes 34798 (33.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


 route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

0.0.0.0         10.0.2.2        0.0.0.0         UG    104    0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     102    0        0 eth2
10.0.2.0        0.0.0.0         255.255.255.0   U     103    0        0 eth3
10.0.2.0        0.0.0.0         255.255.255.0   U     104    0        0 eth0
192.168.56.0    0.0.0.0         255.255.255.0   U     101    0        0 eth1
  • VirtualBox interfaces:

image

  • Interfaces attached to VM:

image

Now,because one specific application, I need to disable eth0 - 10.0.2.15 and still have to be able to reach the internet through eth2 So I disabled eth0. For eth2 added 10.0.2.1 as Default gateway (address is pingable), it's host-only Ethernet Adapter #2 from the picture

#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=yes
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.0.2.10
NETMASK=255.255.255.0
GATEWAY=10.0.2.1
DEVICE=eth2
PEERDNS=no
#VAGRANT-END

But now unable to access to the internet (ping 8.8.8.8 fails)

Previous DG (10.0.2.2) is no longer available (after i disabled eth0)

Tried also to add 192.168.56.1 (also pingable) as Default Gateway but still unable to get Internet.

3
  • 1
    What, exactly, are you trying to accomplish? Host-only networks are meant to only allow communication between the virtual machine host and virtual machine guest. Unless you have configured the host machine to also operate as a router, you shouldn't expect internet access on a host-only network. So I'm not sure I understand what you are trying to do... Aug 5, 2019 at 23:24
  • i'm trying to get intertnet access when eth0 is down, as soon as i disable that interface, i can't access to 8.8.8.8
    – overflowed
    Aug 5, 2019 at 23:26
  • The Vagrant VirtualBox provider supports using the private network as a VirtualBox internal network. By default, private networks are host-only networks, because those are the easiest to work with. However, internal networks can be enabled as well. From Here. Unfortunately, it says nothing about how to switch to a NAT network... which is what you actually want. You may have to use vboxmanage to alter the .vbox file after vagrant creates it. Aug 5, 2019 at 23:35

1 Answer 1

1

Turned out this was quite complex so i created guide if anyone face same issue

https://geekdudes.wordpress.com/2019/08/06/virtual-box-setting-nat-network-and-change-primary-interface/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .