Steps for IP Replacement in Psychz Data Center



The main goal in writing this article is to help our customers take the right steps to replace their IPs . It will contain the following sections: 
1. The necessity for IP replacement
2. How to add new IP in Windows or Linux system
3. Test the new IP
4. Remove old IP from the server

1 The necessity for IP replacement

We've received an IP migration notification from our IP provider.  The upcoming IP migration will affect your services with us. We need to transition your current IP address to a new range to provide the best possible service and ensure our network's continued reliability and security.
We have 2-3 weeks to prepare and execute the IP replacement task. The old IP will be unavailable after the due date defined by the IP provider. Please add the IP as soon as possible to avoid any disruption to your business.  

2 How to add new IP in Windows or Linux system

There are many ways to add IP to a server, here is a quick way to do it for Windows and Linux systems.
  • In Windows system,  we will demonstrate adding new IP as primary with powershell script.
  • In Linux system,  we will demonstrate editing device file to add new IP address.

2.1 Add new IP in Windows System

  •     Start "Windows Powershell ISE"
            Enter ise in the Search box. And click Windows PowerShell ISE to open it.
  • Copy and Edit PowerShell script 
Please copy the following script and edit the $OldIPaddress,$NewIPaddress,$NewSubnetMask,$NewGateway value. The value information can be found in our notification email.  
===========Copy start=============
function Convert-IpAddressToMaskLength([string] $dottedIpAddressString)

  $result = 0;
  [IPAddress] $ip = $dottedIpAddressString;
  $octets = $ip.IPAddressToString.Split('.');
  foreach($octet in $octets)
    while(0 -ne $octet)
      $octet = ($octet -shl 1) -band [byte]::MaxValue
  return $result;
$OldIPaddress = "xx.xx.xx.xx"
$NewSubnetMask = "255.255.255.xx"
$interfaceName= Get-NetIPAddress | Where-Object { $_.IPAddress -eq $OldIPaddress } | Get-NetAdapter | Select-Object -ExpandProperty Name
New-NetIPAddress -InterfaceAlias $InterfaceName -IPAddress $NewIPAddress -PrefixLength (Convert-IpAddressToMaskLength $NewSubnetMask) -DefaultGateway $NewGateway
Set-NetIPAddress –IPAddress $OldIPaddress –SkipAsSource $True
==========  Copy  end ===================
  • Execute the PowerShell script
Please click on the green button in the red box to run the PowerShell script

2.2 Add new IP in the Linux system

For the Linux server, we can refer to the following steps to add the new IP. 
  • Prefix Number 24 = netmask
  • Prefix Number 25 = netmask
  • Prefix Number 26 = netmask

2.2.1 CentOS

  • Get the network device name via the command "ifconfig"
        In the following sample, 'eth0' is the network device name as the old IP was defined under the device.
  • Open network card configuration file
            Use the name of the network card in the red box to the name of the network card obtained in the above step. 
  Vi /etc/sysconfig/network-scripts/ifcfg-eth0
  •  Update the configuration file

PREFIX=<Old Prefix>

GATEWAY=<Old Gatway>
After Updated:
PREFIX=<New Prefix>
GATEWAY=<New Gatway>
PREFIX1=<Old Prefix>
GATEWAY1=<Old Gatway>
  • Save the configuration file and restart the network service
    systemctl restart network
    Here is a sample after the new IP added.

   2.2.2 Ubuntu20/18

  • Switch to root
Execute the  command "sudo -i" to switch to root user
sudo -i
  • Get correct configuration file name

        Find the network configuration file under /etc/netplan.   Please note that your network configuration file name may not be 01-netcfg. yaml
  • Modifying Network Configuration File /etc/netplan/01-netcfg.yaml 
    Vi /etc/netplan/01-netcfg.yaml    
  • Replace the New IP, New prefix, New Gateway in the following lines 
  version: 2
  renderer: networkd
        - Old IP/Old prefix
        - New IP/New prefix
          - ""
        - to:
          via: New gateway
Here is a sample to add new IP
After Modified
  • Make the configuration effective
netplan apply
ip a

2.2.3 Debian/Ubuntu14/Ubuntu16

modify file 
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0

auto eth0
iface eth0 inet static
iface eth0:0 inet static
Please note that eth0 fills in the new IP information. If you don’t want the netmask field, you can also fill in Please replace with your own new IP.
eth0:0 is used to retain the old IP information. In order to avoid conflicts, there is no need to fill in the gateway field here
Then restart the network through the systemctl restart networking command.
systemctl restart networking
detection command
ip a
If all goes well, you will see something similar to the image below, with eth0 and eth0:0 network cards appearing. And the result of ip a shows that there will be two ips under eth0.
If it is the same as the picture above, it means that the ip has been added successfully. Or you can connect to your server with both the new IP and the old IP, then you can end this reading 
If the second ip does not appear, or RTNETLINK answers: File exists error. then go to the next step
If the network card and IP do not appear, you can use the following command to restore the default configuration of eth0:0.
But this will cause the current session to be disconnected, and then please connect through IPMI or other consoles
ip addr flush dev eth0
Then restart the network
systemctl restart networking
ifup eth0
ifup eth0:0

3 Test the new IP

  • You can connect to your server using the new IP address via RDP/SSH. If you are able to establish a connection and perform remote operations successfully, it means the new IP is functioning properly.
  • After updating the IP address, you may need to restart certain services on your server, such as web services like Apache/Nginx, email services, DNS services, etc. This is necessary to ensure that the services start using the updated IP address.

4 Remove the old IP from the server

4.1 Remove old IP from the Windows system

Remove-NetIPAddress  -IPAddress "Old IP "  -DefaultGateway "old gateway"  -Confirm:$false

4.2 For Linux:

Please open the configuration file and then remove the lines that include old IP ,old prefix, and old gateway. And then restart the network.
Please test your application again after the IP is removed from your server.

Request help to add IP

Please send a message to with the following template if you need assistance to add a new IP.
Please add xx.xx.xx.xx for us as an IP Replacement task
We need your assistance to replace the old IP XXX with the new IP XXX.  You can access our server with xxxx as password.

Add Feedback