0

I set up the kvm vm with public static IP and everything works fine, but only after network restart on host. I mean, every time after host turned on, i must run "service network restart" and only after that KVM VM gets ip. Without restart, ip belongs to the host.

Host - centos 7, guest - ubuntu 12.04

Please, advise me how to make ip belong only VM, without network restart? Thank you!

My settings on host:

/etc/sysconfig/network-scripts/ifcfg-enp1s0f1:

DEVICE="enp1s0f1"
ONBOOT=yes
HWADDR="xx:xx:xx:xx:xx:xx"
BRIDGE=br0

/etc/sysconfig/network-scripts/ifcfg-br0:

DEVICE="br0"
TYPE=BRIDGE
ONBOOT=yes
BOOTPROTO=static
IPADDR="host.ip.adress"
NETMASK="255.255.252.0"
GATEWAY="host.gateway"
DNS1=11.11.11.11
DNS2=11.11.11.11

/etc/sysconfig/network-scripts/ifcfg-br0:1

DEVICE="br0:1"
TYPE=BRIDGE
ONBOOT=yes
BOOTPROTO=static
IPADDR="ip.for.kvm.vm"
NETMASK="255.255.252.0"
GATEWAY="host.gateway"
DNS1=11.11.11.11
DNS2=11.11.11.11

vm bridge section

 <interface type='bridge'>
      <mac address='yy.yy.yy.yy.yy.yy'/>
      <source bridge='br0:1'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </interface>

my '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: enp1s0f0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
3: enp1s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP qlen 1000
    link/ether xx:xx:xx:xx:xx:75 brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether zz:zz:zz:zz:zz:zz brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
    link/ether 52...4:98 brd ff:ff:ff:ff:ff:ff
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether xx:xx:xx:xx:xx:75 brd ff:ff:ff:ff:ff:ff
    inet host.ip.adress/22 brd ...3.255 scope global br0
       valid_lft forever preferred_lft forever
    inet ip.for.kvm.vm/22 brd ...3.255 scope global secondary br0:1
       valid_lft forever preferred_lft forever
    inet6 fe8...5/64 scope link 
       valid_lft forever preferred_lft forever
7: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 1000
    link/ether fe:5...1:6a brd ff:ff:ff:ff:ff:ff
    inet6 fe80...:516a/64 scope link 
       valid_lft forever preferred_lft forever

My settings on guest:

auto eth0
iface eth0 inet static
    address ip.for.kvm.vm
    netmask 255.255.255.0
    gateway host.gateway
    broadcast 
    hwaddress ether 52:54:00:2f:21:8b
    dns-nameservers 11.11.11.11 8.8.8.8 11.11.11.11

ip route show (on host)

default via host.gateway dev br0  proto static  metric 425 
89.108.120.0/22 dev br0  proto kernel  scope link  src host.ip.adress  metric 425 
172.17.0.0/16 dev docker0  proto kernel  scope link  src 172.17.0.1 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 

route -n (on host)

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         host.gateway    0.0.0.0         UG    425    0        0 br0
89.108.120.0    0.0.0.0         255.255.252.0   U     425    0        0 br0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
  • Have you got multiple routing tables on the host machine? Did you tried to compare output of ip route show before and after the need of the network restart? Would you share output of this commands? Also include other routing tables if there are, please. – Marco Oct 15 '17 at 8:08
  • Thank you for comment! I did not configure routing tables manually. ip route show before and after network restart are the equally! I'm added outputs in top message. – Arseniy Oct 15 '17 at 8:57
0

You've obfuscated the addresses for your host and guest, so I'll have to use the other data you provided to make an assertion, as well as guess that "ip.for.kvm.vm" is consistent in all of your examples. Please let me know if that's not correct.

What you describe looks like you're giving the same address to your hypervisor as you are to your VM, and both are competing for those addresses. The hypervisor will always win on a reboot, because its networking stack starts first.

Don't do that. You're creating an IP address conflict by doing this. Rather if you need your host machine to be in the same IP subnet as your guest, give them both different addresses in the same subnet. Realize also that your bridge device is a virtual layer 2 switch, so it's not going to care what you do at any layer above it. The only sign you will have that something is going wrong in an unaudited scenario like this is what you've described above in addition to errors in your logs about address conflicts.

To fix this particular scenario, either remove or set differently the address for br0.1 on the hypervisor. Since briges work on layer 2, you can have no IP address on this interface at all and the VM will network properly. Just don't make any conflicts.

  • Thank you very match for answer! Yes, «ip.for.kvm.vm» is consistent! I think I understood the problem, now i'm trying to make the solution. I'm delete IPADDR="ip.for.kvm.vm" from /etc/sysconfig/network-scripts/ifcfg-br0:1 but it did not work. No network in vm, but after network restart (on host) it works again! Probably this is not enough.. – Arseniy Oct 15 '17 at 16:22
  • After host up, "ip.for.kvm.vm" is free (cant ping it). After kvn VM up, "ip.for.kvm.vm" engaged by something (can ping it), but there is no internet in VM.. If i restart network on host, vm get the internet. Here's the situation now. May be firewalld problem? – Arseniy Oct 15 '17 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.