Valid for Dedicated Servers, Server Power Deals, and Value Dedicated Servers, which are managed in the IONOS account.

This article explains how to change the IP address of a dedicated server, or add an additional IP address.

By default, the Dedicated Server are configured for automatic network configuration via DHCP. The server is always assigned the IP address first created in the contract. If you want to change the server address or assign one of the additional addresses to it, a static IP configuration is required.

Notes

  • For network security reasons, all servers are configured with a /32 network (netmask 255.255.255.255) and can therefore only reach your gateway and locally configured IP addresses directly. In order to be able to communicate with other servers in the network segment, all other packets must therefore be routed via the standard gateway. This requires a host route to the gateway.

  • You must be logged into the server as the root user, or as a user with administrative privileges.

Debian/Ubuntu

  • Determine the name of the network interface. To do this, enter the following command:

    [user1@localhost ~]# ip addr

  • To display the default gateway of the active network interface, enter the following commands:

    IPv4:

    [user1@localhost ~]# ip route show | grep 'default'

    IPv6:

    [user1@localhost ~]# ip -6 route show | grep 'default'

  • Note the IP addresses of the gateways. These are listed directly after the default via part. Example:

    [user1@localhost ~]# ip route show | grep 'default'
    default via 10.255.255.1 dev eth0 proto dhcp src 217.160.94.36 metric 100

  • Create a backup of the /etc/network/interfaces file. To do this, enter the following command:

    [user1@localhost ~]# sudo cp /etc/network/interfaces /etc/network/interfaces.bak

  • Open the file /etc/network/interfaces with the vi editor.

    [user1@localhost ~]# sudo vi /etc/network/interfaces

