System adjustments after server replacement with transfer of the drives

Last change on 2023-12-28 • Created on 2020-03-25 • ID: RO-CBCEE

Introduction

If your server needs to get replaced, you may need to adjust the network configuration in the installed system after the server exchange so that you can reach it again. Because of the widespread usage of the predictable naming scheme the name of the network interface might have changed and needs to be adjusted. Older linux systems use udev rules based on the physical MAC address to determine the numeration of the network interfaces.

On the right hand side in the table of contents you will find all the linux distributions which we support or have supported officially. This article only covers the default installations done via Robot or the installimage script.


Debian 9, Debian 10, Debian 11, Debian 12

Location of the network config

/etc/network/interfaces

Content of the network config

### Hetzner Online GmbH installimage

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback
iface lo inet6 loopback

auto enp0s31f6
iface enp0s31f6 inet static
  address 203.0.113.27
  netmask 255.255.255.248
  gateway 203.0.113.25
  # route 203.0.113.24/29 via 203.0.113.25
  up route add -net 203.0.113.24 netmask 255.255.255.248 gw 203.0.113.25 dev enp0s31f6

iface enp0s31f6 inet6 static
  address 2001:db8:5678::2
  netmask 64
  gateway fe80::1

Changes needed after server replacement

  • boot the server into Rescue System
  • check your network interface name with predict-check
  • mount your root partition to the folder /mnt Tutorial
  • open the network file with an editor nano /mnt/etc/network/interfaces
  • replace the current interface name with the new one in all occurences
  • save and close the file with Ctrl+x then y then hit enter
  • reboot

Debian 8

Location of the network config

/etc/network/interfaces

Content of the network config

root@Debian-811-jessie-64-minimal ~ # cat /etc/network/interfaces
### Hetzner Online GmbH installimage

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback
iface lo inet6 loopback

auto eth0
iface eth0 inet static
  address 203.0.113.27
  netmask 255.255.255.248
  gateway 203.0.113.25
  # route 203.0.113.24/29 via 203.0.113.25
  up route add -net 203.0.113.24 netmask 255.255.255.248 gw 203.0.113.25 dev eth0

iface eth0 inet6 static
  address 2001:db8:5678::2
  netmask 64
  gateway fe80::1

Changes needed after server replacement

Debian 8 does not use the predictable naming scheme by default. Instead network interfaces are named by udev according to their mac address.

  • boot the server into Rescue System
  • check your mac address with ifconfig eth0 | grep -o -E ..:..:..:..:..:..
  • mount your root partition to the folder /mnt Tutorial
  • open the udev file with an editor nano /mnt/etc/udev/rules.d/70-persistent-net.rules
  • replace the old mac address with the new one obtained earlier
  • save and close the file with Ctrl+x then y then hit enter
  • reboot

The udev rules should look similar to this:

root@Debian-811-jessie-64-minimal ~ # cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x15b7 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="39:15:42:47:34:44", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Alternatively you can just remove the udev rule file because it will get automatically generated after boot.


Ubuntu 18.04 LTS, 20.04 LTS and Ubuntu 22.04 LTS

Location of the network config

/etc/netplan/01-netcfg.yaml

Content of the network config

### Hetzner Online GmbH installimage
network:
  version: 2
  renderer: networkd
  ethernets:
    enp7s0:
      addresses:
        - 203.0.113.27/32
        - 2001:db8:5678::2/64
      routes:
        - on-link: true
          to: 0.0.0.0/0
          via: 203.0.113.25
        - to: default
          via: fe80::1
      nameservers:
        addresses:
          - 185.12.64.2
          - 2a01:4ff:ff00::add:1
          - 185.12.64.1
          - 2a01:4ff:ff00::add:2

Changes needed after server replacement

  • boot the server into Rescue System
  • check your network interface name with predict-check
  • mount your root partition to the folder /mnt Tutorial
  • open the network file with an editor nano /mnt/etc/netplan/01-netcfg.yaml
  • replace the current interface name with the new one in all occurences
  • save and close the file with Ctrl+x then y then hit enter
  • reboot

Ubuntu 16.04

Location of the network config

/etc/network/interfaces

Content of the network config

root@Ubuntu-1604-xenial-64-minimal ~ # cat /etc/network/interfaces
### Hetzner Online GmbH installimage

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback
iface lo inet6 loopback

auto eth0
iface eth0 inet static
  address 203.0.113.27
  netmask 255.255.255.248
  gateway 203.0.113.25
  # route 203.0.113.24/29 via 203.0.113.25
  up route add -net 203.0.113.24 netmask 255.255.255.248 gw 203.0.113.25 dev eth0

iface eth0 inet6 static
  address 2001:db8:5678::2
  netmask 64
  gateway fe80::1

Changes needed after server replacement

