Updating your Dedicated Linux server IP address to your new IP details.
This article applies to Linux Dedicated Servers.
To replace your current IP addresses with the new IP addresses that have been allocated to you the following has to be done:
- Add the IP addresses to your network interface
- Configure the DNS to work with the new IP addresses
- Update Apache to listen and serve pages from the new IP addresses
- List of default gateways based on primary IP network
These steps are broken up as follows:
Adding the new IP addresses to your network interface
Edit the file:
/etc/network/interfaces
which configures all the IP addresses your server responds to. You will see a section for each of your existing IP addresses, usually divided by blank lines. Each IP address will have an interface name associated with it. One IP address will be your server’s primary IP address; this will have an interface name that doesn’t have a colon in it, probably:
eth0
Each of the other IP addresses will have an interface name that is the primary interface’s name followed by a colon then another number, such as eth0:0 or eth0:1. (There will also be a section for the loopback interface, labelled lo; this section does not need any changes, so please leave it exactly as you found it.)
We want both your old and new IP addresses to work for a transitional period, as such we now want to add additional sections for your new IP addresses while keeping the old ones in place.
Create a section for a new primary interface: copy all the existing lines that define the existing primary interface. These should include a gateway line, and possibly a pre-up line too. In the new primary interface, change the IP address and gateway to the equivalent new addresses. In the old primary interface, delete any gateway and pre-up lines (but leave the IP address defined; this will allow both old and new IP addresses to work over the transition period).
For each additional IP address you have, create a new section for each IP, in each case copying the entire section from the previous IP then change the IP address to the equivalent new one.
Finally, the sections need to be renumbered so that the numbering is consistent. The new primary IP address needs to be the interface name without the colon-number suffix, such as eth0. Each of the other interfaces, including the old primary interface, need a unique colon-number, starting from: 0 and working up without any gaps:
eth0:0
eth0:1
eth0:2
and so on.
For example:
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 109.104.77.000
netmask 255.255.254.0
gateway 109.104.77.254
pre-up /usr/sbin/ethtool -s eth0 speed 10 duplex full autoneg off
auto eth0:1
iface eth0:1 inet static
address 62.44.83.163
netmask 255.255.254.0
auto eth0:0
iface eth0:0 inet static
address 109.104.77.000
netmask 255.255.254.0
auto eth0:2
iface eth0:2 inet static
address 62.44.83.000
netmask 255.255.254.0
Before saving the file, please double-check that you have one primary interface definition eth0, which is a new IP address and has a new gateway, that each of the other IP addresses (old and new) have their own definition, that the gateway line has been removed from the old primary IP address, and that each of the interfaces has a unique number.
Save the file, then run this command to restart your network, using the new IP addresses:
/etc/init.d/network/restart
Configure the DNS to work with the new IP addresses
Edit the file:
/usr/local/djbdns/service/tinydns/env/IP
and remove all its existing content, replacing it with the single line:
0.0.0.0
Do the same for the file:
/usr/local/djbdns/service/axfrdns/env/IP
Save both files, and run these commands:
svc -d /service/tinydns ; svc -u /service/tinydns
svc -d /service/axfrdns ; svc -u /service/axfrdns
Update Apache to listen and serve pages from the new IP addresses
Everywhere in your Apache config that mentions an old IP address needs updating to mention both the old and new IP addresses. Precisely how to do this depends on how you have configured Apache.
If you are running a chroot set-up then you may have two separate Apache instances, both of which will need updating. In the default installation there was an Apache instance running the control panel, configured by the files in the:
/etc/apache-ssl/
directory, and an Apache instance for your websites, configured by:
/usr/fs/etc/apache2/
IP addresses can be mentioned in two forms: Listen directives, and VirtualHost directives.
For each line which starts Listen followed by an IP address, duplicate the line, so that there are two identical Listen directives on adjacent lines. Change the IP address on one of them to the equivalent new IP address. After the IP address should be a colon and then a port number (a single integer, probably :80 or :443); leave this alone, so it is the same for both the current and new IP addresses.
There may also be some Listen directives which just mention a port number and no IP address. If so, leave these alone.
For each line which starts VirtualHost followed by an IP address and port number, add a space after the IP address and then add the equivalent new IP address then a colon then the same port number as the old IP address.
If the line already has multiple IP addresses, add a new IP address for each one, separating them with spaces. The line can be as long as needed, but make sure that there is no line-break character splitting the directive into multiple lines.
The end of the line, after all the IP addresses, must be a single >” character.
There may also be some Listen directives which don’t mention any IP address. If so, leave these alone.
In the default config, you will need to edit these files:
/etc/apache-ssl/httpd.conf — both Listen and VirtualHost
/usr/fs/etc/apache2/sites-available/default — VirtualHost
/usr/fs/etc/apache2/ports.conf — Listen
Restart each Apache instance. The non-chroot Apache can be restarted with this command:
/etc/init.d/apache-ssl stop
/etc/init.d/apache-ssl start
The chroot Apache is restarted with this command:
chroot /usr/fs /etc/init.d/apache2 stop
chroot /usr/fs /etc/init.d/apache2 start