Feb 032010
 

There are 2 basic ways to modify a dns zone file, from the command line or from WHM via
Main >> DNS Functions >> Edit DNS Zone. What happens if you have five hundred domains on a server and want to migrate them all to a new shared IP address? Do you spend the next 4 days going through all of the zone files modifying them by hand or via the command line? I don’t think so…

We will be using cPanels swapip utility. The swapip utility allows you to update nameserver records by specifying 4 parameters in a command line interface. The swapip utility is located at
/usr/local/cpanel/bin/swapip

To use this utility for a single zone file, run the following command, specifying the appropriate parameters:

/usr/local/cpanel/bin/swapip $sourceip $targetip $ftpip $domains

Note: $sourceip, $targetip, $ftpip, and $domains are meant to symbolize the parameters you wish to enter.

Parameters

  1. * sourceip (string) — The old IP address.
    Example: 127.0.0.0
    * targetip (string) — The new IP address.
    Example: 208.77.188.166
    * ftpip (string) — The new FTP server’s IP address.
    Example: 208.77.188.166
    * domains (string) — One or more domains associated with the IP address being changed.
    Example: example.com

Examples:

Typing

/usr/local/cpanel/bin/swapip 127.0.0.0 208.77.188.166 208.77.188.166 example.com

would change the nameserver records for example.com on 127.0.0.0 to point HTTP and FTP requests to 208.77.188.166.

A successful swapip attempt should return you to the command line without displaying any messages. The output should resemble the following:

[email protected] [~]# /usr/local/cpanel/bin/swapip 127.0.0.0 208.77.188.166
208.77.188.166 example.com
[email protected] [~]#

An unsuccessful swapip attempt should result in an error message, the output of which will resemble the following:

[email protected] [~]# /usr/local/cpanel/bin/swapip 127.0.0.0 208.77.188.166 example.com
Error: domains missing
Usage: /usr/local/cpanel/bin/swapip sourceip destip ftpip domains...

Note: At this time the error message may not give an accurate assessment of the error that has occurred.

In order to change all dns zone file ip’s to another ip, we will use a simple one liner like so;

for each in `cat /etc/domainips | grep 72.16.217.108 | cut -d: -f2`; do /usr/local/cpanel/bin/swapip 72.16.217.108 72.16.217.109 $each done;

If you see any variation in this, please let me know.

 Posted by at 12:25 am

 Leave a Reply