I have Hetzner dedicated server where is installed Ubuntu server 16.04.
That server has public ip: 198.51.100.33 (only for explanation).
On that server I have installed KVM.
I have bought additional ip address which I want to add to KVM VPS.
How I can add additional ip address to virtual machine?
I have google it and over 10 times crashed network of host server so I had to connect over remote console Lara to restore network configuration.
Thank you
UPDATE 1:
Host server ip: 198.51.100.160
Ip for VPS: 198.51.100.187
Those are fake IP's, used only for explanation
Here is content of /etc/network/interfaces on host server
### Hetzner Online GmbH installimage
auto lo
iface lo inet loopback
iface lo inet6 loopback
auto eth0
iface eth0 inet static
address 198.51.100.160
netmask 255.255.255.192
gateway 198.51.100.129
# route 198.51.100.128/26 via 198.51.100.129
up route add -net 198.51.100.128 netmask 255.255.255.192 gw 198.51.100.129 dev eth0
iface eth0 inet6 static
address 2a0:4d8:201:231d::2
netmask 64
gateway fe80::1
I have added on the bottom this:
auto eth0:1
iface eth0:1 inet static
address 198.51.100.187
gateway 198.51.100.129
netmask 255.255.255.192
After that I have installed virt-manager for kvm on host server and connected over vnc to host server.
Using GUI virt-manager I have created virtual machine.
How to add that second ip to that VPS?
Here is screenshot of choices:
UPDATE 2:
Bought subnet ip 198.51.110.64 / 29
Best Answer
Well. The good choice is using bridge interfaces. The bridge works alike unmanaged switch. You can connect to one bridge several virtual machines. Also you can use VLANs inside one bridge or create each bridge per VLAN.
From debian WiKi:
You don't need to add route
route add -net 198.51.100.128 netmask 255.255.255.192 gw 198.51.100.129 dev eth0
because network is locally connected to eth0 (eth0 has IP address from this network) and gateway198.51.100.129
is the same as default gateway IP address.Before all you need to install
bridge-utils
:And allow forwarding IP traffic between interfaces:
To allow forwarding all IP packets via firewall on the host server you need to add firewall rule:
You have
198.51.100.160/26
ip address on theeth0
interface of the host server and you need to assign198.51.100.187/26
ip address on VPS1 virtual machine. You createbr0
bridge interface on the host and connecteth0
interface to the bridge. Then connect virtual network interface of VPS1 to thebr0
bridge in the settings of VPS1. Inside VPS1 you will assign198.51.100.187/26
ip address as static by example:To use second IP subnet
198.51.110.64/29
you can create second bridge interfacebr1
and assign first IP address 198.51.110.65/29 on it. Then you can connect other VPS machines to this bridge and assign static IP addresses from this network on them but default gateway IP address will be198.51.110.65/29
there.To do it change
/etc/network/interfaces
file on the host server as: