To add additional IPs to Ubuntu / Debian
To use any additional IPs or subnets you have purchased you may need to configure additional interfaces for them to function. The process of adding interfaces is similar to all Linux distributions and users should follow this post taking note of the steps required for your specific OS.
Always take a backup of your network configuration settings before making any changes to the network configuration. If you make a mistake its possible you will lose the connection to your server and you will have to boot the server in rescue mode to revert any changes you have made.
This guide is specifically written for use with First2Host dedicated servers. If you follow this guide and you do not have a First2Host dedicated server you could break the connection to your server.
Log in as the root user and the enter the commands listed under your specific OS
CentOS / Red Hat / Fedora / Scientific Linux
Take a copy of the eth0 interface and rename it eth0:0
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
Now open up the new eth device you just created
cd /etc/sysconfig/network-scripts/ ; nano /etc/sysconfig/network-scripts/ifcfg-eth0:0
Remove everything from the file and replace it with the below. Add your additional IP where required
DEVICE="eth0:0"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR="ADDITIONAL_IP"
NETMASK="255.255.255.255"
BROADCAST="ADDITIONAL_IP "
Save and close the file then bring up the new eth device by running
ifup eth0:0
The IP should now be usable. If this does not bring up the IP reboot the server, repeat the process to add more IPs using UNIQUE devices like eth0:1, eth0:2
DEVICE="eth0:1"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR="ADDITIONAL_IP"
NETMASK="255.255.255.255"
BROADCAST="ADDITIONAL_IP "
Remember to bring each interface up after you create it
ifup eth0:1
Debian / Ubuntu
Taker a copy of the interfaces file in case of any errors
cp /etc/network/interfaces /etc/network/interfaces.backup
Next, open up the interfaces file using your favorite editor
nano /etc/network/interfaces
Server-IP-minus-last-octet = your server IP minus the last .X
You interface file will look like this
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address Server-IP
netmask 255.255.255.0
network Server-IP-minus-last-octet.0
broadcast 193.70.92.255
gateway Server-IP-minus-last-octet.254
iface eth0 inet6 static
address 2001:41d0:0303:085e::
netmask 64
dns-nameservers 2001:41d0:3:163::1
post-up sleep 5; /sbin/ip -family inet6 route add 2001:41d0:0303:08ff:ff:ff:ff:ff dev eth0
post-up sleep 5; /sbin/ip -family inet6 route add default via 2001:41d0:0303:08ff:ff:ff:ff:ff
pre-down /sbin/ip -family inet6 route del default via 2001:41d0:0303:08ff:ff:ff:ff:ff
pre-down /sbin/ip -family inet6 route del 2001:41d0:0303:08ff:ff:ff:ff:ff dev eth0
To add additional IPs just create secondary interfaces for each IP
auto eth0:1
iface eth0:1 inet static
address IP_HERE
netmask 255.255.255.255
broadcast IP_HERE
auto eth0:2
iface eth0:2 inet static
address IP_HERE
netmask 255.255.255.255
broadcast IP_HERE
So your interfaces file would look like this if you had two additional IPs routed to the server
auto eth0
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 193.70.92.255
gateway 192.168.2.254
iface eth0 inet6 static
address 2001:44d3:0403:085e::
netmask 64
dns-nameservers 2001:41d0:3:163::1
post-up sleep 5; /sbin/ip -family inet6 route add 2001:41d0:0303:08ff:ff:ff:ff:ff dev eth0
post-up sleep 5; /sbin/ip -family inet6 route add default via 2001:41d0:0303:08ff:ff:ff:ff:ff
pre-down /sbin/ip -family inet6 route del default via 2001:41d0:0303:08ff:ff:ff:ff:ff
pre-down /sbin/ip -family inet6 route del 2001:41d0:0303:08ff:ff:ff:ff:ff dev eth0
auto eth0:1
iface eth0:1 inet static
address 192.168.2.2
netmask 255.255.255.255
broadcast 192.168.2.2
auto eth0:2
iface eth0:2 inet static
address 192.168.2.3
netmask 255.255.255.255
broadcast 192.168.2.3
Save and close the file then reboot the server. The IPs should not be usable. Remember to use UNIQUE eth0:X interfaces. If after following this guide you can not ping your IPs please contact support who will advise further.
How was this article?
You might also like
More from Dedicated Servers
Enable Mod_RemoteIP – See Visitors Real IP address when using Cloudflare & Apache
If you are using Cloudflare on your Apache server you will always see Cloudflare IPs in your logs and not …
Fix 413 Request Entity Too Large Errors When Using NGINX
Just like Apache, NGINX imposes default limits on the size of files that can be uploaded. A 413 Request Entity …
Cloud-init Modules That Automate and Customize Deployments
Cloud-init is a popular way to automate deployments of instances in a cloud or none cloud environment. To save having …