Hetzner Cloud servers get their IP configuration from cloud-init from the (innacessible?) Hetzner data source. The configuration includes name resolution via Hetzners own resolvers.

Since Hetzners cloud-init networking configuration overrides /etc/resolv.conf with Hetzner nameservers and hinders resolution it has to be disabled.

We cannot copy the original configuration either, because, cloud-init renames the Ethernet interface to eth0 on boot.

So we have to:

  • Find out the interface name
  • Rewrite network configuration to use it
  • Disable cloud-init network configuration

The network interface currently (01/2019) is called ens3, the rewrite example uses this setting.

?shnippet:

sudo true

# Find out the interface name
sudo dmesg |grep eth0

IF=ens3
OIF=eth0

# Rewrite network configuration
cd /etc/network/interfaces.d || cat >/dev/null
sudo sed -n 'w50-hetzner-CX.cfg' <<EOF
# $USER $(date -uIs)

$(sed "/^#/d;s/$OIF/$IF/g" 50-cloud-init.cfg)
EOF

# Disable cloud-init network configuration
cd /etc/cloud/cloud.cfg.d || cat >/dev/null
sudo sed -n w/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg <<EOF
# $USER $(date -uIs)

network:
  config: disabled
EOF

# Reboot and check
sudo reboot

sudo true

IF=ens3
ip -4 addr | grep $IF

# Disable cloud-init script
cd /etc/network/interfaces.d || cat >/dev/null
sudo mv 50-cloud-init.cfg 50-cloud-init.cfg.disabled