Vagrant configure Box interfaces ( with static IP address )

1- add  a second interface  ( Public Network )

2- modify the default interface ( NAT ) to have only a single interface

3- if more then one bridge interface is available

4- add  a second interface  ( Private Network )


https://www.vagrantup.com/docs/networking/public_network.html


1- add  a second interface ( into the Vagrantfile) Public Network


1a- First: find the name of the interface


1b- edit the Vagrantfile and add


$ cd /cygdrive/c/Users/jkriker/Documents/vagrant/ubuntu


# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
config.vm.network "public_network", bridge: "Intel(R) Ethernet Connection I219-LM" , ip: "192.168.0.101"


1c- look at the box creation

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-16.04' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => C:/Users/jkriker/Documents/vagrant/ubuntu
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.


2- modify the default interface ( NAT ) to have only a single interface


edit Vagrantfile

  config.vm.network "public_network", adapter: "2", bridge: "Intel(R) Ethernet Connection I219-LM" , ip: "192.168.0.101"


config.vm.network "public_network", :adapter=>1 ,bridge: "Intel(R) Ethernet Connection I219-LM"      >>>>>> ip: "x.x.x.x" did not work for adapter 1!?!#@


adapter: "2"    create the second interface

adapter=>"1"  override he first one


3- if more then one bridge interface is available


edit Vagrantfile

config.vm.network "public_network", bridge: [
  "en1: Wi-Fi (AirPort)",
  "en6: Broadcom NetXtreme Gigabit Ethernet Controller",
]

4- add  a second interface  ( Private Network )

https://www.vagrantup.com/docs/networking/private_network.html


Vagrant.configure("2") do |config|
  config.vm.network "private_network", type: "dhcp"
end

From the vagrantfile:



Select an "host-only" interface  with ip address ( name did not work!! )

config.vm.network "private_network", adapter:"2",ip:"192.168.99.10"