Connect Dedicated Servers (vSwitch)

Last change on 2020-11-03 • Created on 2020-11-03

Overview

Dedicated Servers can be attached to Cloud Private Networks. This will enable Cloud and Dedicated Servers to reach each other via their private Network links. For example if you run your Web Frontends on Cloud Servers and your Database on a Dedicated Server you can use the private link to connect both.

Rough overview:

image

It works by using the existing private network mechanisms for both systems:

  • Private Networking for Cloud is done by creating a "Network" and adding your Cloud Servers to it.
  • Private networking for Dedicated Servers is done by creating a "vSwitch" and attaching your Dedicated Servers to it.

Both systems are then coupled by creating a Cloud Network Subnet of type "vSwitch" which links the existing Cloud Network to the existing vSwitch. The network settings on the Cloud Servers are configured automatically. The Dedicated Servers require a special network configuration inside their Operating System for the coupling to work.

Details

Example of a coupled configuration:

image

Assumptions in this document

For the rest of the document we will assume that:

  • Your Cloud Network is 10.0.0.0/16 with subnets:

    • 10.0.0.0/24 for Cloud Servers. 10.0.0.2 is assigned to your Cloud Server
    • 10.0.1.0/24 for your vSwitch Connection. IP 10.0.1.2 is being used by your Dedicated Server
  • You have a vSwitch with vlan-id 4000
  • Your dedicated server has the network interface enp0s31f6 as its public network interface.

You might need to replace the values listed above with the actual values of your setup.

Attaching Dedicated Servers to Cloud Networks

Prerequisites

On the cloud side

You must have an existing Cloud Network with attached Cloud Servers. The Cloud Servers must be able to ping each other using their private IP addresses.

A Cloud Server cloudserver01 attached to a Cloud Network looks like this:

image

On the dedicated side

A Dedicated Server vSwitch must already exist in Robot and the relevant servers must be attached to it. However no private network configuration should be done on the Dedicated Servers yet. Follow this tutorial to create your vSwitch but skip the part for configuring your server operating system.

A vSwitch with vlan-id 4000 and one Dedicated Server called ex41 attached will look like this:

image

Step 1: In Cloud: Create Subnet of type vSwitch

Go to Cloud Console. Networks, click your existing network and select the Subnets tab.

image

Click Add Subnet:

image

Check "Enable dedicated server vSwitch connection" and select the existing vSwitch you want to couple your private network with. You can also pick an IP range your Dedicated Servers will use or go with the default one.

image

Afterwards click "Add Subnet". You will receive instructions on how to configure the network on your Dedicated Servers:

image

You can either follow these instructions - making sure to replace the network interface name, the vSwitch vlan id as well as the Dedicated Server IP with the correct values - or you can manually execute them using Step 2 of this article.

Your Cloud Network and the vSwitch are now coupled.

image

Step 2: Configure networking on your Dedicated Servers

For Cloud Servers the network configuration inside your operating system ist automatically done. For Dedicated Servers you need to do this configuration yourself. The necessary steps for a non persistent configuration were detailed in the "Configuration of your dedicated Server" dialogue in Step 1. The reason for the configuration is explained in this step.

What we want to configure

  • Setup a network interface for the vSwitch vlan (tagged vlan packets) and configure an mtu of 1400.
  • On that interface: Configure an IP-Address from the IP range of the subnet of type vSwitch (10.0.1.2 in example above) and set the first IP address of that subnet as gateway (10.0.1.1 in example). Make sure that every Dedicated Server uses its own, unique private IP address.
  • Configure a route for the network IP range pointing to the gateway (10.0.0.0/16 gw 10.0.1.1 in example above)

Persistent example configurations

Interface enp0s31f6 (usually called eth0, enp6s0 or enp0s31f6), VLAN 4000
Cloud Network: 10.0.0.0/16
Cloud Server Subnet: 10.0.0.0/24
vSwitch Server Subnet: 10.0.1.0/24 and 10.0.1.2 for your Dedicated Server vSwitch vlan: 4000

Example Debian configuration
# /etc/network/interfaces
auto enp0s31f6.4000
iface enp0s31f6.4000 inet static
  address 10.0.1.2
  netmask 255.255.255.0
  vlan-raw-device enp0s31f6
  mtu 1400
  up ip route add 10.0.0.0/16 via 10.0.1.1 dev enp0s31f6.4000
  down ip route del 10.0.0.0/16 via 10.0.1.1 dev enp0s31f6.4000
Example configuration systemd and netplan (e.g.Ubuntu 18.04)

Newer instances of installimage create netplan-based network configurations on Ubuntu 18.04. The /etc/systemd/network/ directory will be empty. To set up the vlan, you need to change the netplan file:

#/etc/netplan/01-netcfg.yaml
### Hetzner Online GmbH installimage
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s31f6:
      addresses:
...
  vlans:
    enp0s31f6.4000:
      id: 4000
      link: enp0s31f6
      mtu: 1400
      addresses:
        - 10.0.1.2/24
      routes:
        - to: "10.0.0.0/16"
          via: "10.0.1.1"

After that you have to execute the following commands and the network should be available:

sudo /lib/netplan/generate
sudo systemctl restart systemd-networkd
Example configuration for systemd

Create two new files for systemd-networkd:

#/etc/systemd/network/10-enp0s31f6.4000.netdev
[NetDev]
Name=enp0s31f6.4000
Kind=vlan
MTUBytes=1400
[VLAN]
Id=4000
#/etc/systemd/network/10-enp0s31f6.4000.network
[Match]
Name=enp0s31f6.4000
[Network]
Description="VLAN 4000"
Address=10.0.1.2/24
[Route]
Gateway=10.0.1.1
Destination=10.0.0.0/16
GatewayOnlink=yes

In newer systemd versions (v242+) you have to use the Option (GatewayOnLink, upper case L) in the last line.

Add the following line into file:

#/etc/systemd/network/10-enp0s31f6.network
....
[Network]
...
VLAN=enp0s31f6.4000

Restart service:

sudo systemctl restart systemd-networkd

Step 3: Test

The example values in this section reflect those of chapter Assumptions above.

3.1: Ensure that network configuration looks right on your Cloud Server

Run the command to show your routes:

ip route show
10.0.0.0/16 via 10.0.0.1 dev ensXX
10.0.0.1 dev ensXX scope link

3.2: Ensure that network configuration looks right on Dedicated Server

Run the command to show your routes:

ip route show

It should include the following lines.

10.0.0.0/16 via 10.0.1.1 dev enp0s31f6.4000
10.0.1.0/24 dev enp0s31f6.4000 proto kernel  scope link  src 10.0.1.2

The vSwitch gateway should be pingable:

$ ping 10.0.1.1
PING 10.0.1.1 (10.0.1.1) 56(84) bytes of data.
64 bytes from 10.0.1.1: icmp_seq=1 ttl=64 time=6.45 ms
...

3.3: Cloud Server should be pingable from Dedicated Server

From Dedicated Server ping the Cloud Server IP address:

$ ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=62 time=26.6 ms
...
Table of Contents