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

Configure the Guest OS to Use the NAT Gateway

After you provision a NAT gateway and its Source NAT (SNAT) rules, each Virtual Machine (VM) behind the gateway must be configured to route outbound traffic through it. IONOS CLOUD does not inject a default route or DNS servers into the guest operating system (OS), so you must configure the network settings manually within each VM. This page covers guest OS configuration for Linux server, how to access VMs behind the gateway, and troubleshooting.

Prerequisites:

  • A provisioned NAT gateway with at least one SNAT rule. If you have not set one up yet, see Configure a NAT Gateway.

  • A VM attached to the private LAN connected to the NAT gateway.

  • Secure Shell (SSH) access to the VM (through a bastion host) or access using the Data Center Designer (DCD) Remote Console.

  • sudo or administrator rights within the VM.

Before you start, note the following values from your setup:

Value

Source

NAT gateway LAN IP address (the private IP address of the NAT gateway on the LAN)

Log in to the DCD > NAT Gateway > Gateway IPs tab. For more information, see Configure a NAT Gateway.

VM private IP address and interface name (for example, ens6, eth0, or Ethernet)

Within the VM: ip -brief addr (Linux)

In the following examples, replace the placeholders with your own values:

Placeholder

Value

10.7.222.225

The NAT gateway LAN IP address

10.7.222.11/24

The VM private address

ens6

The VM interface name

Linux

Quick setup

The following commands take effect immediately but are not persistent across restarts. Use them to validate the setup first, then persist the configuration using the appropriate method for your distribution.

To confirm the NAT gateway is working, see Verify the configuration. If all three checks pass, persist the configuration using the method for your distribution: Netplan for Ubuntu 22.04 and later, or NetworkManager for RHEL-based distributions such as Rocky Linux and AlmaLinux.

  1. Check the interface ID used by the existing Netplan configuration:

Use the same ID (for example, ens6) in the next step. If the IDs differ, Netplan treats them as two definitions of the same Network Interface Controller (NIC) and they can conflict.

  1. Create a drop-in file that adds only the default route and DNS servers. The VM keeps its DHCP-assigned address.

  1. Apply the configuration:

netplan try rolls back automatically after 120 seconds unless you confirm, so you cannot lock yourself out over SSH. Press Enter to keep the change.

Note: On some cloud images, /etc/resolv.conf is a stub managed by systemd-resolved. After netplan try, systemd-resolved picks up the nameservers: block from the YAML and updates the stub. If DNS lookups fail immediately after applying, wait a few seconds and retry. If the issue persists, run resolvectl status to confirm that the configured nameservers appear on the correct interface.

To confirm the NAT gateway is working, see Verify the configuration.

  1. Find the active connection name:

  1. Apply the network configuration. Replace <connection-name> with the connection name from step 1:

To confirm the NAT gateway is working, see Verify the configuration.

Verify the configuration

Run the following commands on the VM to confirm that the NAT gateway is being used for outbound traffic.

Access VMs behind the NAT gateway

The NAT gateway is outbound-only. It does not accept unsolicited inbound connections. To reach a VM behind the NAT gateway for SSH or Remote Desktop Protocol (RDP) access, you must go through a bastion host. A bastion host is a second VM attached to the same LAN with its own public IP address and a firewall rule permitting the required inbound protocol.

From your workstation, open one SSH session that hops through the bastion to the target VM in a single command:

To persist this configuration, add the following block to ~/.ssh/config:

After saving the file, connect with:

Your SSH private key remains on your workstation. The bastion only relays the encrypted TCP connection.

DCD Remote Console

If SSH is unavailable, for example before the guest OS has been configured, use the built-in Remote Console in the DCD to log in with the credentials set at VM creation. To reset a lost password, stop the VM and use the Reset Password action.

Troubleshooting

Symptom

Likely cause and fix

ip route shows only the on-link /24 subnet with no default route

The guest OS is not configured. Follow the steps mentioned above to configure your OS.

curl -4 ifconfig.me returns nothing or times out

The default route is missing, or the SNAT rule Source Subnet does not include this VM IP address. In the DCD, open the NAT Gateway element > NAT Rules tab, and confirm that the Source Subnet covers this VM's private IP address.

curl -4 ifconfig.me returns a public IP address that is not the NAT gateway IP address

The VM has its own public IP address taking priority over the NAT route. Detach the public IP address, or lower its route metric.

Numeric IP address requests work but DNS lookups fail

/etc/resolv.conf is empty or missing nameservers. Repopulate it using the quick setup printf command.

DNS worked, then broke after sudo netplan try

systemd-resolved reset the resolv.conf stub. Pin resolvers through the Netplan nameservers: block, or overwrite /etc/resolv.conf directly.

A ping from the bastion to the target VM succeeds, but SSH fails

The Cloud Firewall on the target VM NIC is missing an inbound rule for TCP/22. Add one in the DCD.

SSH from the bastion to the target returns Permission denied (publickey)

The bastion does not hold the SSH private key for the target VM. Use ssh -J from your workstation, or forward the SSH agent with ssh -A.

Remote Console prompts for a password you did not set

Stop the VM in the DCD and use Reset Password to generate a new one.

Next steps

Last updated

Was this helpful?