How to force Vagrant to have a single, bridged, network interface

20,966

You can try to add the adapter: 1 to the config. Although I still find some problem with it. See if it will help you starts from somewhere.

Example:

config.vm.network "public_network", bridge: "Broadcom BCM5709C", adapter: "1", ip: "192.168.x.xx"

You will still have the eth1 which is host-only network...

Share:
20,966

Related videos on Youtube

Amos Shapira
Author by

Amos Shapira

A Linux system-administrator-turned-developer-turned-DevOps over more than a couple of decades in the field.

Updated on September 18, 2022

Comments

  • Amos Shapira
    Amos Shapira over 1 year

    Using vagrant 1.7.2 on OSX (MacBook Pro), Ubuntu 14.04 guests, VirtualBox 4.3.26. Mac is connected to the world via standard WiFi interface.

    I want the Vagrant boxes to use the bridged network on the local LAN as their primary (and only) interface. This is required for experimenting with tcptraceroute, which doesn't do the right thing through the NAT'ed network. What I have now in my Vagrantfile is:

    Vagrant.configure(2) do |config|
      config.vm.provider "virtualbox"
      config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)"
      config.vm.box = 'ubuntu/trusty64'
    end
    

    And what I get inside the Vagrant box is:

    $ ip -o -4 a
    1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever
    2: eth0    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0\       valid_lft forever preferred_lft forever
    3: eth1    inet 172.16.69.16/24 brd 172.16.69.255 scope global eth1\       valid_lft forever preferred_lft forever
    

    (172.16.69/24 is my LAN address). If I manually take down eth0 and switch the default route to 172.16.69.1 then I can use the VirtualBox as I want to:

    # ifdown eth0
    Internet Systems Consortium DHCP Client 4.2.4
    Copyright 2004-2012 Internet Systems Consortium.
    All rights reserved.
    For info, please visit https://www.isc.org/software/dhcp/
    
    Listening on LPF/eth0/08:00:27:56:a8:46
    Sending on   LPF/eth0/08:00:27:56:a8:46
    Sending on   Socket/fallback
    DHCPRELEASE on eth0 to 10.0.2.2 port 67 (xid=0x69745103)
    # route add -net default gw 172.16.69.1
    # route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use    Iface
    0.0.0.0         172.16.69.1     0.0.0.0         UG    0      0        0 eth1
    172.16.69.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
    

    And now tcptraceroute works right.

    My question is - how can I configure Vagrantfile to avoid bringing up the eth0 interface as a NAT'ed interface and just bring it up as a single, bridged interface?

    I tried playing around with config.vm.network "private_network" as partly explained in http://docs.vagrantup.com/v2/virtualbox/networking.html but as far as I followed all it did was to add interfaces to the box, not replace the default NAT'ed inetface on eth0.

  • Amos Shapira
    Amos Shapira over 8 years
    Thanks. Adding "adapter: '1'" did what I wanted - the VirtualBox came up with exactly one adapter eth0 which is bridged on my LAN and having an IP which it received from the DHCP on my modem. Vagrant itself failed because it was trying to connect to it over my "host-only" network but that's another issue.
  • Hawxby
    Hawxby over 7 years
    Did you manage to solve the vagrant failing to connect issue?
  • Amos Shapira
    Amos Shapira over 7 years
    @Hawxby since it was a one-off experiment I didn't bother to find a solution for it. I just manually ssh'ed into the instance to do my experiments.