How to Temporarily Set a Static IP Address on a Linux System

Setting a static IP address on a Linux system temporarily is useful in situations where you need to troubleshoot network issues or configure networking for a specific session.

This temporary change won’t persist after a reboot, but it can be easily applied for immediate network setup needs.

In this guide, we’ll walk through the steps to configure a static IP address on a Linux system using command-line tools.

Step 1: Check Linux Network Interface

First, identify the name of your network interface by running the following ip command.

ip a

This command will display all the network interfaces available on your system. Look for your active network interface, usually named something like eth0, ens33, or wlan0 (for Wi-Fi).

Check Linux Network Interface
Check Linux Network Interface

Here, enp1s0 is the name of the network interface.

2. Temporarily Assign a Static IP Address on Linux

Once you’ve identified the network interface, use the ip command to assign a temporary static IP address. For example, to assign the IP address 192.168.122.50 with a subnet mask of 255.255.255.0, you can use the following command:

sudo ip addr add 192.168.122.50/24 dev enp1s0

To ensure your system can route traffic properly, you need to set the default gateway, which is typically the IP address of your router or gateway on the local network.

sudo ip route add default via 192.168.122.1

Here, 192.168.122.1 is the IP address of the gateway (router).

Step 3: Verify Network Configuration

After setting the static IP address, you should verify that the changes have been applied correctly.

ip a

Additionally, you can test connectivity by pinging an external site or your gateway:

ping 8.8.8.8

If you get replies, the network configuration is working.

Check Linux Network Configuration
Check Linux Network Configuration

Step 4: Removing Temporary Static IP Address

Since this configuration is temporary, it will revert back to the original settings after a reboot. However, if you want to manually remove the static IP address before rebooting, you can use the following command:

sudo ip addr del 192.168.122.50/24 dev enp1s0

This will remove the static IP address from the network interface.

Conclusion

Temporarily setting a static IP address in Linux can be useful for troubleshooting or specific network setups. The method shown here uses the ip command, which is a modern and versatile tool for managing network configurations on Linux systems.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.