How to Configure Network Static IP Address in Ubuntu 18.04?


Introduction

The Internet Protocol (IP) address is a crucial component of computer networking as it uniquely identifies each device connected to a network. By default, most network interfaces are configured to obtain an IP address dynamically from a router or DHCP server. However, in some cases, it is necessary to configure a static IP address.

A static IP address is an IP address that is manually assigned to a device and does not change over time unless manually reconfigured. In this article, we will discuss how to configure a static IP address on Ubuntu 18.04 and why it's important in some situations.

What Is Static IP Address And Why It's Important?

When you connect your computer or other devices like printers and servers to a network, they are assigned dynamic IPs by default using DHCP (Dynamic Host Configuration Protocol). However, there are several reasons why you may want or need your devices to have static IPs instead of dynamic IPs.

One of the primary reasons for having a static IP is stability- when you have a device with dynamic IPs constantly changing its addresses it can be challenging for other computers on the network to keep track of where that machine is located correctly. This problem can cause issues such as disrupted connections and broken services.

With a static IP address, you specify an address that devices will always be able to find your machine at no matter what else changes on the network around it over time. Another reason for having a static IP is security – assigning fixed addresses can help security measures track traffic patterns from known locations more efficiently than if addresses constantly change; this helps them distinguish between legitimate traffic from known hosts versus potentially malicious traffic from unknown sources.

Understanding Network Configuration in Ubuntu 18.04

Overview of network configuration files and their locations

Before proceeding with setting up a static IP address, it is important to have a basic understanding of network configuration files in Ubuntu 18.04. There are two primary configuration files for network settings in Ubuntu 18.04: /etc/network/interfaces and /etc/netplan/*.yaml.

The /etc/network/interfaces file is used by the ifupdown package, which is the traditional method of configuring networking on Ubuntu systems. The file contains interface configurations such as IP address, netmask, gateway, and DNS servers.

The /etc/netplan/*.yaml file is used by the Netplan utility for configuring networking in Ubuntu 18.04. This YAML-based configuration file provides a simple and flexible way to configure network interfaces.

Explanation of the importance of understanding network configuration before proceeding with configuring a static IP address

Having an understanding of how network configurations work in Ubuntu 18.04 is essential when configuring static IP addresses. Static IP addresses are manually assigned, unlike dynamic IPs that are automatically assigned by DHCP (Dynamic Host Configuration Protocol). Assigning an incorrect static IP address or modifying other critical settings can lead to loss of connectivity to the network and internet.

Therefore, before proceeding with setting up a static IP address on your system, it is important to have some knowledge about how networking works in Ubuntu 18.04 operating system so that you can avoid making mistakes that might cause problems later on during the process or cause your system to be inaccessible over your local area network or even over public networks like the internet. In short, having this knowledge will help you troubleshoot any problem or issue that may arise during the process correctly because you will understand what is happening and why.

Identifying Network Interface Name and Current IP Address

As we proceed towards configuring a static IP address in Ubuntu 18.04, the first step is to identify the network interface name. In Ubuntu 18.04, network interfaces are named differently from previous versions, so it is important to understand how to find the correct interface name.

One way to identify the name of the network interface is by using command-line tools such as ifconfig or ip addr show. To use ifconfig, open a terminal window and type "ifconfig" at the prompt.

A list of all available network interfaces will be displayed with their respective names. To check the current dynamic IP address assigned to the interface, look for an entry labeled "inet addr" under each interface’s details in ifconfig output.

The inet addr value represents the dynamic IP address assigned by DHCP server. Another tool that can be used to obtain information about network interfaces in Ubuntu 18.04 is ip command line utility.

By running “ip addr show” command on terminal you can get a detailed list of all available interfaces with their IPv4, IPv6 addresses and other important information. Knowing how to find both this information will be useful while configuring static IP addresses in Ubuntu 18.04 since you need this information while editing netplan YAML file in order configure a static IP address correctly

Configuring Static IP Address using Netplan

Overview of Netplan YAML file structure

Netplan is a configuration utility that allows users to easily configure network settings in Ubuntu 18.04. The main configuration file for Netplan is located at "/etc/netplan/", and it uses YAML syntax for its configuration files. The syntax of the file is strict, so even a small error can cause issues with network connectivity.

The top-level elements in the Netplan YAML file specify the behavior of each network interface defined in the configuration file. These elements contain basic information about the network interface, such as its name, IP address, gateway, DNS server(s), and any custom routes.

Step-by-step guide on how to edit and configure Netplan YAML file for static IP addressing.

Here are the steps involved in configuring a static IP address using Netplan −

  • Open your Terminal application by pressing `Ctrl+Alt+T` or searching for "Terminal" on the Ubuntu applications menu.

  • Navigate to "/etc/netplan/" by running this command: `cd /etc/netplan/`

  • Open the default NetPlan YAML configuration file called "50-cloud-init.yaml" by running this command: `sudo nano 50-cloud-init.yaml`

  • Locate your network interface name from Section II earlier (e.g., enp0s25) and add these lines under it−

addresses: [YOUR_STATIC_IP_ADDRESS/MASK] 
gateway4: YOUR_GATEWAY_IP_ADDRESS nameservers: 
addresses: [YOUR_DNS_SERVER_IP_ADDRESSES] 
  • Replace "YOUR_STATIC_IP_ADDRESS/MASK", "YOUR_GATEWAY_IP_ADDRESS", and "YOUR_DNS_SERVER_IP_ADDRESSES" with your own values.

  • Save your changes by pressing `Ctrl+X`, then press Y when prompted to save, and press Enter to confirm the file name.

  • Test your configuration by running the following command: `sudo netplan apply`

Explanation on how to apply changes made on Netplan YAML file.

To apply changes made in the Netplan YAML file, you need to run the "netplan apply" command in the Terminal. This command applies your changes immediately without requiring a system reboot.

If you don't run this command, any changes you make will not be applied until a system reboot or until you manually run this command. Additionally, if there are any syntax errors in your NetPlan YAML configuration file, running "netplan apply" will fail and an error message will be displayed in your Terminal output.

Overall, configuring static IP addresses using NetPlan can be a great way to ensure stable network connectivity for Ubuntu 18.04 users. The process may seem complex at first glance but once you follow these steps carefully it'll become much simpler.

Conclusion

In this article, we discussed the importance of having a static IP address in Ubuntu 18.04. A static IP address ensures that your device can always be reached at the same network address, making it easier to manage and keep track of devices on your network. This is particularly important for servers and other devices that need to be accessible from outside your local network.

Updated on: 11-Jul-2023

617 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements