loading

Adding a New Client Server to a Private Cloud Network via cloud-config

Updated at
16/12/2023
Views
1328

Introduction: This tutorial explains how to add a new client server to a private cloud network with a self-hosted gateway. At server creation, we will use a cloud-config script which adds a new route to the server so that all outgoing traffic is sent to the self-hosted gateway (10.0.0.1). The self-hosted gateway then forwards this traffic to your self-hosted gateway. You don't need a public interface (no public IP address) or configure any static routes to your self-hosted gateway. If your gateway has a DNS server, it will be used by your new server.

Prerequisites:

  • Self-hosted gateway in your private Cloud Network

Example Terminology:

  • Private Network: 10.1.0.0/24
  • Self-hosted gateway: 10.1.0.1
  • DNS nameservers: 185.12.64.3 and 185.12.64.4

Step 1 - Prepare "netplan" Configuration

We want cloud-config to create a file (/etc/netplan/51-netcfg.yaml) to set a default route.

Create or edit the netplan configuration file using your preferred text editor:

network: version: 2 ethernets: ens10: dhcp4: true routes: - to: 0.0.0.0/0 via: 10.1.0.1

In this configuration:

  • ens10 is the interface name of your private network.
  • We need to send all outgoing traffic to the self-hosted gateway (10.1.0.1).

Step 2 - Prepare "resolved" Configuration

In this example, we are using alternate DNS servers, but you can also use other DNS servers. Change the /etc/systemd/resolved.conf file:

Edit the /etc/systemd/resolved.conf file:

[Resolve] DNS=185.12.64.3 185.12.64.4

Step 3 - Build the Cloud-Config Script

Now we need to combine both configurations from the first two steps into one cloud-config script. After the two files are written, the cloud-config script will reboot the server.

Create a cloud-config script, for example, cloud-config.yaml, and add the following content:

#cloud-config write_files: - path: /etc/netplan/51-netcfg.yaml permissions: '0644' content: | network: version: 2 ethernets: ens10: dhcp4: true routes: - to: 0.0.0.0/0 via: 10.1.0.1 - path: /etc/systemd/resolved.conf content: | [Resolve] DNS=185.12.64.3 185.12.64.4 runcmd: - reboot

This script includes both the netplan and resolved configurations. It will write these configurations and then reboot the server.

Step 4 - Create a New Server

Open the cloud hosting provider's console and create a new Ubuntu 22.04 server. Add the server to your private network only, and ensure that there are no public interfaces.

Use the cloud-config script created in "Step 3". Make any necessary changes to fit your environment and paste it into the "Cloud config" configuration text box during the server creation process. Create your server and allow some time for it to reboot.

Step 5 - Verify Your Configuration

If you have a VPN connection to your self-hosted gateway, you should be able to SSH into the created server.

If not, you can use the VNC console in the cloud hosting provider's user interface.

Verify DNS Server:

resolvectl status

You should see your configured DNS server.

Verify Default Route:

ip route

You should see a default route:

default via 10.1.0.1 dev ens10 proto static onlink

Conclusion: You have successfully configured a new server with cloud-config to use the self-hosted gateway as a default route for outgoing traffic and to use your own DNS servers. This setup allows your server to connect to the private network through the self-hosted gateway without the need for a public interface or static routes.

YottaSrc footer

why choose us?

Better Pricing, Fast SSD Storage and Real 24/7
Technical Support.

control panel icon
cPanel

Managing Your Site Through CPanel With The Latest Version

security icon
FAST, RELIABLE & SECURE

99.8% Uptime Guarantee.
So Focus On Your Work!

support icon
24/7/365 Support

Day or night, rain or shine,
our team is here for you!

cloud backup icon
Daily Backup

Daily & Weekly Backup.
Your Files Are Safe!