Skip to content

How to setup static IP on CentOS

To set up static IP configuration on your VPS, you have to login into Fleio.
After connecting to Fleio you can use the console to run commands

  1. Login to SSH or console.

  2. Make sure you are sudo

  3. Edit file /etc/cloud/cloud.cfg.d/90-centos-networking.cfg and put in the following line.

    network: {config:disabled}
    

  4. Replace the content of /etc/sysconfig/network-scripts/ifcfg-eth0 with the following lines:

    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>  
    

  5. Restart network using the commands or reboot

    systemctl disable dhclient6.service  
    ifdown eth0  
    ifup eth0  
    

Configuration for more IPs in your instance.

If you want to configure multiple IPs in your instance, we need to create another cfg file.
In default configuration we have ifcfg-eth0 and we have to create file with a different name like ifcfg-eth0:1 using the following command:

vim /etc/sysconfig/network-scripts/ifcfg-eth0:1  

Note We can choose eth0:1, eth0:2, eth0:3, and so on, depending on how many IPs we want to configure.

BOOTPROTO=none  
DEFROUTE=yes  
DEVICE=eth0:1  
GATEWAY=<your IPv4 gateway>  
IPADDR=<your IPv4 address>  
PREFIX=<Your IPv4 prefix>  
IPV6ADDR=<your IPv6 address/64>  
IPV6INIT=yes  
IPV6_DEFAULTGW=<your IPv6 gateway>  
ONBOOT=yes  
STARTMODE=auto  
TYPE=Ethernet  
USERCTL=no  

After the configuration is done, you have to restart network:

ifdown [file configuration]   (ifdown eth0:1)  
ifup   [file configuration]   (ifup eth0:1)