Create IPv6 addresses (based on IPv4) on a Plesk server

Share Button

This is a perl script that I wrote to add IPv6 addresses to a pre-existing Plesk server that is already up and running with IPv4 services.  The script is based on my own personal addressing scheme defined in:

IPv6 addressing scheme for existing IPv4 network

Basically the scheme is the IPv6 address is made up of:

{Your /32 assignment}:{Site ID}:{VLAN}:{IPv4 octet 1 in hex}:{IPv4 octet 2 in hex}:{IPv4 octet 3 in hex}:{IPv4 octet 4 in hex}

So that being said, this perl script will look at the pre-existing ‘exclusive’ IPv4 addresses on a Plesk 10+ server and will output the necessary commands to add equivalent IPv6 addresses to the server based on the above addressing scheme, then if everything looks fine, just copy and paste the commands and Plesk will add the IPv6 addresses:

# Define IPv6 /32 as "####:####"
$ipv6Assignment = "2001:db8";
# Define site ID as just an integer
$ipv6SiteID = "1";
# Define VLAN of server
$vlan = "500";
# Define primary network interface name; typically eth0 or em1
$iface = "eth0";
# Define IPv6 subnet mask; should very rarely be anything other than /64
$mask = "64";

@ipList = `/usr/local/psa/bin/ipmanage --ip_list`;

foreach $line (@ipList) {
 chomp $line;
 if ( $line =~ /^0     E    $iface:(\d+)\.(\d+)\.(\d+)\.(\d+)\// ) {
  $ipv6 = sprintf("$ipv6Assignment:$ipv6SiteID:$vlan:%X:%X:%X:%X",$1,$2,$3,$4);
  $ipv4 = "$1.$2.$3.$4";
  #
  # Doesn't matter of the IPv6 address already exists
  # because Plesk will just give an error about adding it.
  #
  print "/usr/local/psa/bin/ipmanage -c $ipv6 -type exclusive -mask $mask -interface $iface\n";
 }
}

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *