17

I have a physical server running CentOS 6.5 with one interface connected to the Internet (with one public IP address). Inside this server I have two VMs created with KVM through libvirt with one interface each. I want to assign one public IP address to each VM and continue using the connection with the physical server.

This picture illustrates what I have in black and what I want in blue: Network topology.

I have tried various ways, like adding a Linux bridge with brctl and attaching server physical interface and both VMs virtual interfaces, but it didn't work and I lost connectivity to the physical server.

I'm open to use Linux bridges or libvirt networking.

How I can get public IP addresses in both VMs and in the physical server?

5
  • Try to add second adapter to Virtual Machines and connect them into internal server network.
    – shcherbak
    Nov 26, 2015 at 10:31
  • what internal server network? anyway I want the setup of the question, if possible.
    – logoff
    Nov 26, 2015 at 10:32
  • Suppose, this will help: [KVM - Create a virtual machine with 2 bridges interfaces] (askubuntu.com/questions/581771/…), [KVM network bridge with two NICs] (serverfault.com/questions/130134/…)
    – shcherbak
    Nov 26, 2015 at 10:41
  • once again, I would prefer having only one interface per VM, if possible.
    – logoff
    Nov 26, 2015 at 10:47
  • i answered a similar question about debian kvm host & guest yesterday. unix.stackexchange.com/questions/245073/… - aside from minor details of interface setup, should be similar on centos.
    – cas
    Nov 26, 2015 at 12:47

1 Answer 1

7

Finally I found the proper way to achieve question goal. It implies Linux bridging, because I wasn't able to solve the issue with libvirt networking.

Steps:

  1. Identify KVM VM interfaces. Probably interfaces names start with vnet*

In this example vnet0 and vnet1

  1. Create a Linux bridge with:

    brctl addbr virbr1

  2. Attach Physical interface and KVM VMs interfaces to new bridge:

WARNING: if you are connected to the physical server through the network (SSH, Telnet, etc.), you will lose connection. Use a terminal or an alternative method (like other interface with connectivity).

brctl addif virbr1 vnet0
brctl addif virbr1 vnet1
brctl addif virbr1 eth0
  1. Configure physical server interface not having assigned IP address:

In CentOS 6.5, edit file /etc/sysconfig/network-scripts/ifcfg-eth0 with these contents:

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NAME=eth0
TYPE=Ethernet
IPV6INIT=no
USERCTL=no
  1. Configure physical server bridge to have IP address:

In CentOS 6.5, edit file /etc/sysconfig/network-scripts/ifcfg-virbr1 with these contents:

DEVICE=virbr1
BOOTPROTO=none
ONBOOT=yes
IPADDR=<physical_server_public_ip_address>
NETMASK=<physical_server_public_ip_netmask>
GATEWAY=<physical_server_gateway_ip_address>
NAME=virbr1
TYPE=Ethernet
IPV6INIT=no
USERCTL=no
NM_CONTROLLED=no
DNS1=<physical_server_primary_dns_server_ip_address>
DNS2=<physical_server_secondary_dns_server_ip_address>
  1. Restart physical server networking:

service network restart

NOTE: you should recover physical server networking connectivity (through the interface and the bridge)

  1. Configure network interface of the KVM VMs:

This depends on the OS of the VMs. Anyway it should include IP address, netmask and default gateway, at least. Obviously DNS servers will complete the configuration.

All these configurations are static and could be substituted by DHCP assignment. In this case, MAC addresses of the bridge and the KVM VM interfaces could be useful.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .