If you’re like most people, you probably have a single IP address assigned to your computer. This means that if you want to access the internet from another location in your house or office, you’ll need to use a different network cable and router. This can be a bit of a hassle if you want to share files or access the internet from multiple locations on your network. Fortunately, there’s an easy way to add an additional IP address to your Linux server so that you can continue using the same network without having to switch cables and routers. To add an additional IP address to your Linux server, follow these steps:

  1. Open a terminal window by pressing Ctrl+Alt+T or by clicking on the “Terminal” icon in the menu bar at the top of your screen.
  2. Type “sudo nano /etc/network/interfaces” and press Enter. This will open the configuration file for your network interface.
  3. Find the line that says “iface eth0 inet static” and replace it with this: iface eth0 inet static address 192.168.1.* netmask 255.* broadcast 192.* If you’re using a router, replace 192.* with its corresponding IP address (for example, 192.168.1.1). You can also use wildcards (*) if necessary (for example, if you have three addresses available, you could use this line: iface eth0 inet static address 192.). ..

Why Use Another IP Address?

Having multiple addresses is great for a number of reasons. The main benefit is being able to have multiple applications running on the same port, but on different addresses. For example, you couldn’t run NGINX and Apache at the same time, as they’re both web servers that need to use port 80. However, if you ran NGINX bound to one IP address, and Apache bound to another, you could do so without any conflict.

In this case of serving web content, you can also solve this problem with a reverse proxy—a type of web server that sits in front of your content, listens on one port, and directs content to other locations, often multiple different locations.

RELATED: How to Set Up a Reverse Proxy With Apache

However, having multiple actual IP addresses can be much simpler with no reverse proxy configuration to maintain. You simply start the services on the correct address, and it will listen directly on that address.

Multiple addresses also work really well with Docker, which is a tool that can package applications into portable containers and run them anywhere. Having multiple external IPs to bind containers to allows your server to run many different applications easily on one machine.

How Do I Get More IP Addresses?

There are a finite number of public IPs left in the world, and most are already allocated to internet companies. In order to get more, you will need to buy or rent them from your hosting provider. Most mainstream cloud providers will have an option for extra IPs, but the setup will depend on what you’re using.

For example, if you’re on AWS, you probably already have an Elastic IP Address for your EC2 instances. However, you can just add more Elastic IPs, at the cost of $3.65 per month for each one.

RELATED: What Are AWS Elastic IPs, and What Do They Do?

Other cloud providers might let you purchase entire blocks of addresses. OVH, one of the largest dedicated server providers, offers CIDR blocks of up to /24 in size, for a one-time fee.

Large corporations that want to directly own and control a large amount of IPv4 address space can also purchase entire blocks directly from IANA (through a brokerage). However, this comes at a large premium—often over $50 per address, and large blocks cost tens or even hundreds of thousands of dollars.

How Do Multiple IP Addresses Work?

Linux networking is a little weird. Each network card physically attached to your server will show up in ip addr show as a network interface like eth0 or eno1. There can also be various types of virtual interfaces, but all actual connections out from the server go through a physical network interface.

IP addresses are different—they are not tangible things that are associated with your server’s network interface, they’re simply an abstraction used to identify servers for routing. Your hosting provider will get a request, and if it’s destined for an IP address you own, it will be routed to your server using the host’s routing configuration.

The key part there is that your server’s network interface must be configured in software to receive that request. If your server doesn’t have the address added to a network interface’s config, it won’t respond. You could technically configure your server to listen on any address, even ones you don’t own, though it wouldn’t do anything.

IP addresses are allocated in blocks, represented in CIDR notation. The smallest is /32, which represents a single address. As the number gets smaller, the number of addresses increases.

RELATED: What are Subnets, and How Do They Affect My Network?

Configuring Linux to Use Multiple IP Addresses

Linux network configuration can be hard, and there are multiple tools out there to make it easier. One of the best is netplan, created by the team behind Ubuntu. It configures network interfaces using easy YAML templates. It should be installed by default on most systems.

Create a new template in /etc/netplan/config.yaml:

Then, add your configuration. Note that this example is for the interface eno1, which may need to be changed to eth0 or something similar.

You can specify multiple address blocks here, or single IP addresses as singular /32 blocks.

Once configured, run netplan try to test it out. If the config is faulty, it will be rolled back.

If it works, apply the config:

You can debug your routing by running tcpdump to display requests sent to an interface: