vagrant up deletes default (working) route on bridged network

3,791 views
Skip to first unread message

Gawain Hammond

unread,
Nov 12, 2013, 7:21:52 AM11/12/13
to vagra...@googlegroups.com
Hi,

I am using vagrant to provision an ubuntu vm using bridged networking and dhcp. The vm boots successfully with a valid dhcp ip address from the bridged network on eth1 with the vm and can ping the outside world. However, when I run 'vagrant up' is run, it interferes with the vm networking and deletes the default (working) route and gateway supplied by the dhcp server.

if i  run 'VAGRANT_LOG=debug vagrant up ' I see this:

INFO ssh: Execute: sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces (sudo=true)


The problem here is that vagrant injects the following snippet of code into /etc/network/interfaces, which deletes the route and gateway supplied by the dhcp server for eth1. This results in the vm being able to ping out to any host, but hosts on other subnets are unable to ping the vm until the default gateway assigned via dhcp is restored.

#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet dhcp
    post-up route del default dev $IFACE
#VAGRANT-END


If (on the vm) I delete the gateway and add the correct dhcp assigned one, hosts on other subnets are able to ping the vm just fine:

sudo route add default gw 10.69.51.253
sudo route del default gw 10.0.2.2 netmask 0.0.0.0 eth0


However, this is not an ideal option as the effect is only transient and does not persist between reboot, and I also cannot predict what virtual subnet the vm will get assigned by the switch (it could be 10.69.50.X/24 or 10.69.53.X/24). I also tried to change the /etc/network/interfaces file, but 'vagrant up' subsequently complains about the /etc/network/interfaces file not having the format it expects.

So my question is, what is the appropriate way to configure vagrant so that I have a proper dhcp assigned gateway that does not get deleted by the 'vagrant up' command? Ideally I'd like to tell not to mess with the /etc/network/interfaces file, but I imagine there are better ways.



Extra info:

Provisioning Host's Vagrantfile:

Vagrant::Config.run do |config|
  config.vm.box = "precise"
  config.vm.box_url = "http://files.vagrantup.com/precise32.box"
  config.vm.network :bridged, bridge: "em1"
end

Here is vm's ifconfig output

vagrant@precise32:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:12:96:98  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe12:9698/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:440 errors:0 dropped:0 overruns:0 frame:0
          TX packets:316 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:49959 (49.9 KB)  TX bytes:39019 (39.0 KB)
eth1      Link encap:Ethernet  HWaddr 08:00:27:58:b8:91  
          inet addr:10.69.50.46  Bcast:10.69.50.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe58:b891/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1490 errors:0 dropped:5 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:145954 (145.9 KB)  TX bytes:1152 (1.1 KB)
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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


And here is the vm's route -n output:

vagrant@precise32:~$ 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
0.0.0.0         10.0.2.2        0.0.0.0         UG    100    0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.69.50.0      0.0.0.0         255.255.255.0   U     0      0        0 eth1


Ping google from vm:
vagrant@precise32:~$ ping www.gogole.co.uk
PING www.gogole.co.uk (74.86.197.160) 56(84) bytes of data.
64 bytes from 74.86.197.160-static.reverse.softlayer.com (74.86.197.160): icmp_req=1 ttl=63 time=140 ms
64 bytes from 74.86.197.160-static.reverse.softlayer.com (74.86.197.160): icmp_req=2 ttl=63 time=141 ms
^C
--- www.gogole.co.uk ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 140.405/141.020/141.635/0.615 ms
vagrant@precise32:~$

Provisioning Host ifconfig:
tfadmin@hobo1:~/projects/test1$ ifconfig
em1       Link encap:Ethernet  HWaddr 10:60:4b:5b:01:76  
          inet addr:10.69.50.85  Bcast:10.69.50.255  Mask:255.255.255.0
          inet6 addr: fe80::1260:4bff:fe5b:176/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1785569 errors:0 dropped:40462 overruns:0 frame:0
          TX packets:402981 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1065103768 (1.0 GB)  TX bytes:31584989 (31.5 MB)
          Interrupt:20 Memory:f7100000-f7120000 

Nick Downs

unread,
Nov 14, 2013, 1:05:13 PM11/14/13
to vagra...@googlegroups.com
Check out this issue: https://github.com/nickrw/vagrant/commit/a0b684a4ab4a447d408b083c7d62d5f6b5e7d817

I would try adding the following option to your network config to see if it changes anything:

config.vm.network :bridged, bridge: "em1", :use_dhcp_assigned_default_route => true

I could not find this option in the documentation but it was pulled in back in 2012. The issue I posted above references a ticket that states this doesn't work but I don't think it would hurt to try.

The /etc/network/interfaces template for Ubuntu is generated by the Debian plugin. Check here for the actual template source file: https://github.com/mitchellh/vagrant/blob/master/templates/guests/debian/network_dhcp.erb
Reply all
Reply to author
Forward
0 new messages