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.

  1. Go to the /etc/sysconfig/network-scripts directory:
    cd /etc/sysconfig/network-scripts/
  2. Copy the existing ifcfg-eth0 file and rename it to ifcfg-eth0:0:
    cp ifcfg-eth0 ifcfg-eth0:0
  3. Open this file using any text editor you prefer:
    vi ifcfg-eth0:0
  4. Delete the lines related to IPv6 (this is the line # IPv6 and the ones that follow it — they all contain IPv6 at the beginning).
  5. Change the DEVICE line by adding :0 at the end:
    DEVICE=eth0:0
  6. And change the IPADDR line to your new IP:
    IPADDR=185.25.111.111
  7. Then restart the service using the following command:
    service network restart
Once you've completed all the steps, using the ifconfig command, you'll see that an additional interface has appeared: eth:0.
  1. Open the /etc/network/interfaces file for editing:
    nano /etc/network/interfaces
  2. At the end of the group of lines related to the eth0 inet configuration, 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 of 185.25.111.111, you need to specify your new IP address, and instead of 22, you need to specify the correct subnet mask.

  3. 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
You can check that the address was added correctly using the 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
If you are not logged in as the root user, you may need to prefix most commands with sudo and enter your password.
  1. Generate a configuration file if one does not exist. Here's how to do it:
    netplan generate

    To check for existing files, do the following:

    ls -l /etc/netplan/

    If the output shows total 0 then a file needs to be generated.

  2. Check which interfaces already exist in the system. To do this, run the following command:
    ifconfig -a
  3. Open the configuration file for editing:
    nano /etc/netplan/XXXXX.yaml

    Important! Replace XXXXX with the correct name of an existing file.

  4. In the ethernet section, 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.
    • dhcp4 and dhcp6 — DHCP settings for IPv4 and IPv6. You must select no because the IP address will be set manually.
    • addresses — a sequence of IP addresses. Replace XXX.XXX.XXX.XXX with the desired IP address, and YY with 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. Replace XXX.XXX.XXX.XXX with the standard gateway.
    • nameservers — name server settings.
      • addresses — a sequence of IP addresses (the addresses parameter in the nameservers block specifies the IP addresses of the name servers).
  5. After making all changes and saving the file, run the following command to apply the new settings:
    netplan apply
You can check that the address was added correctly using the ifconfig command. You should see the eth1 interface.
  1. Open the /etc/network/interfaces file for editing:
    nano /etc/network/interfaces
  2. 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.0

    Replace 185.25.111.111 with your new IP address, and replace 255.255.252.0 with the subnet mask you specified above.

  3. Save your changes and restart the interface:
    /etc/init.d/networking restart
You can check that the address was added correctly using the ifconfig command. You should see the eth0:0 interface.
  1. Open the file /etc/conf.d/net for editing:
    nano /etc/conf.d/net
  2. 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
  3. Save your changes by pressing Ctrl-X, then y to confirm saving the file, and Enter.
  4. Restart the interface:
    /etc/init.d/net.eth0 restart
You can check that the address was added correctly using the ifconfig command. You should see the eth0:1 interface.
  1. Open the /etc/sysconfig/network/ifcfg-eth0 file:
    vim /etc/sysconfig/network/ifcfg-eth0
  2. Press the i key to enter edit mode.
  3. 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 of 255.255.252.0, you need to enter the value you specified above in the NETMASK line.

  4. Restart the service using the following command:
    service network restart
You can check that the address was added correctly using the 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
  1. Open the /etc/sysconfig/network/ifcfg-eth0 file:
    vi /etc/sysconfig/network/ifcfg-eth0
  2. Press the i key to enter edit mode.
  3. 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 of 255.255.252.0, you need to enter the value you specified above in the NETMASK line.

  4. Restart the service using the following command:
    service network restart
You can check that the address was added correctly using the 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

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.

Tabla de conținut