How to Configure a Static IP Address on Ubuntu [20 Easy Steps]

Written by

Reviewed by

Last updated: July 26, 2023

Expert verified

SVG Image

TL;DR

To configure a static IP address on Ubuntu, you can follow these steps:

  1. View your current IP address using ifconfig and check its details like subnet mask and gateway.
  2. List all network interfaces on Ubuntu with ip link show, showing their names and status.
  3. Check the status of the desired interface with ip a show [interface].
  4. Ensure the selected static IP falls within your network’s range but outside the DHCP pool to avoid conflicts.
  5. Edit the netplan configuration file, adding the desired static IP address, subnet mask, gateway, and DNS settings. Save the changes, restart the networking service, and verify the new static IP using ifconfig

To configure a static IP address on your network, follow best practices like regularly reviewing and updating IP settings, keeping a log of network changes, implementing additional security measures, and planning for network scalability. Be cautious of common errors such as IP conflicts, incorrect settings, inactive interfaces, and typos in configuration files to ensure a smooth and stable static IP configuration on your Ubuntu system.

Continue reading the guide below to learn the step-by-step method to configure a static IP address on Ubuntu. also , learn abou the common errors that can occur during configuration and the best practices to follow.

Configuring a static IP address on your Ubuntu machine is the way to go! A static IP address eliminates the risk of IP conflicts, which can disrupt network communication. It ensures that your device is always accessible at the same address, reducing downtime. In this comprehensive guide, I’ll walk you through the step-by-step process to configure static IP address on Ubuntu system. I will also explore some best practices and common errors that can occur when configuring the static IP address.

How to Configure a Static IP Address on Ubuntu

To configure a static IP address on Ubuntu, you need administrative privileges and access to a functional network interface. Ensure there are available IP addresses within the network’s range to avoid conflicts. Modifying network configuration files or using the Network Manager GUI allows you to assign a stable IP address, enhancing network stability, secure hosting, and performance.

  1. Open a Terminal.
opening terminal 39
  1. Run the following command to view your current IP address:
<strong>ifconfig</strong>
  1. This will show you the IP address, subnet mask, and gateway address of your current network interface.
viewing current ip address
  1. Use the following command to list all network interfaces on your Ubuntu system:
<strong>ip link show</strong>
  1. This will show you a list of all the network interfaces on your system, including their names and status.
listing available network interface
  1. Check the status of each interface with by running the following command to ensure they are up and running.
<strong>ip a show [interface]</strong>

Replace interface with the interface name of which you want to check the status of.

checking status of network interface
  1. Know your network’s subnet mask and gateway address for proper IP assignment. Select an IP address that falls within your network’s address range but outside the DHCP pool. Avoid using IP addresses that are already assigned to other devices.
  2. Run the following command to check for any conflicting responses.
<strong>ping [static IP address]</strong>
  1. If you receive responses, the IP address is already in use, and you should choose another.
checking for ip address conflicts
  1. Run this command to list netplan configuration file:
<strong>ls /etc/netplan/</strong>
  1. The command will list the netplan configuration file.
listing netplan configuration file
  1. Now run the following command:
<strong>sudo cp /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.bak</strong>
  1. The command will create a backup of netplan configura .
creating backup of netplan configuration file

creating-backup-of-netplan-configuration-file

  1. Now execute the command:
<strong>sudo nano /etc/netplan/01-netcfg.yaml</strong>
  1. The command will open the netplan configuration file.
opening netplan configuration file
  1. Add the following lines below it, adjusting the values accordingly:
<strong>network:</strong>
<strong> version: 2</strong>
<strong>  renderer: NetworkManager</strong>
<strong>  ethernets:</strong>
<strong>   enp0s3:  # Change this to your interface name if different</strong>
<strong>     dhcp4: no</strong>
<strong>      addresses: [10.0.2.100/24]  # Replace with your desired static IP and subnet mask (e.g., "192.168.1.100/24")</strong>
<strong>      gateway4: 10.0.2.1  # Replace with your gateway address</strong>
<strong>      nameservers:</strong>
<strong>        addresses: [8.8.8.8, 8.8.4.4]  # Replace with your DNS server ad</strong>
  1. Applying Changes and Restarting the Network Service. Save the changes and exit the text editor (press Ctrl + X, then Y, and Enter).
applying changes to netplan configuration file

applying-changes-to-netplan-configuration-file

  1. Restart the networking service using the command:
<strong>sudo systemctl restart NetworkManager</strong>
  1. The command will restart the networking services.
restarting network service
  1. Run ifconfig in the Terminal to verify that the new static IP address is assigned to your network interface.
verifying configuration

3 Best Practices for Static IP Configuration

Configuring a static IP address on your network can provide numerous benefits, such as enhanced stability, secure hosting, and improved network performance. To ensure a smooth and efficient setup, it’s crucial to follow best practices that guarantee a reliable and hassle-free static IP configuration. Here are four best practices to follow:

  • 🔒 Regularly Review and Update IP Settings: As networks evolve and devices change, it’s essential to periodically review and update your static IP settings. Over time, the initial IP allocations might become inadequate or conflicting, leading to potential connectivity issues. By regularly auditing your IP address assignments, you can ensure smooth communication and prevent any unnecessary disruptions.
  • 📝 Keep a Log of Network Changes: Maintaining a detailed log of all network changes, including static IP configurations, can be invaluable in troubleshooting and resolving issues. Should any problems arise in the future, the log will serve as a comprehensive reference, allowing you to revert to previously working settings or identify the source of the problem more efficiently.
  • 🔥 Implement Additional Security Measures: While static IPs offer stability, they can also be more susceptible to targeted attacks. To enhance network security, consider implementing additional measures such as firewalls, intrusion detection systems, and access control lists. These extra layers of protection will fortify your network, safeguard sensitive data, and minimize the risk of unauthorized access.
  • 🔄 Plan for Network Scalability: As your network grows, it’s vital to plan for scalability in your static IP configuration. Ensure that the selected IP address ranges are ample enough to accommodate future expansion without causing conflicts. Proactively consider the potential addition of new devices, services, or users to avoid potential headaches down the road.

3 Common Errors in Static IP Configuration

Configuring a static IP address on your Ubuntu system can greatly improve network stability and security. However, mistakes during the setup process can lead to connectivity issues and disruptions. Here, I’ll highlight some of the most common errors encountered during static IP configuration and how to avoid them.

  • 🚫 IP Address Conflict: One of the most prevalent errors is assigning a static IP address that conflicts with an existing device on the network. This can cause communication problems and lead to intermittent connectivity. Always ensure you choose an IP address outside the DHCP pool and verify that it’s not already in use by another device.
  • ⚙️ Incorrect Network Settings: Incorrectly configuring network settings, such as the subnet mask or gateway address, can result in isolation from the network or the internet. It’s crucial to double-check and accurately enter the necessary details when setting up a static IP address. Verify the subnet mask and gateway information with your network administrator or router settings.
  • 🔌 Interface Down or Inactive: Another common error is forgetting to activate the network interface after making changes. If the interface remains down or inactive, your static IP configuration won’t take effect. Always restart the networking service or enable the interface using the appropriate commands to ensure your changes are applied correctly.
  • 📄 Typos in Configuration Files: Typos or syntax errors in configuration files, such as /etc/network/interfaces, can lead to unexpected behavior and prevent the static IP address from being applied. Carefully review the files for any errors and use a text editor that highlights syntax to avoid mistakes. Additionally, creating a backup of the original files before modification can be beneficial in case of any mishaps.

In Conclusion

I’ve provided you with a step-by-step guide to configure a static IP address on Ubuntu system, ensuring enhanced stability, security, and network performance. Alongside this guide, I’ve highlighted common errors that may occur during the process, helping you avoid potential connectivity issues. Additionally, I’ve shared essential best practices to ensure a smooth and reliable static IP configuration.

Now, if you’re eager to expand your Ubuntu networking knowledge, consider exploring these topics: Advanced Firewall Configuration for Ubuntu, Load Balancing Strategies for High-Traffic Website, and Implementing Virtual Private Networks for Secure Remote Access. Remember, the more you explore Ubuntu’s networking possibilities, the more proficient you’ll become in managing your network with confidence. So keep exploring, stay curious, and continue expanding your expertise in Ubuntu networking.

Frequently Asked Questions

Can I configure multiple static IP addresses on one Ubuntu system?

Yes, Ubuntu allows you to configure multiple static IP addresses on a single network interface through a feature called IP aliasing. By assigning additional IP addresses to the same interface, you can have multiple distinct network identities. To achieve this, edit the network configuration file, typically located at /etc/network/interfaces. Add additional configurations for each desired IP address, using the :X notation (e.g., eth0:1, eth0:2) to differentiate them. Save the changes and restart the networking service with sudo service networking restart to apply the configurations. Each alias will act as an independent static IP address on your Ubuntu system.

How do I reset my network settings to default if there’s an issue?

If you encounter network issues after configuring static IPs, fear not, as you can revert to the default network settings using the backup you wisely created. Locate the backup of your original network configuration files and restore them to their respective locations. Alternatively, open the configuration files and manually change the static IP settings back to DHCP mode. After saving the changes, restart the networking service with sudo service networking restart to activate the default network settings and resolve any issues you were facing.

Can I use a static IP address with both wired and wireless connections?

Absolutely! Ubuntu allows you to configure static IP addresses for both wired and wireless interfaces independently. You can assign a static IP address to your wired connection, typically eth0, and another static IP to your wireless connection, commonly wlan0. This flexibility comes in handy, especially when you have different network requirements for your wired and wireless connections. To configure static IPs for each interface, use either the command-line method or the Network Manager GUI, making sure to select the correct interface and enter the relevant static IP information for each connection.

Is it possible to switch back to a dynamic IP address after configuring a static IP?

Yes, you can easily switch back to a dynamic IP address after configuring a static IP on your Ubuntu system. To revert to DHCP mode, access the network configuration files (usually located at /etc/network/interfaces) and change the configurations from static to dhcp. Simply remove the lines specifying the static IP address, subnet mask, and gateway details. Save the changes and restart the networking service with sudo service networking restart. Your Ubuntu system will now acquire its IP address dynamically through DHCP, restoring its ability to receive IP assignments from the network router.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Install glibc on Ubuntu [22 Simple Steps]

Next Post

How to Verify Checksum on Linux [2 Proven Methods]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next