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
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
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:
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.
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.
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.