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.

  1. Go to the directory /etc/sysconfig/network-scripts:
    cd /etc/sysconfig/network-scripts/
  2. Copy the existing file ifcfg-eth0 under the name ifcfg-eth0:0:
    cp ifcfg-eth0 ifcfg-eth0:0
  3. Open this file using any convenient editor:
    vi ifcfg-eth0:0
  4. Remove the lines related to IPv6 (this is the line # IPv6 and those that follow — they all contain IPv6 at the beginning).
  5. Change the line DEVICEby adding at the end :0:
    DEVICE=eth0:0
  6. And change the line IPADDRby specifying your new IP:
    IPADDR=185.25.111.111
  7. Then restart the service with the command:
    service network restart
After completing all the actions on the command ifconfig you will see that you have an additional interface: eth:0.
  1. Open the file for editing /etc/network/interfaces:
    nano /etc/network/interfaces
  2. 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 of 22 — the correct netmask.

  3. 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
You can check the correctness of adding the address with the command 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
If you are using a non-root user, then at the beginning of most commands you may need to specify sudo and after entering the password.
  1. 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.

  2. Check which interfaces already exist on the system. To do this, run:
    ifconfig -a
  3. 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.

  4. 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 and dhcp6 — DHCP settings for IPv4 and IPv6. It is necessary to indicate no, since the IP will be set manually.
    • addresses — a sequence of IP addresses. Instead of XXX.XXX.XXX.XXX you should specify the required IP, instead of YY — 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 of XXX.XXX.XXX.XXX you need to specify a standard gateway.
    • nameservers — nameserver settings.
      • addresses — sequence of IP addresses (indication in the block nameservers parameter addresses indicates the IP addresses of nameservers).
  5. After all the changes and saving the file, to accept the new settings, you need to do:
    netplan apply
You can check the correctness of adding the address with the command ifconfig... You should have an interface eth1.
  1. Open the file for editing /etc/network/interfaces:
    nano /etc/network/interfaces
  2. 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 of 255.255.252.0 — the network mask that you have specified above.

  3. Save changes and restart the interface:
    /etc/init.d/networking restart
You can check the correctness of adding the address with the command ifconfig... You should have an interface eth0:0.
  1. Open the file for editing /etc/conf.d/net:
    nano /etc/conf.d/net
  2. 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
  3. Save changes by clicking Ctrl-X, and then y to confirm the file has been written, and Enter.
  4. Restart the interface:
    /etc/init.d/net.eth0 restart
You can check the correctness of adding the address with the command ifconfig... You should have an interface eth0:1.
  1. Open the file /etc/sysconfig/network/ifcfg-eth0:
    vim /etc/sysconfig/network/ifcfg-eth0
  2. Press the key ito enter edit mode.
  3. 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 of 255.255.252.0 — you need to specify the value that you have indicated above in the line NETMASK.

  4. Restart the service with the command:
    service network restart
You can check the correctness of adding the address using 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
  1. Open the file /etc/sysconfig/network/ifcfg-eth0:
    vi /etc/sysconfig/network/ifcfg-eth0
  2. Press the key ito enter edit mode.
  3. 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 of 255.255.252.0 — you need to specify the value that you have indicated above in the line NETMASK.

  4. Restart the service with the command:
    service network restart
You can check the correctness of adding the address with the command 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

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".

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.

Content