Back to Cloud VPS Documentation

    Static IP Configuration

    Disable cloud-init and DHCP to configure static IP addresses on your instance.

    Important Note

    If your instance has both a static IP and a floating IP, the static IP should be configured statically instead of using DHCP. This ensures proper routing and prevents connectivity issues.

    Overview

    The cloud images that we provide use cloud-init and DHCP to configure your instance network interfaces. There may be a situation where you want to disable cloud-init and/or DHCP and set your IP addresses statically. This can be accomplished a variety of ways. Feel free to use the configuration examples below as desired.

    Example Netplan Configuration (Debian/Ubuntu)

    1

    Log into your server

    Connect to your instance via SSH.

    2

    Get root access

    sudo -i
    3

    Disable cloud-init network configuration

    Create a new cloud-init configuration file /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with contents:

    network: {config: disabled}
    4

    Edit Netplan configuration

    Edit /etc/netplan/50-cloud-init.yaml. Remove the dhcp4 and dhcp6 lines and replace with:

    addresses:
      - <your IPv4 address>/24
      - "<your IPv6 address>/64"
    nameservers:
      addresses: [8.8.8.8, 8.8.4.4, 2001:4860:4860::8888, 2001:4860:4860::8844]
    gateway4: <your IPv4 gateway>
    gateway6: "<your IPv6 gateway>"
    5

    Apply your changes

    Use netplan try to verify first, then apply:

    netplan apply
    6

    Verify configuration persists

    Reboot to confirm cloud-init no longer configures networking (check for no new netplan file changes).

    Note: Other example configurations can be found on the Netplan website. DHCP (4 and 6) can be combined with static address configuration as well.

    Example Interfaces Configuration (Debian/Ubuntu)

    1

    Log into your server

    Connect to your instance via SSH.

    2

    Disable cloud-init network configuration

    Create a new cloud-init configuration file /etc/cloud/cloud.cfg.d/95-debian-network-config.cfg with contents:

    network: {config: disabled}
    3

    Comment out cloud-init interface config

    Edit /etc/network/interfaces.d/50-cloud-init.cfg and comment all lines related to eth0 (or any interface you want to statically configure).

    4

    Configure static IPv4

    Edit /etc/network/interfaces. Replace iface eth0 inet dhcp with:

    iface eth0 inet static
        address <your IPv4 address>/24
        gateway <your IPv4 gateway>
    5

    Configure static IPv6 (optional)

    You can add IPv6 the same way:

    iface eth0 inet6 static
        address <your IPv6 address>/64
        gateway <your IPv6 gateway>
    6

    Apply changes

    Save and close the file. Then run:

    ifdown eth0; ifup eth0

    Or simply reboot the server.

    Example Sysconfig Configuration (RHEL: CentOS, AlmaLinux, RockyLinux)

    1

    Log into your server

    Connect to your instance via SSH.

    2

    Disable cloud-init network configuration

    Replace the contents of /etc/cloud/cloud.cfg.d/90-centos-networking.cfg with:

    network: {config: disabled}
    3

    Configure network interface

    Replace the contents of /etc/sysconfig/network-scripts/ifcfg-eth0 with:

    BOOTPROTO=static
    DEVICE=eth0
    ONBOOT=yes
    TYPE=Ethernet
    IPADDR=<your IPv4 address>
    PREFIX=24
    GATEWAY=<your IPv4 gateway>
    IPV6ADDR=<your IPv6 address>/64
    IPV6_DEFAULTGW=<your IPv6 gateway>
    4

    Apply changes

    Run the following commands to apply the changes:

    systemctl disable dhclient6.service
    ifdown eth0; ifup eth0

    Or simply reboot the server.