linux - QEMU outside gateway

08
2014-07
  • codeBarer

    I've created two instances of CentOS6.5 (KVM) using Virtual Manager and I'm able to ping google.com, yahoo.com,etc... However the ip addresses for the instances are 192.168.0.* and the machine that they reside on has the gateway 192.168.0.1 I want the instances to connect to the same gateway (1.2.3.1) as the computer that is hosting the VM's and get addresses such as 1.2.3.*.

    I'm new to networking any pointers would help. I would the issue above would require updating the route tables but not sure how it would happen. Hopefully the attached picture might help explain the layout better.

    Thanks in advance :).

    Layout

  • Answers
  • Roman K.

    You'll want to bridge the physical interface with the guest interfaces.

    http://wiki.libvirt.org/page/Networking#Bridged_networking_.28aka_.22shared_physical_device.22.29

    This describes how to make the changes in libvirt which is probably backing your KVM.

    http://www.techotopia.com/index.php/Creating_a_CentOS_6_KVM_Networked_Bridge_Interface

    This is tailored for Virtual Manager, and likely a lot easier. If you can I'd recommend learning the libvirt side of things so you're more familiar with what's going on.

    It's important to note you'll be creating a bridge with your physical interface, and then point your guests to that bridge. Once configured you'll be able to use the network as usual. The most common mistake I've seen is assigning the bridge to the physical interface, or assigning the guest to use the physical interface instead of the bridge. Virtual manager will likely catch both of these, but its good to watch out for these things.

    A few things to remember about bridged interfaces:

    1) The guest is essentially on your network, meaning you should treat it as such and run any security or monitoring software right on it. You don't want the host running the guest and then processing everything again.

    2) You'll hit the cap on that interface pretty quickly if you're not careful.


  • Related Question

    linux - How do I configure routing table to add correct gateway?
  • Zenet

    I'm getting this error when I try to ping 8.8.8.8 from my Virtual Machine:

    PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
    From 172.30.8.135: icmp_seq=1 Redirect Host(New nexthop: 172.30.8.254)
    From 172.30.8.135: icmp_seq=2 Redirect Host(New nexthop: 172.30.8.254)
    

    When I try wget http://www.google.com I get failed: connection timed out.

    This is the output of route -n:

    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    172.30.8.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0
    0.0.0.0      172.30.8.135       0.0.0.0   UG     0      100       0 eth0
    

    This is how my network looks like: I have created br0 as a bridge over eth0 to run this VM. The host has this IP 172.30.8.135.

    The host has access to internet through eth0 and this is the output of route inside the host:

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    172.30.8.0      0.0.0.0         255.255.255.0   U     0      0        0 br0
    0.0.0.0         172.30.8.254    0.0.0.0         UG    100    0        0 br0
    

    Thanks in advance for any clues on this!


  • Related Answers
  • hbdgaf

    eth0 needs to be in promisc mode to pass traffic to the bridge

    my setup is physical eth0 in promisc with no ip address, br0 with an dhcp ip and using the bridge as my "interface" for the hardware machine with a route to the gateway from dhcp, then a tap interface added to the bridge and this is used as a "bridged" interface in the virtualization product. does that help?

    a tutorial on setting up virtualization with tap interfaces and reachability: http://www.blindhog.net/linux-bridging-for-gns3-lan-communications/

  • pevik

    In my case helped iptables on router:

    iptables -A POSTROUTING --table nat ! -o tap0 -j MASQUERADE