Connecting Two Ubuntu Servers with Private Networking & Public Internet Access

by John November 05, 2025



 

 

In this post, we’ll walk through — step by step — how to connect two Ubuntu servers using a private network.

This setup isn’t just about making your servers talk to each other — it’s about doing it faster, cheaper, and more securely. When servers in the same region use private networking, their data never leaves the data center. That means:

 

⚡ Faster communication: Private links stay inside Linode’s internal backbone, avoiding the latency of public internet hops.

💸 Zero egress fees: Traffic sent over the private network doesn’t count toward your public bandwidth quota — saving real money on data transfer costs.

🔒 More security: Internal traffic never touches the public internet, keeping database replication, API calls, or background jobs isolated and safe.

🧩 Simpler architecture: It’s ideal for setups like a web app talking to a private database, distributed processing between two nodes, or a Docker Swarm cluster.

 

By the end, you’ll have two Ubuntu servers that can:


✅ Reach the internet normally via their public IPs, and
✅ Seamlessly talk to each other through private IPs — without paying a cent in transfer fees.

 

Linode Referral – Linux Cloud Hosting

🚀 Get $100 in free credit when you sign up for Linode with this link!
Just add a valid payment method to activate your 60-day trial.

After spending $25 and staying active for 90 days, I’ll also receive a $25 credit to support more Linux content. 💚 Thanks!

Claim Your $100 Linode Credit

 


 

Setting up the 2 Servers

 

For a full guide on configuring a new Linux server , see our in-depth guide here, also be sure to checkout our security checklist 

Ensure that the two instances you want to connect are both located in the same region. In this guide, we’ll be using Singapore, but the same process applies to any region.

Also, make sure both instances are running the same Linux distribution. For this post, we’re using Ubuntu 24.04 LTS.

 

creating servers that will be connected

 

 

view running servers

 

 

create private IP on server step 1

 

 

 

 

create private IP on server step 2

 

Server 1 IPs 

create private IP on server step 3

 

Server 2 IPs 

create private IP on server step 3

 

 

 

So now we have a total of 2 IP addresses per machine, 1 public and 1 private for a total of 4 IP addresses. 

 

Server Public IP Private IP
Server 1  172.104.188.52 192.168.170.206
Server 2  139.162.44.9 192.168.158.82

 

Private IPs come from the Linode dashboard — but they’re not automatically configured in Ubuntu so we will need to add them to each of the servers. 

 

sudo ip addr add <private-ip>/17 dev eth0

 

adding private IPs to Ubuntu server eth0

 

 

If the IP addresses have already been assigned you should see something like

 

adding private IPs to Ubuntu server eth0

 

This however is not persistent and we must use Netplan to make it permanent 

 

Open the config file with 

 

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

 

And paste the contents below. 

 

network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - <public-ip>/24
        - <private-ip>/17
      routes:
        - to: default
          via: <gateway>

 

 

netplan yaml config

 

Then you make the changes persistent by typing the command below on both servers

 

sudo netplan apply

 

You are likely to see complaints in the terminal like the ouput below , this is just netplan complaining that only root should have access to these config files. 

 

** (generate:14943): WARNING **: 06:26:04.244: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.

** (generate:14943): WARNING **: 06:26:04.244: Permissions for /etc/netplan/50-cloud-init.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:14941): WARNING **: 06:26:04.620: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:14941): WARNING **: 06:26:04.620: Permissions for /etc/netplan/50-cloud-init.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:14941): WARNING **: 06:26:04.793: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:14941): WARNING **: 06:26:04.794: Permissions for /etc/netplan/50-cloud-init.yaml are too open. Netplan conf

 

You can fix this warning with the following command on both servers

 

sudo chmod 600 /etc/netplan/*.yaml && sudo netplan apply

 


 

Enable Private IP Through the Firewall

 

Since you should have a firewall enabled, it will be default block incoming traffic , therefore we need to make a rule on each server to allow traffic from the other server. 

 

sudo allow from <private ip of server you want to allow connection from>

 

So for me on server 1 I input the private IP of server 2 and vice versa on server 2

 

allow private ip through UFW

 

Then we want to ensure that the rule has worked by typing 

sudo ufw status 

 

And we should see the rule on each of the servers.  

 

Allow private ip through ufw

 

 

 

Ping Connected Server to Ensure Connectivity

 

In order to check whether the servers have been connected successfully we can send a ping from one server to the other's private IP address

 

ping -c 3 <server private ip address>

 

ping a private IP address

 


 

Trouble-shooting IP address not Persisting

 

For some reason, on one of my servers, every time the Netplan configuration was applied, the private IP address would be dropped.

To fix this issue, the following steps were used.


Note that the <private ip> placeholder below refers to the private IP of the specific server.

 

echo 'ip addr add <private ip>/17 dev eth0' | sudo tee /etc/network/if-up.d/add-private-ip
sudo chmod +x /etc/network/if-up.d/add-private-ip

 

This adds a script that starts on boot to add the private IP address to eth0

 

 


 

Setting Internal Hostnames

 

Since it will be very cumbersome to constantly have to remember and type out the private IP address of the servers we want to connect to, it is a better idea to create a hostname. 

To do this on each server type in 

 

sudo nano /etc/hosts

 

And then put the other server's IP address and a useful name in your editor

 

creating hostname on /etc/hosts

 

 

Then we are able to ping the server from the given hostname with ping -c 3 <hostname>

 

ping server by hostname

 

And that's it hopefully you were able to follow along with this guide!