How to create same subnet IP interface within host network by vagrant-libvirt
Objectives
- Usually, vagrant-libvirt creates an interface within virbr* network subnet.
- virt-install command can attach to host bridge network with the option "--network=bridge:br0"
- How to assign a vagrant-libvirt's interface to host bridge like virt-install does?
- If possible, I can access to the VM from my client notebook within KVM host network without adding routing configuration etc
- And that is possible.
System
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
$ vagrant --version
Vagrant 1.8.1
$ vagrant plugin list
fog-libvirt (0.0.3)
- Version Constraint: 0.0.3
vagrant-libvirt (0.0.35)
- host network is 192.168.100.0/24 has dhcp server.
- attach bridge interface "br0" on KVM host.
$ ip a s br0 | grep -Ei "br0|inet4"
8: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
inet 192.168.100.5/24 brd 192.168.100.255 scope global br0
Configure Vagrantfile
$ cat Vagrantfile
Vagrant.configure(2) do |config|
config.vm.define :vm1 do |vm1|
vm1.vm.box = "centos/7"
vm1.vm.network :public_network, :type => "bridge",
dev: "br0",
mode: "bridge",
network_name: "public_network"
end
end
vagrant up
[vagrant@localhost ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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 qlen 1000
link/ether 52:54:00:f6:a0:c2 brd ff:ff:ff:ff:ff:ff
inet 192.168.121.21/24 brd 192.168.121.255 scope global dynamic eth0
valid_lft 3579sec preferred_lft 3579sec
inet6 fe80::5054:ff:fef6:a0c2/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:31:b9:94 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.163/24 brd 192.168.100.255 scope global dynamic eth1
valid_lft 578sec preferred_lft 578sec
inet6 fe80::5054:ff:fe31:b994/64 scope link
valid_lft forever preferred_lft forever
Confirmation
C:\WINDOWS\system32>ping 192.168.100.163
Pinging 192.168.100.163 with 32 bytes of data:
Reply from 192.168.100.163: bytes=32 time=1ms TTL=64
Reply from 192.168.100.163: bytes=32 time=2ms TTL=64
Reply from 192.168.100.163: bytes=32 time=1ms TTL=64
Reply from 192.168.100.163: bytes=32 time=2ms TTL=64
Ping statistics for 192.168.100.163:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 2ms, Average = 1ms