0

I have a KVM server and two VMs. I have one main IP and two additional "single" IPs (not a subnet). I don't want have a local network with private addresses on my KVM, but I want to assign my public IPs from the provider (which I bought) to the VMs and I want to manage the routing of those IPs on the KVM Host, not on the provider side (so, no just bridging from the provider, but maybe bridging from my host to the VMs)

All the tutorials I found in the Internet are a bit confusing, because they are all different solving the same problem (but still doesn't work for me).

Update:

will this work?

auto  eth0
iface eth0 inet manual

auto vmbr0
iface vmbr0 inet static
  address 176.x.y.133 (not 192.168.1.1)
  netmask 255.255.255.224 (not 255.255.255.0)
  gateway 176.x.y.129 (Provider's GW IP)
  bridge_ports eth0
  bridge_stp off
  bridge_fd 0
static
  • 341
  • 2
  • 4
  • 16

1 Answers1

2

Your setup doesn't really have anything to do with public IPs - your underlying problem is that you need to use a bridged network instead of a NATted or host-only bridge.

Put something like the following into /etc/network/interfaces:

iface eth0 inet manual
iface br0 inet static
    bridge_ports eth0
    bridge_stp no
    bridge_fd 0
    bridge_maxwait 0
    address 192.168.1.2
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 192.168.1.2 8.8.8.8 8.8.4.4
    dns-search example.com

Reconfiguring of course for your particular setup.

Then configure your VM to bridge to br0 and it'll behave as though it's directly connected to the cable coming in to eth0.

i.e. your guest VM will look like:

<interface type='bridge'>
  <mac address='52:54:de:ad:be:ef'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
MikeyB
  • 39,291
  • 10
  • 105
  • 189
  • 192.168.x.x are private. Does it mean I create a new local network or it doesn't matter if I will set it to 176.x.y.z/27 where it is an IP I got from the provider? "...configure your VM to bridge to br0..." - just configuring the ip to one of my public IPs and GW to the br0's IP? Are any static routes needed to add with pre-up/post-down? – static Jul 15 '13 at 16:47
  • You're thinking about it wrong. In the file above, replace the network info with the address for your KVM host. Then in your guest, just give them the appropriate IPs that *would work if directly connected to the cable on eth0*. – MikeyB Jul 15 '13 at 17:14
  • What's *really* going on here is that you're configuring a *switch* (bridge==switch). Plug eth0 into the switch, then plug your KVM host and the VMs into the switch. – MikeyB Jul 15 '13 at 17:17
  • "file above": `/etc/network/interfaces` ? like in the Update to the question? Does it look like this?: #1# (KVM-Host)(eth0) -> (vmbr0) -> (Provider GW iface) ## #2# (KVM-VM)(eth0) -> (KVM-Host)(vmbr0) -> (Provider GW iface) ## – static Jul 15 '13 at 17:27
  • And now I have confusion: MAC-Addresses of eth0 and vmbr0 (on KVM-Host) are the same [http://serverfault.com/questions/523454/why-are-eth0-and-vmbr0-bridge-having-the-same-mac-addresses] – static Jul 15 '13 at 17:32
  • Yep, that's OK. – MikeyB Jul 15 '13 at 19:04
  • Still it doesn't work. The VM has empty routing and arp tables and I cannot add static routes (either IP-addr or MAC-addr: RTNETLINK: no such process, SIOCSARP: network is unreachable). I already removed the network-manager to be not confused with its own configs. – static Jul 15 '13 at 19:57
  • I added a route to the VM's MAC-addr: 176.x.y.155 ab:cd:ef:12:34:56. After that ping 176.x.y.155 doesn't respond anything: no even `timeout` or `network unreachable` – static Jul 15 '13 at 20:10
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/9664/discussion-between-static-and-mikeyb) – static Jul 15 '13 at 20:10