kvm "default" NAT network doesn't work

18,566

You need to setup a macvtap from your host to allow your VM's guest to have an internet connection which in your case you have your NAT configuration for hosts to guest connection only.

Also, I advised you to have virt-manager installed to know the basic concept and setups of KVM graphically then you can do it to CLI the next time.

For your reference,I have a connection from host to guest connection this configuration is NAT with virtio.

This is my host to guest connection

Now for your guest VM to have a connection set up the macvtap, but first you have to create a separate bridge connection here and then the macvtap.

This is the setup for guest connection outside

By the time you set it up you should have this network configuration.

For your reference

Another one would be the guest xml file which was located in /etc/libvirt/qemu/guest.xml - But do not edit that it only serves as reference

This is sample network setup from one of my guest

This is my centos guest network configuration

I am not adept on the CLI part but here is the thing I've done to make this case work.

Hope this helps.

Share:
18,566

Related videos on Youtube

Sunnyrain
Author by

Sunnyrain

Updated on September 18, 2022

Comments

  • Sunnyrain
    Sunnyrain over 1 year

    I just created a virtual machine using qemu-kvm. Both the host and the guest is Ubuntu 16.04 LTS. However, the guest doesn't have access to internet. I can ping host from guest or ping guest from host. Here is the output of from host's ifconfig

    eno1      Link encap:Ethernet  HWaddr 6c:0b:84:98:06:a3  
              inet addr:10.7.202.66  Bcast:10.7.202.255  Mask:255.255.255.0
              inet6 addr: fe80::5388:4cd6:d475:94ca/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:41093 errors:0 dropped:0 overruns:0 frame:0
              TX packets:100041 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:7514291 (7.5 MB)  TX bytes:117854779 (117.8 MB)
              Interrupt:20 Memory:f7c00000-f7c20000 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:377404 errors:0 dropped:0 overruns:0 frame:0
              TX packets:377404 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:1034501784 (1.0 GB)  TX bytes:1034501784 (1.0 GB)
    
    virbr0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
              inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:3539 errors:0 dropped:0 overruns:0 frame:0
              TX packets:953 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:240370 (240.3 KB)  TX bytes:141550 (141.5 KB)
    

    And here is the output from virsh net-dumpxml default:

    <network>
      <name>default</name>
      <uuid>f4a19eaf-dbfa-46a5-bc9a-ccdc809363be</uuid>
      <forward dev='eno1' mode='nat'>
        <nat>
          <port start='1024' end='65535'/>
        </nat>
        <interface dev='eno1'/>
      </forward>
      <bridge name='virbr0' stp='on' delay='0'/>
      <mac address='52:54:00:3e:46:10'/>
      <ip address='192.168.122.1' netmask='255.255.255.0'>
        <dhcp>
          <range start='192.168.122.2' end='192.168.122.254'/>
        </dhcp>
      </ip>
    </network>
    

    And output from host's route -n:

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         10.7.202.251    0.0.0.0         UG    100    0        0 eno1
    10.7.202.0      0.0.0.0         255.255.255.0   U     100    0        0 eno1
    10.22.224.196   10.7.202.251    255.255.255.255 UGH   100    0        0 eno1
    169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eno1
    192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
    

    I also enabled net.ipv4.ip_forward=1 in /etc/sysctl.conf.

    Can anyone suggest anything else to do?

  • user68186
    user68186 over 6 years
    Are you sure you need two NICs? Mine works with the just one NIC, Network source set at default NAT and device model set at virtio.
  • Yien
    Yien over 6 years
    i got many guest VM's and I've separated each to their own bridges but you can use any it the way you want it and will work on a one nic configuration for many VM's. It's just I've been doing it to separate for faster isolation should I have problems with it.
  • Sunnyrain
    Sunnyrain over 6 years
    Thank you for the detailed answer although my original question is really why my NAT network setup doesn't work. I finally figured it out that it actually worked but I didn't have the correct proxy setup. I updated the proxy settings in /etc/environment and NAT network works fine. I cannot use other network setup because it is not allowed by company's IT.
  • SeligkeitIstInGott
    SeligkeitIstInGott about 4 years
    In this case is ens9 (I presume in your guest VM) the thing that was bridged to eno1 on the host? Where did it get the 172.69 address from? I'm having trouble knowing how to set up the guest networking, as far as static or DHCP. I also saw a few confusing examples of people setting up bridge interfaces inside a guest vm which I think was a red herring. On that topic the 192.168.122.X IP and subnet has no role in the bridging example shown above right? That's just the default bridge subnet and interface that KVM installs, but isn't what makes the NAT forwarding in your example possible, right?
  • kas
    kas almost 4 years
    Thank you! Internet was not working in my guest, and nowhere was it explained that I need to set my NIC to "Virtual network 'default' : NAT"!