Linux Explorers

Exploring the wonderful world of Linux

March 28th, 2012

Network Connectivity Between a Virtual Guest to the Host in RHEL/CentOS

Networking, Virtual Machines, by programr101.

I have been experimenting with virtual machines on my Red Hat and CentOS systems and have been having issues with connecting to the host system from the virtual guest when using the host device’s NIC as the primary NIC interface. For example I cannot connect via SSH, VNC or to the HTTP server on the host machine when trying to access them from the Guest VM.

The virtual guest is using eth0 on the host as its network adapter. This was done to allow communication to other devices on the network without having to use NAT.  I am able to ping and connect to services such as HTTP and SSH on other physical machines on my network however not the host.  I am also able to connect to the virtual guest from other physical machines on the network.

I’ve tried setting eth0 to use the virtual network (192.168.100.0/24) and I was able to connect to the host and other physical machines, however the physical machines could not connect to the virtual guest as their IPs were on different networks.

I came up with the solution to add two NICs to the VMs.  Please see my solution below

First here is the virtual guest network card configuration for eth0

eth
Source device: Host Device eth0: macvtap
Device model: virtio
MAC address: xx:xx:xx:xx:xx:20
Source mode: VEPA

VM IP: 192.168.1.80

The IP to the VM Host: 192.168.1.2

Solution

The solution I found to this issue was to add an additional network interface (eth1) and configuring it to use the “default virtual network” as its interface (192.168.100.0/24). I then had to edit the config files to route all traffic to the host over the eth1 interface instead of eth0.  The steps I followed are below:

1) I added an additional network interface to the virtual gues using the “virt-manager” tool.  Below are the settings:

eth1
Source device: Virtual network 'default' : NAT to eth0
Device model: Hypervisor default
MAC address: xx:xx:xx:xx:xx:21
IP: 192.168.100.222 (DHCP)

2) Connect to the virtual guest as root

3) Next I created an “ifcfg-eth1″ config file and placed it in “/etc/sysconfig/network-scripts/” directory.  Here are the contents of the ifcfc-eth1 file.

/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="dhcp"
HWADDR="xx:xx:xx:xx:xx:21"
IPV6INIT="yes"
MTU="1500"
NM_CONTROLLED="yes"
ONBOOT="yes"
 

4) I created  file named “route-eth1″ and placed it in “/etc/sysconfig/network-scripts/” This file contains one line with syntax to route traffic to the host IP through the gateway IP for the virtual network 192.168.100.1.

 /etc/sysconfig/network-scripts/route-eth1
192.168.1.2 via 192.168.100.1

4) I rebooted the virtual guest for the settings to take effect.  You may also run the command “service network restart” to re-read the configuration files but if this doesn’t work a reboot should do the trick.

5) After rebooting test connectivity to the virtual host.

Again this works by routing traffic to the host system by using the network interface which is connected to the virtual network (eth1). 

There may be other solutions to this and I’d be happy to hear them so please share if you have another method.

 Thanks

Back Top

Responses to “Network Connectivity Between a Virtual Guest to the Host in RHEL/CentOS”

  1. Hi Kent,I agree that that could be a very valuable atddiion to VC Plus. But to give you something before Richard will be able to implement it into VC plus, I’ve uploaded a script that may ease your trouble.It uses the VI Perl Toolkit and searches a host for VM’s that have devices connected to them, and then automatically disconnects them so you can VMotion them. It’s eases your life if you want to put a host in Maintenance Mode and not worry about any connected Devices.You can download the script here:

    • This looks like information on VMWare but the progam used here is QEMU on Redhat Linux. It doesnt give you the option of using VMotion.

      programr101 at Reply

Leave a Reply

Your email address will not be published. Required fields are marked *