Note

  • The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press [ESC]. If you use command mode, your keyboard input is interpreted as a command.

  • To exit vi and save the file, enter the command :wq and then press Enter.

  • Customize your configuration file /etc/network/interfaces. Replace the existing entries with the information below.

    # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
    # Generated by debian-installer.
    # The loopback interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug INTERFACE-DEVICE

    iface INTERFACE-DEVICE inet static
       address MAIN-IPv4-ADDRESS/32
       gateway GATEWAY-ADDRESS
       up route add -net GATEWAY-ADDRESS netmask 255.255.255.255 dev INTERFACE-DEVICE

    iface INTERFACE-DEVICE inet6 static
       address MAIN-IPv6-ADDRESS/64
       gateway fe80::1

    Example:

    # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
    # Generated by debian-installer.
    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug eth0

    iface eth0 inet static
       address 82.165.103.128/32
       gateway 10.255.255.1
       up route add -net 10.255.255.1 netmask 255.255.255.255 dev eth0

    iface eth0 inet6 static
       address 2001:8d8:1800:334::1/64
       gateway fe80::1

  • Replace the INTERFACE-DEVICE placeholder in all places with the interface device you have determined. Then enter the main IPv4 address and the main IPv6 address.
  • Replace the placeholder GATEWAY-ADDRESS with the gateway address you have determined.
  • To configure the additional IPv4 address(es), add the following entry(s) below the entry for the main IPv4 address:

    iface INTERFACE-DEVICE inet static
       address Additional-IPv4-address-1
    iface INTERFACE-DEVICE inet static
       address Additional-IPv4-address-2

  • Replace the Additional-IPv4-address placeholders with the desired additional IPv4 address.
  • Replace the INTERFACE-DEVICE placeholder with the interface device you have determined.
  • To configure additional IPv6 addresses, add the following entry or entries below the entry for the main IPv6 address:

    iface INTERFACE-DEVICE inet6 static
       address Additional-IPv6-address-1
       gateway fe80::1
    iface INTERFACE-DEVICE inet6 static
       address Additional-IPv6-address-2
       gateway fe80::1

  • replace the Additional-IPv6-address part with the desired additional IPv6 address.
  • Replace the placeholder INTERFACE-DEVICE with the interface device you have determined.

    The following example shows a complete entry that is used to configure the main IPv4 and the main IPv6 address as well as an additional IPv4 and an additional IPv6 address.

    source /etc/network/interfaces.d/*

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug eth0

    iface eth0 inet static
       address 82.165.103.128/32
       gateway 10.255.255.1
       up route add -net 10.255.255.1 netmask 255.255.255.255 dev eth0

    iface eth0 inet static
       address 212.227.193.228/32

    iface eth0 inet6 static
       address 2001:8d8:1800:334::1/64
       gateway fe80::1

    iface eth0 inet6 static
       address 2001:8d8:1800:334::2/64
       gateway fe80::1

  • To exit vi and save the file, enter the command :wq and then press Enter.
  • To restart the server, enter the following command:

    [user1@localhost ~]# sudo systemctl reboot

  • To check whether the additional IP address has been configured correctly, enter the following command:

    [user1@localhost ~]# ip addr

CentOS

Changing the IP address of the server

  • Create a backup of the file /etc/sysconfig/network-scripts/ifcfg-eth0. To do this, enter the following command:

    [user1@localhost ~]# sudo cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak

  • Open the file /etc/sysconfig/network-scripts/ifcfg-eth0 with the vi editor.

    [user1@localhost ~]# sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

Notes

  • The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press [ESC]. If you use command mode, your keyboard input is interpreted as a command.

  • To exit vi and save the file, enter the command :wq and then press Enter.

  • Change this for the static IP configuration as follows and replace the placeholder<MAIN IPv4 ADDRESS> with your IP address.

    DEVICE=eth0
    BOOTPROTO=static
    NM_CONTROLLED="yes"
    ONBOOT=yes
    IPADDR0=<MAIN IPv4 ADDRESS>
    NETMASK=255.255.255.255

  • Now you need to configure the necessary route. To do this, create a configuration file /etc/sysconfig/network-scripts/route-eth0:

    [user1@localhost ~]# sudo vi /etc/sysconfig/network-scripts/route-eth0

  • Next, add the following content, and save the file:

    ADDRESS0=10.255.255.1
    NETMASK0=255.255.255.255
    ADDRESS1=0.0.0.0
    NETMASK1=0.0.0.0
    GATEWAY1=10.255.255.1

  • To restart the network, enter the following command:

    [user1@localhost ~]# sudo /sbin/service network restart

Add another IP address
  • Ensure that the main IPv4 address of the server is configured as a static IP address as described above.

  • Open the file /etc/sysconfig/network-scripts/ifcfg-eth0 with the vi editor.

    [user1@localhost ~]# sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

Notes

  • The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press [ESC]. If you use command mode, your keyboard input is interpreted as a command.

  • To exit vi and save the file, enter the command :wq and then press Enter.

  • Make sure that the main IP address is entered in the following format:

    IPADDR0=<MAIN IP address>

  • To configure the additional IPv4 address(es), add the following entry(s) and replace the placeholders:

    IPADDR1=<additional IPv4 address>
    PREFIX1=32
    IPADDR2=<additional IPv4 address>
    PREFIX2=32
    IPADDRN=<additional IPv4 address>
    PREFIXN=32

  • To restart the server, enter the following command:

    [user1@localhost ~]# sudo systemctl reboot

  • To check whether the additional IP address has been configured correctly, enter the following command:

    [user1@localhost ~]# ip addr

SUSE 13.x

Changing the IP address of the server

  • Create a backup of the file /etc/sysconfig/network-scripts/ifcfg-eth0. To do this, enter the following command:

    [user1@localhost ~]# sudo cp /etc/sysconfig/network/ifcfg-eth0 /etc/sysconfig/network/ifcfg-eth0.bak

  • Open the file /etc/sysconfig/network/ifcfg-eth0 with the vi editor.

    [user1@localhost ~]# sudo vi /etc/sysconfig/network/ifcfg-eth0

Notes

  • The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press [ESC]. If you use command mode, your keyboard input is interpreted as a command.

  • To exit vi and save the file, enter the command :wq and then press Enter.

  • To change the MAIN IPv4 address of the server, you must configure it as a static IP address. To do this, change the default values for BOOTPROTO, IPADDR and NETMASK as follows:

    BOOTPROTO='static'
    IPADDR=<MAIN IPv4 ADDRESS>
    NETMASK=255.255.255.255

  • Create the /etc/sysconfig/network/routes file required for manual routing:

    [user1@localhost ~]# sudo vi /etc/sysconfig/network/routes

  • Add the following code there, and save:

    10.255.255.1 0.0.0.0 255.255.255.255 eth0
    default 10.255.255.1

  • To restart the network, enter the following command:

    [user1@localhost ~]# sudo /sbin/service network restart

Add another IP address

  • Ensure that the main IP address of the server is configured as a static IP address as described above.

  • To add another IP address, enter the information in the file /etc/sysconfig/network/ifcfg-eth0:

    IPADDR1='ADDITIONAL IPv4 ADDRESS'
       NETMASK1='255.255.255.0'

    Example:

    IPADDR1='82.165.197.41'
       NETMASK1='255.255.255.0'

  • To restart the network, enter the following command:

    [user1@localhost ~]# sudo /sbin/service network restart

  • To check whether the additional IP address has been configured correctly, enter the following command:

    [user1@localhost ~]# ip addr