Atlantic.Net Blog

How to Add an Additional IP to Your Ubuntu 18.04 Server

Hitesh Jethva
by Atlantic.Net (12posts) under VPS Hosting
0 Comments

Adding an additional IP is routine for any system administrator. When you set up a new server, it will have a single IP address linked with the server hostname. There are several reasons you might need to set up an additional IP address on your system. Some of them are listed below:

  • To set up Internet sharing with Squid proxy server.
  • To run the same service multiple times.
  • To use different hostnames in reverse DNS lookups.
  • To avoid being blacklisted in spam filters.
  • To host multiple SSL sites.

Ubuntu allows you to add multiple virtual IP addresses on a single network interface card without buying an additional network adapter.

In this tutorial, we will explain how to add an additional IP address on an Ubuntu 18.04 server.

Prerequisites

Create an Atlantic.Net Cloud Server

First, log in to your Net Cloud Server. Create a new server, choosing Ubuntu 18.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged into your Ubuntu 18.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Add an Additional IP Address Permanently

The process to configure an IP address on an Ubuntu 18.04 server is different than the older method used in the older version of Ubuntu. Ubuntu 18.04 uses Netplan utility to configure networking.

You can add an additional IP address permanently to your system by editing the file /etc/netplan/50-cloud-init.yaml.

First, you can see your existing IP address with the following command:

ip addr

You should see the following output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:c8:48:62 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.101/24 brd 192.168.0.255 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fec8:4862/64 scope link
       valid_lft forever preferred_lft forever

You can also see your existing network configuration with the following command:

cat /etc/netplan/50-cloud-init.yaml

You should see your existing network configuration in the following output:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.0.101/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8]

In the above output, you should see that the IP address 192.168.0.101 is assigned to the interface.

Here’s a brief explanation of each parameter:

  • enp0s3: A device name to be configured.
  • dhcp4:  Used to enable or disable dhcp4.
  • dhcp6: Used to enable or disable dhcp6.
  • addresses: The IP address of the device.
  • gateway4: The IP address of your gateway.
  • nameservers: The IP address of your DNS server.

Next, we will add an additional IP address 192.168.0.100 to the server.

To do so, open your file /etc/netplan/50-cloud-init.yaml in your preferred text editor:

nano /etc/netplan/50-cloud-init.yaml

After adding an additional IP address, your file should look something like this:

network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.0.101/24, 192.168.0.100/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8]

Save and close the file when you are finished. Then, enable the new configuration with the following command:

netplan apply

Now, check your new IP address with the following command:

ip addr

You should see both IP addresses in the following output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:c8:48:62 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.101/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 192.168.0.100/24 brd 192.168.0.255 scope global secondary enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fec8:4862/64 scope link
valid_lft forever preferred_lft forever

Add an Additional IP Address Temporarily

You can also add an additional IP address temporarily to your server easily with ip addr command.

For example, add the IP address 192.168.0.100 temporarily with the following command:

ip addr add 192.168.0.100/24 dev enp0s3 label enp0s3:1

Now, check your IP address with the following command:

ip addr

You should see that the new IP address 192.168.0.100 is assigned to the interface enps3:1.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:c8:48:62 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.101/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 192.168.0.100/24 scope global secondary enp0s3:1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fec8:4862/64 scope link
valid_lft forever preferred_lft forever

Conclusion

Congratulations! You have successfully configured multiple IP addresses on a single network interface. I hope you have now enough knowledge to add multiple IP addresses to your system as per your requirements. If you’re ready to get started configuring multiple IPs on a VPS, check out Atlantic.Net’s VPS Hosting options.

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Sales Today! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Case Studies

White Papers

Resources


HIPAA Partners


Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources