Setup the guest network in KVM to interact with the outside world (google.com )

networking

I am trying to better understand the network setup in my machine.

Host Machine Setup

  1. I have a wireless interface (wlan0) on my host machine which has
    the IP address as 192.168.1.9.
  2. The default gateway of this host is the router which goes to the
    outside world through my ISP, whose IP address is 192.168.1.1.
  3. The route -n command in my host machine returns me the output as,

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 wlan0
    169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlan0
    192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0
    192.168.1.160   0.0.0.0         255.255.255.224 U     0      0        0 virbr2
    

Guest Machine Setup

Now, I setup a guest OS in KVM as below.

  1. The KVM is in a sub-network which has the details as
    192.168.1.160/27.
  2. The DHCP start is 192.168.1.176 and the DHCP end is 192.168.1.190.
  3. I also did the below command for my KVM configuration to work.

    arp -i wlan0 -Ds 192.168.1.9 wlan0 pub
    

From the guest OS, I see that my IP address is 192.168.1.179. My route -n command in the guest machine returns me the output as,

kernel IP routing table
Destination     Gateway         Genmask
0.0.0.0        192.168.1.161    0.0.0.0
192.168.1.160  0.0.0.0          255.255.255.224

How can I make the guest OS to interact with the outside world?

EDIT

This is the output of virsh net-list --all.

ramesh@ramesh-pc:~$ virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 arpbr0               inactive   yes           yes
 default              active     yes           yes
 proxyArp             active     yes           yes

Best Answer

I would like to thank user slm for guiding me in the right direction in setting up the guest network in the KVM. I will add the screen shots to the answer so that it will be more informative.

I assume the virt-manager package is installed and also the host machine is setup with the necessary packages for KVM to work.


Preparing the Network For Guest to Host Interaction


The main step in the KVM is setting up of the network. If the machine is not available in the network, then it serves no purpose, be it physical or virtual.

Type virt-manager in the terminal. The console would show up as below.

Initial Virtual Manager Console Window

Click on Edit -> Connection Details and a new screen would pop up as below.

After Clicking Edit button

Click on Virtual Networks tab and from there click on the + button to add a new network to the KVM guests.

Creating a new Virtual Network

Click on Forward and then we would be presented with the below screen. Now, the IPV4 addresses we choose here is completely up to our choice and we could optimize this step to suit our actual needs.

Choosing an IPv4 Address Space

After we click on Forward in the above screen, we would be presented with the below screen. In this step, it basically tells the address space available for us.

DHCP Addresses available

In this step, choose forwarding to physical network and select the host's network interface which will help the guests to interact with the outside world.

Choose NAT with the host physical device

After the above step, we are almost done and we just would be presented with the below screen, which is kind of a review of all the details we chose so far.

Final Step


Adding this new device to our Guest OS


From the initial screen of virt-manager, click on the Open and we will be presented with a screen as below.

First Step

From the above screen, click on the i to open up another screen as below.

second step

Click on Add Hardware and select Network. In the Network tab, select the host device as our newly created network in the previous step and click on Finish as shown in the below screen.

Final Configuration


Testing in the guest OS


Now, inside the guest OS make sure that you are able to ping the host machine and outside network such as google. If the ping succeeds, then we have successfully setup our network in the guest OS.


References


The reference material used to setup the guest network

Related Question