Learn about Centmin Mod LEMP Stack today
Become a Member

Sysadmin How to add a IPv4 Failover Range to CentOS 7?

Discussion in 'System Administration' started by Oxide, Sep 13, 2016.

  1. Oxide

    Oxide Active Member

    534
    29
    28
    Mar 19, 2015
    Ratings:
    +59
    Local Time:
    7:11 PM
    Hello.

    How can I do this properly on my OVH? I own a IP Range. I added manually each one, by copying eth0 into eth0:1 etc.


    Code:
    DEVICE="eth0:7"
    BOOTPROTO=static
    IPADDR=1
    NETMASK=255.255.255.255
    ONBOOT=yes
    BROADCAST=1
    
    1 = is my ip, just removed it though
     
  2. eva2000

    eva2000 Administrator Staff Member

    54,860
    12,239
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,810
    Local Time:
    7:11 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    11:11 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Just to get it right :)

    Now i have:

    and i should create a second file there:

    and add inside:

    Code:
    DEVICE="eth0:1"
    BOOTPROTO=static
    IPADDR="secondiphere"
    NETMASK="255.255.255.255"
    BROADCAST="providers broadcast"
    ONBOOT=yes
    and just :

    and for a third ip repeat it and add a new file name ifcfg-eth0:2 and so on?

    After restart that will be up again or i must run again ifup eth0:1 ?

    Other than that i should change also the A record for the new ip?

    Can i use two A records with the two ip's that i would set?

    Thanks
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,860
    12,239
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,810
    Local Time:
    7:11 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    try and see, you can script it with a for sequence loop

    this one just echo/displays the output not create the files themselves nor does it insert contents of files, you can do that if you rewrite the for sequence loop yourself

    example IP range 192.168.2.2 to 192.168.2.10

    Code (Text):
    for i in {2..10}; do echo -e "\n/etc/sysconfig/network-scripts/ifcfg-eth0:${i}"; echo "
    DEVICE="eth0:$i"
    BOOTPROTO=static
    IPADDR="192.168.2.$i"
    NETMASK="255.255.255.255"
    BROADCAST="xxx.xxx.xxx.xxx"
    ONBOOT=yes";
    echo -e "\nifup eth0:${i}";
    done

    gives following display only output
    Code (Text):
    /etc/sysconfig/network-scripts/ifcfg-eth0:2
    
    DEVICE=eth0:2
    BOOTPROTO=static
    IPADDR=192.168.2.2
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:2
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:3
    
    DEVICE=eth0:3
    BOOTPROTO=static
    IPADDR=192.168.2.3
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:3
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:4
    
    DEVICE=eth0:4
    BOOTPROTO=static
    IPADDR=192.168.2.4
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:4
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:5
    
    DEVICE=eth0:5
    BOOTPROTO=static
    IPADDR=192.168.2.5
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:5
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:6
    
    DEVICE=eth0:6
    BOOTPROTO=static
    IPADDR=192.168.2.6
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:6
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:7
    
    DEVICE=eth0:7
    BOOTPROTO=static
    IPADDR=192.168.2.7
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:7
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:8
    
    DEVICE=eth0:8
    BOOTPROTO=static
    IPADDR=192.168.2.8
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:8
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:9
    
    DEVICE=eth0:9
    BOOTPROTO=static
    IPADDR=192.168.2.9
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:9
    
    /etc/sysconfig/network-scripts/ifcfg-eth0:10
    
    DEVICE=eth0:10
    BOOTPROTO=static
    IPADDR=192.168.2.10
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    
    ifup eth0:10
     
  5. eva2000

    eva2000 Administrator Staff Member

    54,860
    12,239
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,810
    Local Time:
    7:11 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    What you trying to accomplish ? I never used OVH failover IPs, if you have same A record for same dns record then you'd be doing dns round robin.
     
  6. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    11:11 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Great thanks :)
     
  7. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    11:11 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    If the ip fail like getting attacked to use another ip but if it is possible to be automated...

    If it is possible...
     
  8. eva2000

    eva2000 Administrator Staff Member

    54,860
    12,239
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,810
    Local Time:
    7:11 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Last edited: Sep 13, 2016
  9. SeaTea

    SeaTea Member

    49
    13
    8
    Feb 20, 2015
    the Netherlands
    Ratings:
    +28
    Local Time:
    10:11 AM
    Nginx:1.11
    MariaDB-10
    If you just need more ip-addresses you do not need to use separate alias files (eth0:x) in Centos-7. You could just use one ifcfg-eth0 file with more "IPADDR" lines with a number.

    Example:

    Code (Text):
    IPADDR0=123.45.67.89
    PREFIX0=24
    GATEWAY0=123.45.67.1
    IPADDR1=124.56.78.9
    PREFIX1=24
    GATEWAY1=124.56.78.1
    IPADDRx=.....
    PREFIXx=....
    GATEWAYx=....
    
     
  10. eva2000

    eva2000 Administrator Staff Member

    54,860
    12,239
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,810
    Local Time:
    7:11 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    indeed you can for CentOS 7 at least Linux Basics: Assign Multiple IP Addresses To Single Network Interface Card On CentOS 7 | Unixmen though trickier to automate like my above for sequence loop if you want to auto insert and create the files :)

    but if you just want to output the line syntax and manually copy and paste with same above example IP range 192.168.2.2 to 192.168.2.10
    Code (Text):
    for i in {2..10}; do echo "IPADDR${i}=\"192.168.2.${i}\""; done

    Output would be
    Code (Text):
    for i in {2..10}; do echo "IPADDR${i}=\"192.168.2.${i}\""; done
    
    IPADDR2="192.168.2.2"
    IPADDR3="192.168.2.3"
    IPADDR4="192.168.2.4"
    IPADDR5="192.168.2.5"
    IPADDR6="192.168.2.6"
    IPADDR7="192.168.2.7"
    IPADDR8="192.168.2.8"
    IPADDR9="192.168.2.9"
    IPADDR10="192.168.2.10"
    
     
  11. eva2000

    eva2000 Administrator Staff Member

    54,860
    12,239
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,810
    Local Time:
    7:11 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+