5.3.3. Activate additional IP address
To add an additional IP address to your VPS, you need to connect to the server via SSH or VNC, edit the network interface configuration file, and restart the network service. These steps vary depending on the distribution.
CentOS
- Go to the
/etc/sysconfig/network-scriptsdirectory:cd /etc/sysconfig/network-scripts/ - Copy the existing
ifcfg-eth0file and rename it toifcfg-eth0:0:cp ifcfg-eth0 ifcfg-eth0:0 - Open this file using any text editor you prefer:
vi ifcfg-eth0:0 - Delete the lines related to IPv6 (this is the line
# IPv6and the ones that follow it — they all contain IPv6 at the beginning). - Change the
DEVICEline by adding:0at the end:DEVICE=eth0:0 - And change the
IPADDRline to your new IP:IPADDR=185.25.111.111 - Then restart the service using the following command:
service network restart
ifconfig command, you'll see that an additional interface has appeared: eth:0.
Debian
- Open the
/etc/network/interfacesfile for editing:nano /etc/network/interfaces - At the end of the group of lines related to the
eth0 inetconfiguration, before the IPv6 address settings (eth0 inet6), add the following lines:up ip addr add 185.25.111.111/22 dev eth0 down ip addr add 185.25.111.111/22 dev eth0Instead of
185.25.111.111, you need to specify your new IP address, and instead of22, you need to specify the correct subnet mask. - Save the changes and restart the interface by running the following command:
- For Debian 6:
ifdown eth0 && ifup eth0 - For Debian 7:
ifdown --force eth0; ifup --force eth0
ip addr command. You should see lines like this:2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 10:36:3f:04:27:47 brd ff:ff:ff:ff:ff:ff
inet <old_IP>/22 brd 185.25.111.255 scope global eth0
inet <new_IP>/22 scope global secondary eth0
Ubuntu
sudo and enter your password.
- Generate a configuration file if one does not exist. Here's how to do it:
netplan generateTo check for existing files, do the following:
ls -l /etc/netplan/If the output shows
total 0then a file needs to be generated. - Check which interfaces already exist in the system. To do this, run the following command:
ifconfig -a - Open the configuration file for editing:
nano /etc/netplan/XXXXX.yamlImportant! Replace
XXXXXwith the correct name of an existing file. - In the
ethernetsection, specify the following lines:eth1: dhcp4: no dhcp6: no addresses: [XXX.XXX.XXX.XXX/YY, XXX.XXX.XXX.XXX/YY] gateway4: XXX.XXX.XXX.XXX nameservers: addresses: [XXX.XXX.XXX.XXX, XXX.XXX.XXX.XXX]This option will change the interface settings:
eth1— the interface name. You must specify the interface you want to configure.dhcp4anddhcp6— DHCP settings for IPv4 and IPv6. You must selectnobecause the IP address will be set manually.addresses— a sequence of IP addresses. ReplaceXXX.XXX.XXX.XXXwith the desired IP address, andYYwith the desired subnet mask.
Important! When specifying an IPv6 address, be sure to enclose it in quotation marks, for example «'2a05:410:0:9b5b::3/64'».gateway4— the default gateway for IPv4. ReplaceXXX.XXX.XXX.XXXwith the standard gateway.nameservers— name server settings.addresses— a sequence of IP addresses (theaddressesparameter in thenameserversblock specifies the IP addresses of the name servers).
- After making all changes and saving the file, run the following command to apply the new settings:
netplan apply
ifconfig command. You should see the eth1 interface.
- Open the
/etc/network/interfacesfile for editing:nano /etc/network/interfaces - Add the following lines to the end of this file:
auto eth0:0 iface eth0:0 inet static address 185.25.111.111 netmask 255.255.252.0Replace
185.25.111.111with your new IP address, and replace255.255.252.0with the subnet mask you specified above. - Save your changes and restart the interface:
/etc/init.d/networking restart
ifconfig command. You should see the eth0:0 interface.
Gentoo
- Open the file
/etc/conf.d/netfor editing:nano /etc/conf.d/net - The first line of this file will contain your current IP address. Add another line below it, specifying the new IP address, and then, after the slash, the same subnet mask as for the first address:
config_eth0="<прежний_IP>/22 <новый_IP>/22 - Save your changes by pressing
Ctrl-X, thenyto confirm saving the file, andEnter. - Restart the interface:
/etc/init.d/net.eth0 restart
ifconfig command. You should see the eth0:1 interface.
OpenSUSE
- Open the
/etc/sysconfig/network/ifcfg-eth0file:vim /etc/sysconfig/network/ifcfg-eth0 - Press the
ikey to enter edit mode. - Scroll to the very bottom of the file and add the following lines at the end:
IPADDR_2='185.25.111.111' NETMASK_2='255.255.252.0'Instead of
185.25.111.111, you need to enter your new IP address. Instead of255.255.252.0, you need to enter the value you specified above in theNETMASKline. - Restart the service using the following command:
service network restart
service network status command. You should see lines that look like this: network[13632]: eth0 IP address: <old_IP>
network[13632]: secondary eth0 IP address: <new_IP>
network[13632]: eth0 IP address: <IPv6>
network[13632]: eth0 is up
Fedora
- Open the
/etc/sysconfig/network/ifcfg-eth0file:vi /etc/sysconfig/network/ifcfg-eth0 - Press the
ikey to enter edit mode. - After the line
GATEWAY, add the following lines:IPADDR0=185.25.111.111 NETMASK0='255.255.252.0'Instead of
185.25.111.111, you need to enter your new IP address. Instead of255.255.252.0, you need to enter the value you specified above in theNETMASKline. - Restart the service using the following command:
service network restart
ip addr command. You should see lines like this:2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 10:36:3f:04:27:47 brd ff:ff:ff:ff:ff:ff
inet <old_IP>/22 brd 185.25.111.255 scope global eth0
inet <new_IP>/22 scope global secondary eth0
Windows
To add an additional address on this operating system, connect to it via RDP and right-click the network connection icon in the system tray. Select "Network and Sharing Center". In the "View your active networks" section, click the "Local Area Connection" link, and then click "Properties" in the window that opens. Now select the "Internet Protocol Version 4" entry and click "Properties". In the new window, click "Advanced". Now click the "Add" button and enter your new address and subnet mask. The subnet mask must be the same as that of the existing address.