Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Create a WireGuard® Peer Between Two VDCs

Overview

This tutorial demonstrates how to configure the VPN Gateway product in IONOS CLOUD to create a WireGuard® based site-to-site setup between two Virtual Data Centers (VDCs) in different regions. It uses a managed WireGuard instance in each VDC to provide secure, encrypted connectivity between the two networks.

This tutorial demonstrates the use of the following:

Components

Description

Two VDCs

- Berlin VPN example (de/txl) is the first VDC. - London VPN example (gb/lhr) is the second VDC.

Managed gateways

A managed WireGuard gateway in each VDC (wg-txl and wg-lhr) provides secure, encrypted connectivity between the two VDCs in IONOS CLOUD.

Architecture diagram showing two IONOS CLOUD VDCs in de/txl and gb/lhr, each with a VPN Gateway, connected by a WireGuard tunnel over the internet on the default UDP port 51820
WireGuard site-to-site VPN between two IONOS CLOUD VDCs

Target audience

This tutorial is intended to help both developers and technical decision-makers.

What you will learn

By following this tutorial, you will learn how to:

  • Provision managed WireGuard VPN Gateways in IONOS CLOUD across different regions.

  • Generate and manage WireGuard key pairs for secure connectivity.

  • Set up LAN subnets and assign gateway addresses.

  • Configure a VPN peer on each gateway for site-to-site communication.

  • Manually add routing rules to enable traffic flow between the two VDCs.

  • Verify connectivity between hosts in separate VDCs.

Before you begin

Note: This document uses sample keys as examples. The sample keys are shortened for illustration, while real WireGuard keys are 44 characters long. Do not use these keys for real-world scenarios.

The following information is necessary to set up a WireGuard connection between two VDCs:

Components

Berlin VPN (Left) de/txl

London VPN (Right) gb/lhr

Datacenter Name

Berlin VPN example

London VPN example

Gateway Name

wg-txl

wg-lhr

Gateway Public Address

203.0.113.10

203.0.113.20

LAN ID

1

2

LAN Subnet

192.168.1.0/24

192.168.2.0/24

Gateway LAN Address

192.168.1.5/24

192.168.2.5/24

LAN Host 1

192.168.1.11 (berlin-lan-host-1)

192.168.2.11 (london-lan-host-1)

LAN Host 2

192.168.1.12

192.168.2.12

WireGuard Subnet

172.16.1.0/30

172.16.1.0/30

Gateway WireGuard Address

172.16.1.1/30

172.16.1.2/30

Gateway Private Key

abcdefABC12345=

kHKHABcC+67891=

Gateway Public Key

defDEFhiH/98765=

lmnoLMNO/89762=

Create the VDCs

Ensure you have already created two VDCs, one in de/txl and one in gb/lhr. Each VDC must contain two virtual servers connected to each other via a private LAN. For more information, see Create a Data Center.

Reserve IP addresses

Before proceeding, ensure you have an IP block with at least one free IP address to assign to each gateway. Each VPN Gateway must be assigned a public IP address. For more information, see Reserve an IPv4 Address.

Components

Berlin VPN (Left) de/txl

London VPN (Right) gb/lhr

Gateway Public Address

203.0.113.10

203.0.113.20

Configure LAN

This tutorial uses 192.168.1.0/24 for the private LAN in Berlin and 192.168.2.0/24 for the private LAN in London. Assign an IP address from each subnet to its respective gateway. For example, use 192.168.1.5 for the Berlin VPN Gateway and 192.168.2.5 for the London VPN Gateway.

The VPN Gateway is not DHCP-aware. Therefore, assign it a static address that is outside the DHCP pool, in the range from .2 to .9.

Components

Berlin VPN (Left) de/txl

London VPN (Right) gb/lhr

LAN ID

1

2

LAN Subnet

192.168.1.0/24

192.168.2.0/24

Gateway LAN Address

192.168.1.5/24

192.168.2.5/24

WireGuard interface IP address and subnet information

Each participant in a WireGuard VPN setup requires its own WireGuard interface address and subnet, which are unrelated to the networks you use in the cloud. Choose a subnet that does not conflict with anything already in use in the cloud or on the other side of the connection.

This tutorial connects two gateways, so it uses a /30 subnet. A /30 provides 2 usable host addresses, one for each gateway.

Components

Berlin VPN (Left) de/txl

London VPN (Right) gb/lhr

WireGuard Subnet

172.16.1.0/30

172.16.1.0/30

Gateway WireGuard Address

172.16.1.1/30

172.16.1.2/30

Generate key pairs

WireGuard requires a key pair for each gateway. You can generate them using the WireGuard utilities or the OpenSSL command-line tools. This tutorial describes both approaches and recommends the WireGuard utilities because the procedure is more straightforward. Generate one key pair for each gateway.

Components

Berlin VPN (Left) de/txl

London VPN (Right) gb/lhr

Gateway Private Key

abcdefABC12345=

kHKHABcC+67891=

Gateway Public Key

defDEFhiH/98765=

lmnoLMNO/89762=

Use wg genkey to create the private key and wg pubkey to derive the public key content from the private key. You can also perform it via a single command, as shown below. The umask 077 command ensures that only your user can read the key files. Repeat the process for each gateway.

The output shows the private key followed by the public key:

Use openssl to generate der keys and convert them to the required format for WireGuard. The umask 077 command ensures that only your user can read the key files. Repeat the process for each gateway:

The output shows the private key followed by the public key:

If the WireGuard tools are also available locally, you can verify the OpenSSL-generated key by deriving the public key from the OpenSSL-generated private key.

The output shows the public key:

The public key content matches the one generated by OpenSSL.

Procedure

1

Set up the VDCs

The following screenshot from the Data Center Designer (DCD) shows the Berlin VDC. It contains two virtual servers that are connected to each other via a private LAN. They have no other connectivity. In this instance, LAN 1 uses a custom subnet of 192.168.1.0/24. The two LAN hosts use the addresses 192.168.1.11 and 192.168.1.12.

Configuring Berlin VDC in the DCD

Set up the London VDC in the same way, using LAN 2 with the custom subnet 192.168.2.0/24. The two LAN hosts use the addresses 192.168.2.11 and 192.168.2.12.

2

Provision the VPN Gateways

Create the Berlin gateway (wg-txl) first, and then repeat the procedure for the London gateway (wg-lhr) using the values for that site.

1. In the DCD, go to Menu > Network Services > VPN Gateway.

2. Click Create VPN Gateway from the VPN Gateways window.

3. Enter the following details:

Components

Description

Example (Berlin)

Example (London)

Name

Enter a descriptive name for the gateway instance. It is not required to be globally unique but must be limited to 255 characters.

wg-txl

wg-lhr

Description

Enter a descriptive text for the gateway. It is limited to 1024 characters.

Not applicable

Not applicable

Location

Select a location from the drop-down list of available locations for VPN Gateway.

de/txl

gb/lhr

IP Address

Select an IP address from the drop-down list of available Public IPv4 Addresses.

203.0.113.10

203.0.113.20

Define properties

The Enhanced VPN tier is selected by default. The number of LANs and peers differ for each tier. You can also enable High Availability for a chosen tier, allowing VMs to operate in an active-passive mode. It minimizes downtime during a failover and ensures an uninterrupted connection.

Select a tier

Note: You can only upgrade the tier or switch between High Availability (HA) and non-HA variants during editing.

Select WireGuard protocol and specify the following:

Components

Description

Example (Berlin)

Example (London)

Private Key

The gateway_private_key value generated earlier in this tutorial for this gateway.

abcdefABC12345=

kHKHABcC+67891=

Interface IPv4

The IPv4 address of the WireGuard interface.

172.16.1.1/30

172.16.1.2/30

Interface IPv6

The IPv6 address of the WireGuard interface. This demonstration does not contain IPv6 addresses.

Not applicable

Not applicable

ListenPort

The UDP port on which WireGuard listens for encrypted VPN packets. The tutorial uses the default value 51820.

51820

51820

Select a protocol

Attach a VPN Gateway to LANs in IONOS CLOUD. You can only connect to LANs in the exact location where the VPN Gateway was provisioned. Take a look at the following mandatory parameters:

Components

Description

Example (Berlin)

Example (London)

Datacenter

Select a data center from the drop-down that lists VDCs in the same location as the gateway.

Berlin VPN example

London VPN example

Connections

After selecting a data center, click Add LAN Connection to open an additional pop-up window to set the properties.

See Below

See Below

Enter the following in the Edit LAN Connection pop-up window:

Components

Description

Example (Berlin)

Example (London)

LAN

The ID of the LAN to connect to.

1

2

IPv4 CIDR

The LAN IPv4 address assigned to the subnet's gateway in CIDR notation.

