Ubuntu 20.04 Server Static IP: How to Set It Up

Introduction

Greetings, fellow tech enthusiasts! If you’re running a server using Ubuntu 20.04, then you might have encountered a common problem: your server’s IP address keeps changing. This can cause several issues, especially if you’re running a website or service that requires a consistent IP address. Fortunately, there’s a simple solution: setting up a static IP address.

In this article, we’ll provide you with a step-by-step guide on how to set up a static IP address on your Ubuntu 20.04 server. But before we dive into the technicalities, let’s first understand what a static IP address is.

What is a Static IP Address?

A static IP address is a fixed IP address that doesn’t change, unlike a dynamic IP address that is assigned by a DHCP server. In other words, a static IP address is a permanent address that you can use to access your server from anywhere without worrying about it changing.

Now that we know what a static IP address is let’s move on to why you should consider setting one up.

Why Should You Set Up a Static IP Address?

There are several reasons why you should set up a static IP address for your Ubuntu 20.04 server:

Improved accessibility: A static IP address allows you to access your server remotely without needing to constantly check for IP address changes.

Better security: Since a static IP address doesn’t change, it makes it easier to set up firewall rules and whitelist trusted IP addresses.

Easier identification: If you’re running multiple servers, a static IP address helps you easily identify and differentiate between each server.

Now that you know why you should set up a static IP address, let’s proceed to the steps.

Setting Up a Static IP Address on Ubuntu 20.04 Server

Step 1: Check Your Network Configuration

The first step is to check your network configuration. You can do this by running the following command:

Command
Description
ip address show
Displays your current network configuration.

When you run this command, you should see output that looks something like this:

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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:3f:d7:35 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.15/24 brd 192.168.0.255 scope global dynamic ens33
valid_lft 3352sec preferred_lft 3352sec
inet6 fe80::d9e1:ef5d:1747:4066/64 scope link noprefixroute
valid_lft forever preferred_lft forever

The output above shows that there are two interfaces: lo and ens33. The lo interface is the loopback interface, and ens33 is the network interface that we’re interested in. In our case, the IP address assigned to the ens33 interface is currently 192.168.0.15, which is a dynamic IP address.

Step 2: Locate and Open the Netplan Configuration File

The next step is to locate and open the Netplan configuration file. Netplan is the new network configuration tool for Ubuntu 20.04.

To open the Netplan configuration file, run the following command:

Command
Description
sudo nano /etc/netplan/50-cloud-init.yaml
Opens the Netplan configuration file in the Nano text editor.

This command opens the Netplan configuration file in the Nano text editor. The file will look something like this:

network:
version: 2
ethernets:
ens33:
dhcp4: true
optional: true

The configuration above shows that the ens33 interface is set to obtain its IP address automatically using DHCP, which is why it’s currently a dynamic IP address.

Step 3: Configure a Static IP Address

The next step is to configure a static IP address for the ens33 interface. To do this, we need to modify the Netplan configuration file. Replace the contents of the file with the following configuration:

Configuration
Description
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
addresses: [192.168.0.100/24]gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
The new Netplan configuration for a static IP address.

The configuration above sets the ens33 interface to use a static IP address of 192.168.0.100 with a netmask of 255.255.255.0 (/24). The gateway4 field specifies the IP address of the default gateway, and the nameservers field specifies the IP addresses of the DNS servers.

READ ALSO  Configuration DNS Ubuntu Server: A Comprehensive Guide

After you’ve made the changes, save the file by pressing CTRL+X, then Y, and then ENTER.

Step 4: Apply the Netplan Configuration

The final step is to apply the Netplan configuration by running the following command:

Command
Description
sudo netplan apply
Applies the new Netplan configuration.

The command above applies the new Netplan configuration and restarts the networking service. After running this command, your server should now have a static IP address.

Advantages and Disadvantages of Using a Static IP Address

Now that we’ve covered how to set up a static IP address let’s discuss the advantages and disadvantages of using one.

Advantages of Using a Static IP Address

Consistent accessibility: With a static IP address, you can access your server from anywhere without worrying about IP address changes.

Better security: Static IP addresses make it easier to set up firewall rules and whitelist trusted IP addresses.

Easier identification: If you’re running multiple servers, a static IP address helps you easily identify and differentiate between each server.

Better for hosting services: If you’re running a website or other service that requires a consistent IP address, a static IP address is a must.

Disadvantages of Using a Static IP Address

Requires manual configuration: Unlike dynamic IP addresses, static IP addresses require manual configuration.

Can be more expensive: Some ISPs charge extra for static IP addresses.

Less flexibility: A static IP address ties your server to a specific address, which can be limiting if you need to move your server to a different location.

Frequently Asked Questions

1. What is the difference between a dynamic and static IP address?

A dynamic IP address changes every time you connect to the network, while a static IP address remains the same.

2. How do I check my server’s IP address?

You can check your server’s IP address by running the command ip address show.

3. Can I use a static IP address for my home network?

Yes, you can use a static IP address for your home network for improved accessibility and security.

4. How do I set up a static IP address on Windows?

You can set up a static IP address on Windows by going to the Network and Sharing Center and selecting Change adapter settings. Then right-click on the adapter you want to set a static IP address for and select Properties. From there, select Internet Protocol Version 4 (TCP/IPv4) and click on Properties. Then select Use the following IP address and enter your desired IP address, subnet mask, default gateway, and DNS server.

5. Can I switch from a static IP address to a dynamic IP address?

Yes, you can switch from a static IP address to a dynamic IP address, but you’ll need to reconfigure your network settings.

6. How do I find my default gateway?

You can find your default gateway by running the command ip route show default.

7. What is Netplan?

Netplan is the new network configuration tool for Ubuntu 20.04 that allows you to configure network settings in a YAML file format.

8. Can I use a static IP address for my mobile device?

Yes, you can use a static IP address for your mobile device by going to the Wi-Fi settings and selecting the network you want to configure. Then select Static IP and enter your desired IP address, subnet mask, default gateway, and DNS server.

9. How do I configure DNS servers on Ubuntu?

You can configure DNS servers on Ubuntu by editing the /etc/resolv.conf file and adding the IP addresses of your desired DNS servers.

10. Is it safe to use a static IP address?

Yes, it’s safe to use a static IP address as long as you take the necessary security measures.

11. Do I need a static IP address for hosting a website?

Yes, you need a static IP address for hosting a website to ensure that your website is accessible from anywhere.

12. Can I set up a static IP address for my virtual machine?

Yes, you can set up a static IP address for your virtual machine by following the same steps as for a physical machine.

READ ALSO  How to Set up a Mail Server Ubuntu

13. How do I troubleshoot network connectivity issues after setting up a static IP address?

If you’re facing network connectivity issues after setting up a static IP address, try the following troubleshooting steps:

– Check your network configuration for any errors.

– Make sure that your IP address, subnet mask, and gateway settings are correct.

– Check your firewall settings to ensure that they’re not blocking incoming traffic.

Conclusion

Congratulations! You’ve successfully set up a static IP address for your Ubuntu 20.04 server. We hope this guide has been helpful in improving your server’s accessibility and security. Remember to take the necessary security measures to protect your server from any potential threats.

If you have any questions or feedback, feel free to leave them in the comments below. And if you found this guide helpful, please share it with your fellow tech enthusiasts.

Disclaimer

This article is for educational purposes only. We do not take responsibility for any damages or losses that may arise from following this guide. Please exercise caution and take the necessary security measures before implementing any changes to your network configuration.

Video:Ubuntu 20.04 Server Static IP: How to Set It Up