How to access guest virtual with CentOS using additional ip?

xav asked:

I have a dedicated server in Hetzner.
In which I have installed CentOS 7.4, inside it I have KVM with another CentOS 7.4.

I have requested an additional ip from Hetzner that has a Mac separated for virtualization purposes.

I would like the guest to have access to the internet and that this virtual machine can be accessed from the internet.

Here’s the data from the two ips I have with Hetzner robot.

Main IP: AA.BBB.CCC.DD

Gateway:       AA.BBB.CCC.1
Netmask:       255.255.255.192
Broadcast:     AA.BBB.CCC.63

Additional IP: AA.BBB.CCC.EE

Gateway:       AA.BBB.CCC.1
Netmask:       255.255.255.192
Broadcast:     AA.BBB.CCC.63

This is the file /etc/sysctl.d/99-hetzner.conf configuration

### Hetzner Online GmbH installimage
# sysctl config
net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1
# ipv6 settings (no autoconfiguration)
net.ipv6.conf.default.autoconf=0
net.ipv6.conf.default.accept_dad=0
net.ipv6.conf.default.accept_ra=0
net.ipv6.conf.default.accept_ra_defrtr=0
net.ipv6.conf.default.accept_ra_rtr_pref=0
net.ipv6.conf.default.accept_ra_pinfo=0
net.ipv6.conf.default.accept_source_route=0
net.ipv6.conf.default.accept_redirects=0
net.ipv6.conf.all.autoconf=0
net.ipv6.conf.all.accept_dad=0
net.ipv6.conf.all.accept_ra=0
net.ipv6.conf.all.accept_ra_defrtr=0
net.ipv6.conf.all.accept_ra_rtr_pref=0
net.ipv6.conf.all.accept_ra_pinfo=0
net.ipv6.conf.all.accept_source_route=0
net.ipv6.conf.all.accept_redirects=0

This is the initial configuration just installed and running host

DEVICE=enp0s31f6
ONBOOT=yes
BOOTPROTO=none
IPADDR=AA.BBB.CCC.DD
NETMASK=255.255.255.255
SCOPE="peer AA.BBB.CCC.1"
IPV6INIT=yes
IPV6ADDR=2a01:4f8:13b:1801::2/64
IPV6_DEFAULTGW=fe80::1
IPV6_DEFAULTDEV=enp0s31f6

This is the previous file modified to get a bridge

DEVICE=enp0s31f6
ONBOOT=yes
HWADDR=90:1b:0e:ee:05:4e
BOOTPROTO=none
IPADDR=AA.BBB.CCC.DD
NETMASK=255.255.255.192
SCOPE="peer AA.BBB.CCC.1"
BRIDGE=br0

This is the br0 file I created

DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=AA.BBB.CCC.DD
NETMASK=255.255.255.192
SCOPE="peer AA.BBB.CCC.1"
ONBOOT=yes
DELAY=0

Does anyone know what configuration should be done in CentOS guest?

Is there something wrong with what I’ve done published above?

Thank you so much for the help.

My answer:


First, you need to create the guest’s virtual network interface using the virtual MAC address that Hetzner assigned to you, and bridged to br0 on your host system. For example (libvirt XML):

    <interface type='bridge'>
      <mac address='00:0c:29:34:b3:a1'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/>
    </interface>

You then configure the guest OS with the associated IP address, netmask and gateway. The IP address is not assigned to the host.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.