hetzneronline / community-content

Hetzner Online Community Project
https://community.hetzner.com
MIT License
292 stars 356 forks source link

How to set up NAT gateway for private Cloud Networks #947

Open paulrogov opened 3 days ago

paulrogov commented 3 days ago

Problem

  1. Persistent configuration for Ubuntu 24.04 client servers (CX22 instance) does not work.
  2. There is not DNS config for Ubuntu client servers specified at all.

Reason

A Hetzner Ubuntu 24.04 CX22 has network interface named enp7s0, not ens10 mentioned in the current version of the document.

Suggested Fix

Tested with Ubuntu 24.04 CX22

  1. Change to enp7s0 (can be double-checked with ifconfig output)
    $ nano /etc/systemd/network/10-enp7s0.network
    
    [Match]
    Name=enp7s0

[Network] DHCP=yes Gateway=10.0.0.1

```bash
$ reboot
  1. Add DNS config
    $ nano /etc/systemd/resolved.conf
    DNS=1.1.1.1 FallbackDNS=8.8.8.8 # Cloudflare and Google Fallback
    $ sudo systemctl restart systemd-resolved
paulrogov commented 3 days ago

Optionally, you can use this cloud-init config for persistent config on Ubuntu 24.04 client servers. This is in yaml format and should be specified when creating a new server instance (tested with Hetzner Ubuntu 24.04 CX22):

#cloud-config
write_files:
  - path: /etc/systemd/network/10-enp7s0.network
    content: |
      # Custom network configuration added by cloud-init
      [Match]
      Name=enp7s0

      [Network]
      DHCP=yes
      Gateway=10.0.0.1
    append: true

  - path: /etc/systemd/resolved.conf
    content: |
      # Custom network configuration added by cloud-init
      DNS=1.1.1.1 FallbackDNS=8.8.8.8 # Cloudflare and Google Fallback
    append: true

runcmd:
  - reboot