Ubuntu 16.04 does not use the predictable naming scheme by default. Instead network interfaces are named by udev according to their mac address.

  • boot the server into Rescue System
  • check your mac address with ifconfig eth0 | grep -o -E ..:..:..:..:..:..
  • mount your root partition to the folder /mnt Tutorial
  • open the udev file with an editor nano /mnt/etc/udev/rules.d/80-net-setup-link.rules
  • replace the old mac address with the new one obtained earlier
  • save and close the file with Ctrl+x then y then hit enter
  • reboot

The udev rules should look similar to this:

root@Ubuntu-1604-xenial-64-minimal ~ # cat /etc/udev/rules.d/80-net-setup-link.rules 
# device: eth0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="39:15:42:47:34:44", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

CentOS 7.9

Location of the network config

/etc/sysconfig/network-scripts/ifcfg-enp0s31f6 !! The name of the file depends on your (old) interface name !!

Content of the network config

### Hetzner Online GmbH installimage

DEVICE=enp0s31f6
ONBOOT=yes
BOOTPROTO=none
IPADDR=203.0.113.27
PREFIX=32
SCOPE="peer 203.0.113.25"
DEFROUTE=yes

IPV6INIT=yes
IPV6ADDR=2001:db8:5678::2/64
IPV6_DEFAULTGW=fe80::1
IPV6_DEFROUTE=yes
IPV6_DEFAULTDEV=enp0s31f6

Changes needed after server replacement

  • boot the server into Rescue System
  • check your network interface name with predict-check
  • mount your root partition to the folder /mnt Tutorial
  • open the network file with an editor nano /mnt/etc/sysconfig/network-scripts/ifcfg-enp0s31f6

!! The name of the file depends on your (old) interface name !!

  • replace the current interface name with the new one in all occurences
  • save and close the file with Ctrl+x then y then hit enter
  • rename the file to contain the new interface name

mv /mnt/etc/sysconfig/network-scripts/ifcfg-enp0s31f6 /mnt/etc/sysconfig/network-scripts/ifcfg-enp7s0 (replace with your interface name)

  • reboot

Alma Linux 8.7, Rocky Linux 8.7, CentOS Stream

Location of the network config

/etc/sysconfig/network-scripts/ifcfg-enp0s31f6 !! The name of the file depends on your (old) interface name !!

Content of the network config

[root@CentOS-85-64-minimal ~]# ls /etc/sysconfig/network-scripts/
ifcfg-enp0s31f6
mit dem Inhalt:
### Hetzner Online GmbH installimage

DEVICE=enp0s31f6
ONBOOT=yes
BOOTPROTO=none
IPADDR=203.0.113.27
PREFIX=32
GATEWAY=203.0.113.25
DEFROUTE=yes

IPV6INIT=yes
IPV6ADDR=2001:db8:5678::2/64
IPV6_DEFAULTGW=fe80::1
IPV6_DEFROUTE=yes

Changes needed after server replacement

  • boot the server into Rescue System
  • check your network interface name with predict-check
  • mount your root partition to the folder /mnt Tutorial
  • open the network file with an editor nano /mnt/etc/sysconfig/network-scripts/ifcfg-enp0s31f6

!! The name of the file depends on your (old) interface name !!

  • replace the current interface name with the new one in all occurences
  • save and close the file with Ctrl+x then y then hit enter
  • rename the file to contain the new interface name

mv /mnt/etc/sysconfig/network-scripts/ifcfg-enp0s31f6 /mnt/etc/sysconfig/network-scripts/ifcfg-enp7s0 (replace with your interface name)

  • reboot

Arch Linux

Location of the network config

/etc/systemd/network/10-enp0s31f6.network !! The name of the file depends on your (old) interface name !!

Content of the network config

[root@archlinux-latest-64-minimal ~]# cat /etc/systemd/network/10-enp0s31f6.network
### Hetzner Online GmbH installimage
[Match]
Name=enp0s31f6

[Network]
Address=2001:db8:5678::2/64
Gateway=203.0.113.25
Gateway=fe80::1

[Address]
Address=203.0.113.27
Peer=203.0.113.25/32

Changes needed after server replacement

  • boot the server into Rescue System
  • check your network interface name with predict-check
  • mount your root partition to the folder /mnt Tutorial
  • open the network file with an editor nano /mnt/etc/systemd/network/10-enp0s31f6.network

!! The name of the file depends on your (old) interface name !!

  • replace the current interface name with the new one in all occurences
  • save and close the file with Ctrl+x then y then hit enter
  • rename the file to contain the new interface name

mv /mnt/etc/systemd/network/10-enp0s31f6.network /mnt/etc/systemd/network/10-enp7s0.network (replace with your interface name)

  • reboot

VMware vSphere/ESXi

You can find helpful information in the following article about adjusting ESXi after a server replacement: VMware ESXi: Hardware change

Table of Contents