10

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
7
  • Can you check your setup w/ virsh as described here: wiki.libvirt.org/page/…. Also the box needs to allow this: net.ipv4.ip_forward = 1 .
    – slm
    Oct 5, 2014 at 1:46
  • @slm, thanks. I have added the output to the question.
    – Ramesh
    Oct 5, 2014 at 2:03
  • What's the status of ipv4.ip_forward?
    – slm
    Oct 5, 2014 at 12:24
  • Also if you take a look at your setup using virt-manager: linuxnix.com/2013/02/…
    – slm
    Oct 5, 2014 at 12:45
  • I modified the /etc/sysctl.conf file to change the status of ipv4.ip_forward to 1.
    – Ramesh
    Oct 5, 2014 at 15:24

2 Answers 2

8

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

0

setup static routes in your router(192.168.1.1).

# ip route add 192.168.1.160/27 via 192.168.1.9 dev < wlan iface>

or via webui.

add iptables forward routes on your host from router to 192.168.1.160/27 and vice versa (although, i think, libvirt provides these rules already).

3
  • Thanks for the answer. But unfortunately this solution did not work.
    – Ramesh
    Oct 5, 2014 at 3:39
  • is your KVM guest NATed or routed to your host?
    – mVincent
    Oct 5, 2014 at 14:35
  • The KVM is routed to the host.
    – Ramesh
    Oct 5, 2014 at 15:23

You must log in to answer this question.

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