Configuring a static IP address in Ubuntu provides greater control, consistency, and customization of network parameters for servers, workstations, and networking devices. This in-depth guide will cover use cases, fundamentals, step-by-step configuration using nmcli and GUI tools, troubleshooting tips, and best practices for experts.
Key Reasons to Use a Static IP Address
While dynamic IP addressing via DHCP may be preferable for client devices like laptops, utilizing a static IP address offers several key advantages:
- Consistent accessibility – Servers and devices maintain a fixed address for remote access.
- Hosting web services – Many internet servers and local servers rely on a static address that does not change.
- Network equipment configuration – Devices like routers and switches often leverage static addressing.
- Port forwarding simplicity – Forwarding ports to a static IP is much easier than to a dynamic one.
- Device communication – Static IPs help IoT gadgets, cameras, printers and other hosts reliably find each other on a LAN.
- Control – Administrators have granular control over IP parameters tailored to their network instead of relying on DHCP.
For these reasons, network engineers often configure headless servers, cloud hosts, on-premise hardware, and networking gear to leverage static IP addresses instead of dynamic ones.
IP Addressing and Subnetting Fundamentals
Before diving into the steps on setting a static IP, it helps to have a solid grasp of some key IP addressing fundamentals.
IP addresses consist of four octets – or eight binary bits – separated by periods. An example address could be 192.168.1.25. Each octet represents a number from 0 to 255 in decimal notation.
The first 3 octets (192.168.1) comprise the network ID, identifying the network that a device or host belongs to. This is also referred to as the subnet. The last octet (25) denotes the host ID, representing the individual device or host IP address on that network.
A subnet mask accompanies the IP address, indicating which portion belongs to the network ID and which portion is the host. A common subnet mask is 255.255.255.0 (or /24 in CIDR notation). This means the first 24 bits are for the network 192.168.1, and the last 8 bits represent the host. By analyzing the subnet mask, devices can understand the network/host split.
A default gateway is also key. This is the IP address that the Ubuntu system will use to communicate with other networks outside its own LAN subnet.
With this foundation, we can now assign our Ubuntu server or workstation a static IP address tailored to our network, define the appropriate subnet mask, and specify the correct gateway router for external communication.
Step By Step Guide – Using nmcli
The NetworkManager CLI tool nmcli allows full control over network interfaces and connections directly from Ubuntu‘s terminal. Follow this step-by-step guide to configure an Ethernet static IP address using nmcli.
- First, open a new terminal window by pressing Ctrl+Alt+T or searching for "Terminal" from Ubuntu‘s application menu.
- Before making any changes, identify your current network interface name with the command:
nmcli device status
This will list all current interfaces and their state. Identify the wired interface, which is typically "eth0" or "enp0s3". Make a note of this device name.
- Optionally, view full configuration details of your current wired connection:
nmcli connection show "Wired connection 1"
Substitute your connection‘s specific name. This will indicate if DHCP is currently assigning a dynamic address.
- Next, add a new Ethernet connection profile with a static IP address assigned to your noted network device:
sudo nmcli connection add type ethernet con-name static-ip ifname enp0s3 ip4 192.168.1.25/24 gw4 192.168.1.1
Customize the connection name, interface name, desired static IP address, subnet mask, and gateway address to match your network. The ip4 parameter configures the IPv4 method as manual instead of automatic DHCP.
- You can also configure DNS servers on the new connection:
sudo nmcli connection modify static-ip ipv4.dns "8.8.8.8 8.8.4.4"
Substitute alternate public DNS servers or your own local DNS IPs instead.
- In order for the changes to take effect, restart the NetworkManager service:
sudo systemctl restart NetworkManager.service
This will terminate all active connections and reinitialize them, loading your new static IP profile.
- Check that the profile is now listed in nmcli:
nmcli connection show static-ip
It should display the connection name, static IP parameters, subnet mask, gateway, and DNS servers defined earlier.
- Finally, clean up old connection profiles by deleting them:
sudo nmcli connection delete "Wired connection 1"
This helps avoid conflicts with the newly defined static connection.
After following these nmcli steps, your Ubuntu server or desktop should now utilize your configured static IP address instead of DHCP.
Verifying the Static IP Address
To validate everything is working as expected:
ip addr show dev enp0s3 ping google.com -I enp0s3
The ip command prints details on your network interfaces, including the assigned IP address. Ping verifies connectivity to the internet or other networks through that interface using the static IP.
You can also reboot the server or desktop and check nmcli again:
nmcli device status nmcli connection show static-ip
The new connection should remain intact with your defined static configuration still applied as shown in the output.
Step By Step Guide – Using Ubuntu Desktop‘s GUI
For those that prefer a graphical interface, Ubuntu Desktop includes a Network Manager app with a simple panel for modifying wired and wireless connections. Here is how to set a static IP address using the Network Manager GUI.
- Click the WiFi/Network icon in the top right toolbar, then select Network Settings.
- Locate the correct wired connection for the Ethernet interface, and click the gear icon to edit the connection.
- Select the IPv4 tab, then change the Method dropdown from "Automatic (DHCP)" to "Manual".
- Enter your desired static IP address, network subnet mask, gateway address, and DNS server IP addresses. For example:
- Address: 192.168.1.75
- Netmask: 255.255.255.0
- Gateway: 192.168.1.1
- DNS: 8.8.8.8
- Click Apply when complete editing the connection.
- Toggle the connection Off then On again to restart the networking service and apply the changes.
The Network Manager app will write the new IP configuration to the connection profile file used by Netplan when rendering network configurations.
You can confirm everything is working by inspecting ip addr show dev enp0s3 again and issuing test pings to verify connectivity like in the nmcli section above.
Ubuntu Server Static IP Configuration
The Network Manager tools work well for Ubuntu Desktop and also Ubuntu Server editions when utilizing a desktop environment. But Ubuntu Server by default runs headless without a GUI. In that case the recommended approach is editing Netplan YAML configuration files directly.
Netplan oversees rendering network configurations on each boot. To assign a static IP address, create a new YAML file under /etc/netplan with contents like:
network:
version: 2
ethernets:
enp1s0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
This configures an IPv4 static IP address, subnet mask, gateway and DNS servers for the enp1s0 wired interface. Additional parameters like DHCP enabling/disabling, VLANs, and links to physical ports can also be configured.
After editing Netplan configs, run:
sudo netplan apply
To parse the YAML and update systemd-networkd with the rendered network configurations. Reboot to verify settings persist as expected.
The key difference from Network Manager is that Netplan configurations are more server-focused and continue to apply on boot instead of reliance on the NetworkManager service.
Dynamic vs Static IP Addressing
It helps to compare some key differences between dynamic IP assignment via DHCP vs manually configured static IP addresses:
| Dynamic IP (DHCP) | Static IP | |
|---|---|---|
| IP Address | Automatically assigned from a DHCP server, subject to change | Manually defined by administrator and persistent |
| Control | DHCP server governs scope, leases, and recycling | Complete administrator control over IP and subnet |
| Configuration | No manual intervention needed on client | Manual subnetting and IP address selection |
| Setup Simplicity | Very easy, no additional changes | Increased complexity especially for servers |
| Accessibility | Unpredictable if IP address changes | Persistent accessibility at a fixed address |
In summary, DHCP is simpler for clients but static IPs facilitate greater control, consistency and reliability for long-running servers and infrastructure. Both dynamic and static IP assignment have their appropriate use cases.
The Role of NetworkManager Service
Ubuntu‘s NetworkManager service oversees tracking, maintaining, and controlling network configurations including both wired and wireless connections. It aims to autoconfigure networking appropriately while allowing administrative overrides via methods like nmcli when manual control is preferred.
The key functions include:
- Profiles – Stores details on saved wired, WiFi, and other connections for different network interfaces.
- DHCP – Automatically assigns dynamic IP addresses by default via DHCP agents.
- DNS management – Configures DNS server IP assignments per connection.
- Traffic routing – Manages traffic routing rules between different interfaces.
- Firewall zones – Classifies connections by trust levels to integrate with the UFW firewall.
- Status monitoring – Tracks current state of all network interfaces.
- IP configuration – Applies static IPs or DHCP assigned addresses to reboot persistently.
When modifying an Ubuntu network configuration manually like when assigning a static IP, the NetworkManager service reloads the updated connection profiles. This allows changes to take effect immediately without a system reboot.
However for servers, networking is instead configured via Netplan YAML at the system level on each boot rather than relying on the NetworkManager service.
Troubleshooting Tips for Networking Issues
In the event of network connectivity issues after configuring a static IP address, first determine if the problem is specific to that Ubuntu server/workstation or more general:
Server-Specific Troubleshooting
- Check ip addr output – Verify static IP and subnet mask are correctly assigned to the server‘s network interface.
- Ping loopback and gateway – Test connectivity to 127.0.0.1 and the default gateway router.
- Inspect logs – Check syslog and NetworkManager logs for related errors applying configurations.
- Review configs – Confirm static IP, subnet mask, DNS servers, gateway IP are all correctly specified.
- Disable firewall – Temporarily stop UFW firewall to isolate networking issues.
Address any server-specific configuration or connectivity issues found through testing and log inspection.
Network-Wide Issues
If the problem impacts more than just a single Ubuntu system:
- Ping tests – Attempt pings to static server IP from different points on LAN.
- DHCP servers – Validate DHCP servers have accessible address pools not conflicting with static IPs.
- Switch/router config – Inspect configurations for issues like incorrect VLAN trunking.
- Cabling tests – Check for loose patch cables or failing ports.
- Power cycling – Power cycle switches/routers and other network hardware as a last resort.
For wide network outages, physical and external factors should be investigated alongside individual system configurations.
In many cases, properly analyzing IP address assignments, gateway connectivity, DNS resolution, routing tables, and observing error logs will uncover root cause. Understanding the downstream impact allows resolving whether issues are localized or more expansive.
Conclusion
While Ubuntu Linux desktops and servers default to DHCP for dynamically assigning IP addresses, moving to a static IP address offers advantages like consistency, customization, hosting flexibility and control. This guide explored numerous use cases for static IPs, provided key foundational networking knowledge, and demonstrated step-by-step configuration procedures using both nmcli and Ubuntu‘s GUI network manager. Additional tips covered verifying correct assignment, contrasting differences between static and dynamic IPs, the role of NetworkManager, and both server-specific and network-wide troubleshooting techniques. Configuring static addressing on Ubuntu is straight-forward, especially when armed with this exhaustive reference guide.


