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_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network :private_network, ip: "192.168.99.4", :netmask => "255.255.255.0", auto_config: false
end
So I expect to have 192.168.99.4 as IP but I always have:
eth0 Link encap:Ethernet HWaddr 08:00:27:88:ba:8f
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe88:ba8f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr 08:00:27:9c:a9:9f
inet6 addr: fe80::a00:27ff:fe9c:a99f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Any clue what I do wrong ?
Got some progress on the question, and it is almost like this one : How to switch order of network adapters in Vagrant under VirtualBox?
It is about not using "10.0.2.15" and from what I understand it is to be changed in the "NAT" setup of virutalbox, can not be managed by Vagrant
Vagrant supports host-only networks by specifying a static IP for the machine. Vagrant will handle creating the host-only network and configuring the guest machine to get the specified IP. The machine can then be accessed directly using this IP.
To configure private or host-only networking in Vagrant with static IP address, open the Vagrantfile, find the following line and uncomment it. Here, 192.168. 121.60 is the IP address of the VM. Replace this with your own IP.
The easiest way to use a private network is to allow the IP to be assigned via DHCP. This will automatically assign an IP address from the reserved address space. The IP address can be determined by using vagrant ssh to SSH into the machine and using the appropriate command line tool to find the IP, such as ifconfig .
To make this experience better, Vagrant allows specifying the default provider to use by setting the VAGRANT_DEFAULT_PROVIDER environmental variable. Just set VAGRANT_DEFAULT_PROVIDER to the provider you wish to be the default.
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; }'`"
To change the default NAT you should set it in Vagrantfile.
For instance:
config.vm.define "bs" do |bvtserver|
bvtserver.vm.hostname = "bvt-server"
bvtserver.vm.network "private_network", ip: "192.168.50.3",
virtualbox__intnet: "gcptest-network"
bvtserver.vm.provider :virtualbox do |vbox|
vbox.customize ["modifyvm", :id, "--natnet1", "10.3/16"]
end
end
For credits and more informations: Li Chao blog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With