Francesco Marchioni
Francesco Marchioni

Reputation: 4328

Vagrant how to force libvirt to use a different network interface

I'm using Vagrant to define a Fedora machine with a static IP address.

Vagrant.configure("2") do |config|
  config.vm.network :public_network, :bridge => 'enp0s25', :dev => 'enp0s25'
  config.vm.network "private_network", ip: "192.168.122.1"
  config.vm.provision "shell", inline: "ifconfig"
  config.vm.define "fedora1" do |fedora1|
    fedora1.vm.box = "fedora/23-cloud-base"
  end
end

The problem is that if I try to provision the VM an error is raised:

Call to virDomainCreateWithFlags failed: Unable to get index for interface eth0: No such device

As a matter of fact I don't have eth0 on my Fedora 21 but

enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.1.71.85  netmask 255.255.255.0  broadcast 10.1.71.255
        inet6 fe80::6af7:28ff:fef3:b97d  prefixlen 64  scopeid 0x20<link>
        ether 68:f7:28:f3:b9:7d  txqueuelen 1000  (Ethernet)
        RX packets 1753807  bytes 1271298509 (1.1 GiB)
        RX errors 0  dropped 26  overruns 0  frame 0
        TX packets 771439  bytes 73736761 (70.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xe1200000-e1220000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 1450325  bytes 565140300 (538.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1450325  bytes 565140300 (538.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:5f:e6:70  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.121.1  netmask 255.255.255.0  broadcast 192.168.121.255
        ether 52:54:00:fe:98:b5  txqueuelen 0  (Ethernet)
        RX packets 3673  bytes 403458 (394.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2367  bytes 381415 (372.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Adding the line:

config.vm.network :public_network, :bridge => 'enp0s25', :dev => 'enp0s25'

didn't produce any effect. Is there any solution (besides restoring the old eth0 interface) ?

Upvotes: 2

Views: 7159

Answers (1)

Andrey Arapov
Andrey Arapov

Reputation: 101

I was facing the same problem today and the solution was as simple as just destroying the vagrant machine after the modifications were done to the Vagrantfile. vagrant destroy fedora1 && vim Vagrantfile && vagrant up fedora1 --provider libvirt

$ vagrant plugin list
fog-libvirt (0.0.3)
  - Version Constraint: 0.0.3
vagrant-libvirt (0.0.32)

$ vagrant version
Installed Version: 1.6.5

Hope that helps you.

Upvotes: 7

Related Questions