Vagrant: Change the eth0 ip because oft IP conflict

Created on 30 Jan 2014  ·  10Comments  ·  Source: hashicorp/vagrant

Hi, we are using the 10.0.0.0 net at work for our Servers. Server within that net are not reachable from a vagrant virtualbox. Even adding a public_network interface using DHCP only works if i explicitly set the interface eth1 in the ping Command. My solution now was to add a Route for the destination IP, but this is a annoying workaround. Is it possible to set a different eth0 IP in the vagrantfile or could this be implemented?

Most helpful comment

According to https://www.virtualbox.org/manual/ch09.html#changenat ,

If, for any reason, the NAT network needs to be changed, this can be achieved with the following command:
VBoxManage modifyvm "VM name" --natnet1 "192.168/16"

This can be fixed by modifying your Vagrantfile:

  config.vm.provider "virtualbox" do |vb|
    [...]
    vb.customize ['modifyvm', :id, '--natnet1', '192.168.222.0/24']
    [...]
  end

ALSO SEE:

All 10 comments

hello

you usually end having eth0 on the NAT network in virtualbox, then on
eth1/eth2 you can have other networks.

if I read your email and I understand it correctly, you have a network in
eth1 that have router/gw, and is not working because the route packages
goes over eth0?

can you paste here the output of

ifconfig -a
route -n

and tellme your host and guest os?

On Fri, Jan 31, 2014 at 8:13 AM, Benjamin Boit [email protected]:

Hi, we are using the 10.0.0.0 net at work for our Servers. Server within
that net are not reachable from a vagrant virtualbox. Even adding a
public_network interface using DHCP only works if i explicitly set the
interface eth1 in the ping Command. My solution now was to add a Route for
the destination IP, but this is a annoying workaround. Is it possible to
set a different eth0 IP in the vagrantfile or could this be implemented?

Reply to this email directly or view it on GitHubhttps://github.com/mitchellh/vagrant/issues/2915
.

ifconfig -a

eth0 Link encap:Ethernet HWaddr 08:00:27:47:e9:26
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe47:e926/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9082 errors:0 dropped:0 overruns:0 frame:0
TX packets:5210 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4929114 (4.7 MiB) TX bytes:453716 (443.0 KiB)

eth1 Link encap:Ethernet HWaddr 08:00:27:5e:8d:96
inet addr:192.168.250.150 Bcast:192.168.250.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:598516 errors:0 dropped:0 overruns:0 frame:0
TX packets:545839 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:216251796 (206.2 MiB) TX bytes:103186591 (98.4 MiB)

eth2 Link encap:Ethernet HWaddr 08:00:27:f5:dc:de
inet addr:10.0.3.214 Bcast:10.0.3.255 Mask:255.255.252.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:45358 errors:0 dropped:0 overruns:0 frame:0
TX packets:446 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4896975 (4.6 MiB) TX bytes:29802 (29.1 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1052 (1.0 KiB) TX bytes:1052 (1.0 KiB)

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 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.252.0 U 0 0 0 eth2
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.250.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

route add -host 10.0.2.114 dev eth2

fixes it, but only for 10.0.2.114 .... (dont want to add each internal server there)

eth2 is used to connect to the interal net (dhcp), eth1 has a static ip to use for etc/hosts (dont know how to update on vagrant up, plugins for that are not working .... )

Host OS is Ubuntu (mint) and guest if Debian Wheezy.

eth0 in Vagrant for now is always NAT. The NAT IP is determined by VirtualBox settings that Vagrant doesn't touch. You can change the NAT IP range by configuring VirtualBox itself.

on a multi-vm vagrant env, this ip is always the same, so how to get a different one, because some services relies on the default ethernet interface.

According to https://www.virtualbox.org/manual/ch09.html#changenat ,

If, for any reason, the NAT network needs to be changed, this can be achieved with the following command:
VBoxManage modifyvm "VM name" --natnet1 "192.168/16"

This can be fixed by modifying your Vagrantfile:

  config.vm.provider "virtualbox" do |vb|
    [...]
    vb.customize ['modifyvm', :id, '--natnet1', '192.168.222.0/24']
    [...]
  end

ALSO SEE:

All,
I am getting a similar problem as "killerwolf" on a multi-vm vagrant env where eth0 of all VMs are getting the same ip. How can this be fixed.

Thanks @mckelvin - my Vagrantfile was booting 7 VM's that refused to talk to each other and your snippit allowed me to move off the 10.0.2 subnet. This in turn avoided some IP clash somewhere on my work network. The clue was running a port scan on my vagrant provisioned salt-master - the results came back with a load of listening ports not appropriate to the VM i.e. some other machine somewhere. For reference on CentOS you can do this as follows:

sudo yum install nmap
sudo nmap -sT -O 192.168.0.100

In the above example my salt-master is _192.168.0.100_ so I called _nmap_ from a minion to see what ports it was exposing and couldn't see a listener on _4506_ or any familiar services.

thanks @mckelvin - nice trick
I defined a NAT network for every single VM in my multi-machine Vagrantfile. works now. :+1:

vb.customize ['modifyvm', :id, '--natnet1', '192.168.222.0/24']
…
vb.customize ['modifyvm', :id, '--natnet1', '192.168.n.0/24']

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings