mammoth's Private IP Setup

Supports: CentOS 5.9/7 (64-bit), 6 (32-bit and 64-bit); Debian 7.0 (32-bit and 64-bit), 8 (64-bit); Ubuntu 12.04 LTS/14.04 LTS (32-bit and 64-bit)

Source Code

#!/bin/bash
 
privateip_debianlike() {
grep -q $VPS_PRIVATEIP /etc/network/interfaces && return
 
echo "Adding eth0:mammoth ($VPS_PRIVATEIP) to /etc/network/interfaces"
cat >> /etc/network/interfaces <<EOT
 
auto eth0:mammoth
iface eth0:mammoth inet static
address $VPS_PRIVATEIP
netmask 255.255.0.0
EOT
 
echo "Bringing up interface eth0:mammoth"
ifup eth0:mammoth
}
 
privateip_redhatlike() {
local networkfile=/etc/sysconfig/network-scripts/ifcfg-eth0\:mammoth
test -e $networkfile && return
 
echo "Adding eth0:mammoth ($VPS_PRIVATEIP) as $networkfile"
cat >> $networkfile <<EOT
DEVICE=eth0:mammoth
IPADDR=$VPS_PRIVATEIP
NETMASK=255.255.0.0
EOT
 
echo "Bringing up interface eth0:mammoth"
ifup eth0:mammoth
}
 
if test -z "$VPS_PRIVATEIP" ; then
  echo VPS_PRIVATEIP is not set, giving up
fi
 
# Run appropriate function for our distribution
test -e /etc/network/interfaces && privateip_debianlike
test -e /etc/sysconfig/network-scripts && privateip_redhatlike
Preload Preload Preload