How to Set Up a Static IP Address on Linux

A static IP address is required for server use, development, or network configuration. A static IP address is different from a dynamic IP address. That changes from time to time. A static IP address ensures that the IP address of your device remains the same at all times.

Administrators configure static IP settings for their Linux systems. They can enjoy the benefits of network communication. Therefore, this is one of the main reasons why administrators use the static ip configuration for the Linux operating system for their systems.

There are different ways of configuring network settings for the Linux operating system. The network configuration for the Ubuntu operating system can use the Netplan or the NetworkManager network configuration tools. The basic concept of network configuration remains the same for all tools.

The Significance of Static IP Addresses

The static IP address is commonly employed in professional environments because it can prevent confusion in network connections. The server may not be able to host services like a web server, DNS server, or remote connections if the IP address of the server changes.

There are many advantages to setting up a static IP address:

  • Reliable remote connections through SSH/remote desktop
  • Reliable server hosting services for websites and API servers
  • Simple firewall management
  • Simplified port forwarding management
  • Simple management of the internal network
  • Simplified management of the monitoring and logging system

For companies that manage servers, the advantages of static IP address setup can be quite significant.

Check Your Current Network Interface

You can configure the IP settings. It is necessary to determine the current interface that is active on the Linux system. The interface may be named “eth0,” “ens33,” “enp0s3,” etc.

You can verify this by using the addr command.

This command will list all network interfaces and their allocated IP addresses.

Some of the information it will return includes:

  • Interface Name
  • Current IP address
  • Net mask
  • Interface status

As a result, after establishing which interface is correct, you can proceed to configure a Linux static IP.

Temporarily Setting a Static IP Using the addr Command

Linux allows users to configure a static IP by using a command-line interface.

Example:

sudo ip addr add 192.168.1.100/24 dev eth0

This command will configure an IP address on a specified interface.

To enable the interface if it is disabled, use this command:

sudo ip link set eth0 up

However, it is worth noting that this configuration will not be saved after a restart.

Configure Static IP on Ubuntu Using Netplan

Modern Ubuntu systems utilize a tool called Netplan to configure network settings. Also, this tool helps to configure Ubuntu network settings using a file written in a format called YAML.

To configure a static IP on Ubuntu permanently, perform these steps.

Step 1: Locate the Netplan Configuration File

Netplan configuration files can be found in this location by default:

/etc/netplan/

/etc/netplan/

File Example

01-netcfg.yaml

Step 2: Edit the Configuration

Open it with a text editor using a command such as this one:

sudo nano /etc/netplan/01-netcfg.yaml

Example configuration

network:

  version: 2

  ethernets:

    eth0:

      dhcp4: no

      addresses:

        - 192.168.1.100/24

      gateway4: 192.168.1.1

      nameservers:

        addresses: [8.8.8.8, 8.8.4.4]

Step 3: Apply the Changes

After editing and saving the file, apply these changes by entering this:

sudo netplan apply

The system will now use the defined Static IP configuration.

Verifying Your Static IP Configuration

Verify the applied configuration using the same command again:

ip addr show

Your IP should now be reflected under the correct network interface.

ping google.com

The ping is successful if the network configuration is correct.

At other times, the configuration may not allow the system to connect as required. Hence, the common problems that may arise, together with the solutions, are as follows:

1. Incorrect Gateway

The gateway address may not be correctly configured. Thus, failing to allow the system to access other external networks.

2. YAML Formatting Errors

The netplan configuration file requires proper formatting, such that a small error may lead to the failure of the configuration.

3. Interface Name Errors

The interface name may not be correctly configured, which may lead to the failure of the configuration.

To verify the interface name, the following command can be run:

ip addr

Best Practices for Static IP Configuration

The following best practices should be followed in order for a stable networking setup to be achieved:

  • Document all static IP addresses in use in the network
  • Avoid overlapping IP address ranges
  • Gateway and DNS server consistency
  • Testing before implementation
  • Frequent monitoring of network configurations

Conclusion

Configuring a static IP address on a Linux system is an essential skill for every system administrator and developer. Whether you are using a temporary setup through addr or a permanent setup using Netplan, configuring an IP address is a process that enables your system to maintain a consistent identity in a network. It is a simple process that enhances security and performance with proper planning and tools in place.

Reserve the static IP in the DHCP settings of the router. The same IP may be assigned to other network devices on the same network by the router. Moreover, this can cause IP conflicts. As a result, reserving the IP in the DHCP settings of the router will solve this problem.

FAQs

What is a static IP in Linux?
How do I configure a static IP on Linux?
What command do I use to check the current IP address?
Is static IP on Linux better than DHCP?
Does Ubuntu use Netplan for network configuration?

Related Post

How to Install and Deploy Kubernetes on AlmaL...

Kubernetes, often abbreviated as K8s, is an open-source...

Exploring chsh Command in Linux with Examples

The chsh command a utility commonly found in Linux dist...

How to use Linux Shutdown Command

The shutdown command is a powerful tool in the Linux op...

How to Check if Your Linux OS is 32-bit or 64...

In the field of computing understanding your syste...

How to Install Visual Studio Code on Linux

Visual Studio Code (VS Code) is a widely used code edit...

How to Generate Report Using MTR on Linux

When troubleshooting network issues on Linux, having a ...

Leave a Comment