192.168.1.5/24

192.168.2.5/24

IPv6 CIDR

The LAN IPv6 address assigned to the subnet's gateway in CIDR notation.

Not applicable

Not applicable

LAN connections

4. Click Save and wait for the gateway to complete provisioning. The process typically takes about 10-15 minutes, but further operations on the gateway are almost instantaneous. When provisioning completes, the gateway status shows Available.

3

Configure the VPN peers

Now that the VPN Gateway instances are provisioned, configure a peer on each gateway to permit the two sides to communicate with each other. Configure the peer to_lhr on wg-txl and the peer to_txl on wg-lhr.

1. Click Create Peers to begin configuring a new peer.

Configure a peer

Enter the following details to configure a peer:

Components

Description

Example (on wg-txl)

Example (on wg-lhr)

Peer Name

Specify a name for the peer. The name is not required to be unique and can be up to 255 characters long.

to_lhr

to_txl

Description

Enter more descriptive text for the peer, not exceeding 1024 characters.

Not applicable

Not applicable

Configure peer properties

Configure the endpoint so the gateway knows with which remote address the connection must be established. Set it to the public IPv4 address of the gateway in the other location.

Components

Description

Example (on wg-txl)

Example (on wg-lhr)

Endpoint host

The gateway public IPv4 address of the remote gateway.

203.0.113.20

203.0.113.10

Endpoint port

The endpoint port on which WireGuard listens for incoming encrypted VPN packets. The tutorial uses the default value 51820.

51820

51820

Configure endpoint

The peers section specifies which networks are permitted across the peer. Specify the LAN subnet of the remote site in CIDR notation, together with the public key of the remote gateway.

Components

Description

Example (on wg-txl)

Example (on wg-lhr)

Allowed IPs

Enter a comma separated list of subnets in CIDR notation that are permitted to send traffic to the given peer. It is the LAN subnet used on the remote site.

192.168.2.0/24

192.168.1.0/24

Public Key

The public key of the remote gateway, as generated earlier in this tutorial.

lmnoLMNO/89762=

defDEFhiH/98765=

Configure peer

2. Click Save to save the peer configuration. This operation typically completes within a few minutes at most. When the operation completes, the gateway status shows Available.

3. Repeat the steps on the wg-lhr gateway in London, using the values from the Example (on wg-lhr) column.

4

Configure routing on LAN hosts

You cannot automate adding routes to LAN hosts to route the required subnets over the VPN Gateway. In this section, you manually add the required routes on the LAN hosts in both VDCs.

1

Configure routing on Berlin LAN hosts

1. Establish a console session to the LAN hosts

The LAN hosts have no internet access, so the only way to reach them is the web console. Open a console session and run ping against the LAN address assigned to the VPN Gateway, 192.168.1.5:

Berlin LAN host pinging the gateway LAN address
2. Configure the VPN route

The LAN hosts must know where to route traffic destined for London. Add a route for the London subnet 192.168.2.0/24 through the Berlin gateway's LAN address 192.168.1.5:

Repeat this process for each LAN host in Berlin.

2

Configure routing on London LAN hosts

1. Establish a console session to the LAN hosts

Open a console session on a London LAN host and run ping against the LAN address assigned to the VPN Gateway, 192.168.2.5:

London LAN host pinging the gateway LAN address
2. Configure the VPN route

The LAN hosts must know where to route traffic destined for Berlin. Add a route for the Berlin subnet 192.168.1.0/24 through the London gateway's LAN address 192.168.2.5:

Repeat this process for each LAN host in London.

Note: Routes added with ip route add do not persist across a restart. To make the routes persistent, use the network configuration tool of your operating system. For examples that use Netplan on Ubuntu and NetworkManager on Rocky Linux and AlmaLinux, see Configure the Guest OS to Use the NAT Gateway.

5

Final result

You can now test connectivity across the VPN from either side. From a LAN host in Berlin, run ping against a LAN host in London (192.168.2.11). From a LAN host in London, run ping against a LAN host in Berlin (192.168.1.11).

On the Berlin LAN host berlin-lan-host-1, test connectivity to a London LAN host:

On the London LAN host london-lan-host-1, test connectivity to a Berlin LAN host:

Conclusion

You have successfully configured two managed WireGuard gateways connected to different VDCs and established a site-to-site VPN connection between them in IONOS CLOUD.

Next steps

Last updated

Was this helpful?