4.3.3. Activating an additional IP address
To add an additional IP address to the VPS, you need to connect to the server using SSH or VNC, edit the network interface configuration file and restart the network service. Different distributions perform these operations differently.
CentOS
- Go to the directory
/etc/sysconfig/network-scripts
:cd /etc/sysconfig/network-scripts/
- Copy the existing file
ifcfg-eth0
under the nameifcfg-eth0:0
:cp ifcfg-eth0 ifcfg-eth0:0
- Open this file using any convenient editor:
vi ifcfg-eth0:0
- Remove the lines related to IPv6 (this is the line
# IPv6
and those that follow — they all contain IPv6 at the beginning). - Change the line
DEVICE
by adding at the end:0
:DEVICE=eth0:0
- And change the line
IPADDR
by specifying your new IP:IPADDR=185.25.111.111
- Then restart the service with the command:
service network restart
ifconfig
you will see that you have an additional interface: eth:0
.
Debian
- Open the file for editing
/etc/network/interfaces
:nano /etc/network/interfaces
- At the end of a group of lines related to setting
eth0 inet
, 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 eth0
Instead
185.25.111.111
you need to specify your new IP, and instead of22
— the correct netmask. - Save the changes and restart the interface by running the appropriate command:
- For Debian 6:
ifdown eth0 && ifup eth0
- For Debian 7:
ifdown --force eth0; ifup --force eth0
ip addr
... You should display 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 after entering the password.
- Generate a config file if there is none. You can do it like this:
netplan generate
To check for existing files, you need to run:
ls -l /etc/netplan/
If the output contains
total 0
, then file generation is required. - Check which interfaces already exist on the system. To do this, run:
ifconfig -a
- Open the configuration file for editing:
nano /etc/netplan/XXXXX.yaml
Important! Instead
XXXXX
you need to specify the correct name of the existing file. - In chapter
ethernet
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 instruction will change the interface settings:
eth1
— interface name. You must specify the interface that you plan to configure.dhcp4
anddhcp6
— DHCP settings for IPv4 and IPv6. It is necessary to indicateno
, since the IP will be set manually.addresses
— a sequence of IP addresses. Instead ofXXX.XXX.XXX.XXX
you should specify the required IP, instead ofYY
— the desired mask.
Important! When specifying IPv6, be sure to wrap the address in quotes, for example "'2a05:410:0:9b5b::3/64'
".gateway4
— specifying the default gateway for IPv4. Instead ofXXX.XXX.XXX.XXX
you need to specify a standard gateway.nameservers
— nameserver settings.addresses
— sequence of IP addresses (indication in the blocknameservers
parameteraddresses
indicates the IP addresses of nameservers).
- After all the changes and saving the file, to accept the new settings, you need to do:
netplan apply
ifconfig
... You should have an interface eth1
.
- Open the file for editing
/etc/network/interfaces
:nano /etc/network/interfaces
- At the end of this file, add the following lines:
auto eth0:0 iface eth0:0 inet static address 185.25.111.111 netmask 255.255.252.0
Instead
185.25.111.111
specify your new IP, instead of255.255.252.0
— the network mask that you have specified above. - Save changes and restart the interface:
/etc/init.d/networking restart
ifconfig
... You should have an interface eth0:0
.
Gentoo
- Open the file for editing
/etc/conf.d/net
:nano /etc/conf.d/net
- On the first line of this file, you will have your current IP address. Insert another line after it, indicating the new IP, and then after the slash — the same netmask as for the first address:
config_eth0="<old_IP> / 22 <new_IP>/22
- Save changes by clicking
Ctrl-X
, and theny
to confirm the file has been written, andEnter
. - Restart the interface:
/etc/init.d/net.eth0 restart
ifconfig
... You should have an interface eth0:1
.
OpenSUSE
- Open the file
/etc/sysconfig/network/ifcfg-eth0
:vim /etc/sysconfig/network/ifcfg-eth0
- Press the key
i
to enter edit mode. - Scroll down to the 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
185.25.111.111
you need to enter your new IP. Instead of255.255.252.0
— you need to specify the value that you have indicated above in the lineNETMASK
. - Restart the service with the command:
service network restart
service network status
... You should have lines 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 file
/etc/sysconfig/network/ifcfg-eth0
:vi /etc/sysconfig/network/ifcfg-eth0
- Press the key
i
to enter edit mode. - After the line
GATEWAY
add the following lines:IPADDR0=185.25.111.111 NETMASK0=255.255.252.0
Instead
185.25.111.111
you need to enter your new IP. Instead of255.255.252.0
— you need to specify the value that you have indicated above in the lineNETMASK.
- Restart the service with the command:
service network restart
ip addr
... You should display 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
ISPmanager
Adding an address through ISPmanager is much easier — you need to go to this control panel, open the section in the left column "Server Tuning → List of IP addresses" and at the top right click the button "Create".
Windows
To add an additional address in this operating system, connect to it via RDP and in the system tray, right-click on the network connection icon. Select item "Network and Sharing Center"... In chapter "View active networks" click the link "LAN connection", and in the window that opens, click "Properties"... Now select the line "Internet Protocol Version 4" and press "Properties"... In the new window, click "More"... Now click on the button "Add" and enter your new address and netmask. You must specify the netmask the same as for the existing address.