I started using Vagrant recently to quickly install virtual machines. I noticed that my network configuration isn't perfect, but I can't get it right.
This is my Vagrantfile:
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
config.vm.provider "libvirt" do |lv|
lv.driver = "kvm"
end #config.vm.provider
#how many hosts to deploy?
n = 1
(10..n+9).each do |i|
config.vm.define "#{i}" do |vs|
vs.vm.hostname = "vs-#{i}"
vs.vm.network "private_network", ip: "10.0.0.#{i}"
end #config.vm.define
end #loop
#copy local ssh key to vm with ansible
config.vm.provision :ansible do |ansible|
ansible.playbook = "vagrant-provision.yml"
## Debugging
#ansible.verbose = true
#ansible.verbose="vvvvv"
end
end #Vagrant.configure
My box starts up correctly and it is also reachable via the defined IP address (10.0.0.X), but this address is on eth1. Vagrant is creating another interface first, eth0, and this interface receives a 192.168.121.XXX address. I would like to get rid of this one, but I don't know how.
This is the output of vagrant ssh-config:
$ vagrant ssh-config
Host 10
HostName 192.168.121.148
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/max/vagrant/vs/.vagrant/machines/10/libvirt/private_key
IdentitiesOnly yes
LogLevel FATAL
This is from within the vm:
root@vs-10:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:b1:1f:fd brd ff:ff:ff:ff:ff:ff
inet 192.168.121.148/24 brd 192.168.121.255 scope global dynamic eth0
valid_lft 3503sec preferred_lft 3503sec
inet6 fe80::5054:ff:feb1:1ffd/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:c8:05:48 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.10/24 brd 10.0.0.255 scope global eth1
valid_lft forever preferred_lft forever
root@vs-10:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
address 10.0.0.10
netmask 255.255.255.0
#VAGRANT-END
As you see, the defined address in my Vagrantfile is getting inserted in the interfaces file, but for eth1. eth0 is not defined there, but still shows up when I run ip addr. I would like to have the address 10.0.0.10 on the interface eth0 and get rid of the 192.168.121.XXX address.