How to add an additional ip address to your linux server.
Most Linux servers, including virtual private servers, will come with a public IP address for you to connect to.
Why use another ip address, how do i get more ip addresses, how do multiple ip addresses work, configuring linux to use multiple ip addresses.
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.
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.
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.
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.
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.
Linux networking is a little weird. Each network card physically attached to your server will show up in
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
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.
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:
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How to release an IP address and renew from the commandline?
I am using modern versions of Ubuntu that use network-manager, and I would like release and renew my network settings through the commandline.
In the olden days when Ubuntu used the interfaces file, I would simply do: sudo /etc/init.d/networking restart but now that no longer works.
I am looking for functionality similar to Windows' ipconfig /release and ipconfig /renew .
How can I release and renew network settings from the commandline interface?
- Which version of Ubuntu? Network Manager's tools have evolved over time. Have a look at manpages.ubuntu.com/manpages/xenial/en/man1/nmcli.1.html – muru May 4, 2016 at 7:51
- 2 Did you try sudo /etc/init.d/network-manager restart ? – migrc May 4, 2016 at 8:50
- What exactly is a "modern version of Ubuntu"? You should be more specific. – Rosamunda Mar 12, 2017 at 17:30
- 1 A modern version of Ubuntu would be a current version. The answer could change over time. – David Mar 15, 2017 at 21:17
2 Answers 2
To release and renew the IP address it is:
Or you can try a one-liner that grabs the default ethernet name from netstat (using -v switch to show verbose):
From the dhclient manpage:
Hope this helps!
- For the second command ( sudo dhclient eth0 ) I get this error: Failed to try-reload-or-restart systemd-resolved.service: Unit systemd-resolved.service is masked. It's actually because I use dnscrypt-proxy and I have to have systemd-resolved masked, otherwise it will interfere with it. Any other option? Thanks. – Shayan Aug 23, 2019 at 17:18
- 1 @Shayan I really don't know about dnscrypt-proxy and I wouldn't know any commands to help about that. I guess you could try downing the eth0 port then bring it back up. sudo ifconfig eth0 down then sudo ifconfig eth0 up . Sorry for the late response. – Terrance Apr 23, 2020 at 21:51
One way to accomplish this is to tell network-manager to briefly disconnect the device and the connecting it again:
(replace wlan0 with the correct device name on your system)
- 1 So there's no equivalent to ipconfig /release /renew of Windows for Linux? But other than that, your answer works perfectly. – Shayan Aug 23, 2019 at 17:29
You must log in to answer this question.
Not the answer you're looking for browse other questions tagged command-line networking network-manager dhcp ..
- The Overflow Blog
- CEO update: Giving thanks and building upon our product & engineering foundation
- The AI assistant trained on your company’s data
- Featured on Meta
- Update: New Colors Launched
- Incident update and uptime reporting
- AI-generated content is not permitted on Ask Ubuntu
- Notifying users about the policy on AU concerning AI-generated content
Hot Network Questions
- Should I tin wires prior to installation in the panel?
- a Gutter or Sewer?
- Fixing wrong ideas about coefficients (e.g. subtract 3 from 3x to isolate x)
- Independent researcher being solicited for an academic collaboration. What do I need to know?
- Can I, a British Green Card holder residing in western NY, go to pick up my British mother flying into Toronto airport and bring her back home?
- (How) would the water deluge system impact Starship superheavy captures?
- Do I need to let the editor know of my first peer-review?
- How to group a square grid diagonally
- Classical capacity of quantum channel - Holevo quantity vs accessible information of a channel
- What is the difference between "the spacecraft is in the sky" and "the spacecraft is in space"?
- Could the human body feel the sudden disappearance or end of a gravitational force?
- Will recording as MIDI lose the quality of a WAV?
- Will the passport control (tourist visa check) happen in Norway (destination and visa issuing country) or Munich (layover)?
- How to change the size of a point in pst-solides3d?
- Does n have to equal infinity?
- Who hugely misunderstood the sentence "Do you feel like breakfast ?"
- Maya Bending in Blender, is it possible?
- Is there equivalent for "I'm starving to death" in Portuguese?
- Paying $185k back rent to sister - can I claim in taxes?
- Can a sealed jar be unsafe?
- Why didn't Microsoft use a well-known encryption algorithm like RSA for telephone activation?
- Defensive Middle Ages measures against magic-controlled "smart" arrows
- Can you completely determine a finitely presented finite group?
- Has there been any significant pro-Palestinian protest critical of Hamas?