Welcome to Centmin Mod Community
Become a Member

Sysadmin Give a domain a different IP?

Discussion in 'System Administration' started by saigoncrypto, May 28, 2020.

  1. saigoncrypto

    saigoncrypto New Member

    22
    2
    3
    Nov 14, 2017
    Ratings:
    +2
    Local Time:
    5:59 PM
    How would i go about this in CentMinMod? I am trying to add a floating IP from digitalocean.
    I am not sure if I understand how this works correctly... Do I have to add the IP to centos network? And can I change the IP in cloudflare to point to the new ip. Would this separate the domains if I do this? My main concern is that I want to split IPs incase on gets penalized by google.

    Correct me if I am doing this wrong...

    I am first adding a new file to /etc/sysconfig/network-scripts
    DEVICE=eth0:1
    HWADDR=[original hardware address]
    BOOTPRO=static
    IPADDR= [my digital oceanfloating ip]
    NETMASK=255.255.240.0
    NETMASK1=255.255.0.0
    ONBOOT=yes
    TYPE=Ethernet
     
  2. eva2000

    eva2000 Administrator Staff Member

    44,417
    10,144
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,692
    Local Time:
    10:59 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Adding additional IPs to a server involves 2 main tasks
    1. Adding and registering additional IPs to system network configuration
    2. Configuring Nginx to use those additional IPs

    Additional IPs System Configuration



    For CentOS to add additional IP address, you need to first be assigned additional IP addresses by your web host or order the additional IPs. For instance, OVH calls additional IPs failover IPs.

    OVH has a guide for adding and registering the additional IPs for CentOS and other Linux distributions to the system outlined at Network IP Aliasing | OVH Docs.

    There's a previous discussion for this with tips at Sysadmin - How to add a IPv4 Failover Range to CentOS 7? including scripting the format for each
    /etc/sysconfig/network-scripts/ifcfg-eth0:X file you need to create.

    Example for CentOS 6 & 7



    Example IP range 192.168.2.2 to 192.168.2.10 in SSH or shell script define IPLIST variable listing all additional IP addresses in single space separated list and define i variable with starting value of 0. Then a for ip in $IPLIST loop incrementing i variable by 1 for each IP listed in IPLIST
    Code (Text):
    IPLIST="192.168.2.2 192.168.2.3 192.168.2.4 192.168.2.5 192.168.2.6 192.168.2.7 192.168.2.8 192.168.2.9 192.168.2.10"
    i=0
    for ip in $IPLIST; do
      i=$(($i+1))
    echo -e "\n/etc/sysconfig/network-scripts/ifcfg-eth0:${i}"; echo "
    DEVICE="eth0:$i"
    BOOTPROTO=static
    IPADDR="$ip"
    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

    Where the first entry /etc/sysconfig/network-scripts/ifcfg-eth0:2 would contain
    Code (Text):
    DEVICE=eth0:2
    BOOTPROTO=static
    IPADDR=192.168.2.2
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    

    and command to start up the interface for initial first time for eth0:2 would be
    Code (Text):
    ifup eth0:2
    


    Example for CentOS 7 Only



    For CentOS 7 there's a 2nd method for adding additional IPs to your system Linux Basics: Assign Multiple IP Addresses To Single Network Interface Card On CentOS 7 | Unixmen. Instead of separate /etc/sysconfig/network-scripts/ifcfg-eth0:X files where X increments, you add additional IPs within the same /etc/sysconfig/network-scripts/ifcfg-eth0 existing file defined by variable IPADDRx where x increments from 1 to number of IP addresses you want to add. Your file might not be named eth0 as it depends on your CentOS 7 network device naming scheme which you can find out via command below to check which network device belongs to your existing public IP address for your server:
    Code (Text):
    ifconfig
    

    So if you existing /etc/sysconfig/network-scripts/ifcfg-eth0 file contain
    Code (Text):
    DEVICE=eth0
    BOOTPROTO=static
    IPADDR=192.168.2.1
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    

    adding additional example IPs above would add these additional entries
    Code (Text):
    IPADDR1="192.168.2.2"
    IPADDR2="192.168.2.3"
    IPADDR3="192.168.2.4"
    IPADDR4="192.168.2.5"
    IPADDR5="192.168.2.6"
    IPADDR6="192.168.2.7"
    IPADDR7="192.168.2.8"
    IPADDR8="192.168.2.9"
    IPADDR9="192.168.2.10"
    

    so /etc/sysconfig/network-scripts/ifcfg-eth0 file with additional IPs would contain
    Code (Text):
    DEVICE=eth0
    BOOTPROTO=static
    IPADDR0=192.168.2.1
    IPADDR1="192.168.2.2"
    IPADDR2="192.168.2.3"
    IPADDR3="192.168.2.4"
    IPADDR4="192.168.2.5"
    IPADDR5="192.168.2.6"
    IPADDR6="192.168.2.7"
    IPADDR7="192.168.2.8"
    IPADDR8="192.168.2.9"
    IPADDR9="192.168.2.10"
    NETMASK=255.255.255.255
    BROADCAST=xxx.xxx.xxx.xxx
    ONBOOT=yes
    

    again you can script for this IPLIST variable defining space separated list of additional IP addresses in a for ip in $IPLIST loop with starting i=0 variable that increments by a value of 1 for each IPLIST entry
    Code (Text):
    IPLIST="192.168.2.2 192.168.2.3 192.168.2.4 192.168.2.5 192.168.2.6 192.168.2.7 192.168.2.8 192.168.2.9 192.168.2.10"
    i=0
    for ip in $IPLIST; do
      i=$(($i+1))
      echo "IPADDR${i}=\"$ip\""
    done
    

    changing existing IPADDR line from
    Code (Text):
    IPADDR=192.168.2.1
    

    to
    Code (Text):
    IPADDR0=192.168.2.1
    

    Then restart your networking service
    Code (Text):
    service network restart
    

    check the additional IPs registered on your system via command
    Code (Text):
    ifconfig
    


    Configuring Nginx Additional IP Usage



    To configure Nginx additional IPs, you need to first do the above to add the additional IPs to the system's networking configuration and for the IPs to show up in ifconfig output and be pingable. Nginx can setup Vhosts to use either name based hosting (default) sharing the main IP address or IP based hosting where a Vhost uses a dedicated or different IP address for main IP address. This is controlled by Nginx listen directive How nginx processes a request

    Centmin Mod 123.09beta01 and higher have native support to configure Nginx vhost creation routines to use a separate second IP from the main server IP address via persistent config file /etc/centminmod/custom_config.inc set variable called SECOND_IP discussed and added at Beta Branch - update nginx vhost generator routines support second IP

    Support secondary dedicated IP configuration for centmin mod nginx vhost generator, so out of the box, new nginx vhosts generated will use the defined SECOND_IP=111.222.333.444 where the IP is a secondary IP addressed added to the server.

    You define SECOND_IP variable is centmin mod persistent config file outlined at Upgrade Centmin Mod - CentminMod.com LEMP Nginx web stack for CentOS you manually create the file at /etc/centminmod/custom_config.inc and add SECOND_IP=yoursecondary_IPaddress variable to it which will be registered with nginx vhost generator routine so that any new nginx vhosts created via centmin.sh menu option 2 or /usr/bin/nv or centmin.sh menu option 22, will have pre-defined SECOND_IP ip address set in the nginx vhost's listen directive.

    So in persistent config file you create or already created at /etc/centminmod/custom_config.inc set in it
    Code (Text):
    SECOND_IP=111.222.333.444
    


    So at centmin.sh menu option 2, 22 or nv command runs to create a fresh new Nginx vhost instead of server{} context's listen directive being listed as
    Code (Text):
    listen 80;
    

    with SECOND_IP set it will become
    Code (Text):
    listen 111.222.333.444:80;
    

    for HTTPS on port 443

    instead of
    Code (Text):
    listen 443;
    

    with SECOND_IP set it will become
    Code (Text):
    listen 111.222.333.444:443;
    

    where you defined SECOND_IP=111.222.333.444

    Thus allowing you to use a different server IP for new nginx vhosts generated automatically.

    Now if you want to use a different IP address from main server IP or the one defined in SECOND_IP variable, then right now you would need to manually edit your Nginx vhost config file's listen directive yourself defining the additional IP you added earlier and restart Nginx server afterwards
    Code (Text):
    service nginx restart
    

    or centmin mod command shortcut
    Code (Text):
    ngxrestart
    


    You can spin up a test VPS to try this without touching your live VPS ;)
     
  3. saigoncrypto

    saigoncrypto New Member

    22
    2
    3
    Nov 14, 2017
    Ratings:
    +2
    Local Time:
    5:59 PM
    Thank you! That was very informative :)