Technology

#How to Add an Additional IP Address to Your Linux Server

“How to Add an Additional IP Address to Your Linux Server”

network switch panel
asharkyu/Shutterstock.com

Most Linux servers, including virtual private servers, will come with a public IP address for you to connect to. However, the physical network card used to carry the connection can support any number of IP addresses. Here’s how to add a new one to your server.

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.

192.168.0.0/24 -> 192.168.0.0 to 192.168.0.255

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:

sudo nano /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.

network:
    version: 2
    ethernets:
        eno1:
            addresses:
            - 123.1.2.3/32

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.

sudo netplan try

If it works, apply the config:

sudo netplan apply

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

If you liked the article, do not forget to share it with your friends. Follow us on Google News too, click on the star and choose us from your favorites.

For forums sites go to Forum.BuradaBiliyorum.Com

If you want to read more like this article, you can visit our Technology category.

Source

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close

Please allow ads on our site

Please consider supporting us by disabling your ad blocker!