Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

How to Configure Static and Dynamic IP Address in Ubuntu

Published

Ubuntu

Network configuration is fundamental to Ubuntu system administration, determining how your system connects to networks and communicates with other devices. Proper IP address management ensures reliable connectivity for both server deployments requiring consistent network identity and desktop systems needing flexible network access. This article covers multiple methods to configure static and dynamic IP addresses in Ubuntu, including modern Netplan configuration, NetworkManager tools, and GUI methods. You will learn to implement appropriate networking solutions for different Ubuntu use cases and troubleshoot common connectivity issues.

Prerequisites

Before following this guide, ensure you have:

  • An Ubuntu system (16.04 or later)
  • Administrative privileges (sudo access)
  • Basic understanding of IP addresses and networking concepts
  • Active network interface detected by Ubuntu

Understanding Ubuntu Network Management

Ubuntu uses different network management systems depending on the version and installation type. Ubuntu 18.04 and later primarily use Netplan for network configuration, which generates backend configurations for systemd-networkd or NetworkManager. Ubuntu Desktop editions typically include NetworkManager for user-friendly network management, while Ubuntu Server installations often rely on Netplan with systemd-networkd backend. Understanding your Ubuntu setup helps determine the most appropriate configuration method.

Static IP addresses provide consistent network identity essential for servers, while dynamic IP addresses offer flexibility for desktop systems and reduce administrative overhead through automatic DHCP configuration.

Check Current Network Configuration

Examine your current network setup before making changes to understand existing configuration and identify the network interfaces available on your Ubuntu system.

  • Display network interfaces and current IP addresses.
$ ip addr show
  • Check the default route and gateway.
$ ip route show
  • Identify the network management system in use.
$ systemctl is-active NetworkManager
$ systemctl is-active systemd-networkd
  • Check if Netplan is available and configured.
$ ls /etc/netplan/
$ sudo netplan status
  • View current DNS configuration.
$ systemd-resolve --status
$ cat /etc/resolv.conf

Configure Static IP Using Netplan (Ubuntu 18.04+)

Netplan is Ubuntu’s default network configuration system for versions 18.04 and later. It uses YAML files to define network settings and generates appropriate backend configurations.

  • Identify your network interface name.
$ ip link show

Note the interface name (typically starts with enp, ens, or eth).

  • Locate existing Netplan configuration files.
$ sudo ls -la /etc/netplan/
  • Create or edit the Netplan configuration file.
$ sudo nano /etc/netplan/01-netcfg.yaml
  • Configure static IP address settings.
network:  
  version: 2  
  renderer: networkd  
  ethernets:    
    enp0s3:      
      dhcp4: no      
      addresses:        
        - 192.168.1.100/24      
      gateway4: 192.168.1.1      
      nameservers:        
        addresses: [8.8.8.8, 1.1.1.1]

Replace enp0s3 with your actual interface name and adjust IP addresses for your network.

  • Test the configuration before applying permanently.
$ sudo netplan try

This command applies the configuration temporarily and automatically reverts if not confirmed within 120 seconds.

  • Apply the configuration permanently.
$ sudo netplan apply
  • Verify the static IP configuration.
$ ip addr show enp0s3
$ ping -c 4 8.8.8.8

Configure Dynamic IP Using Netplan (Ubuntu 18.04+)

Dynamic IP configuration through Netplan enables automatic network configuration via DHCP, suitable for most desktop environments and flexible server deployments.

  • Edit the Netplan configuration file.
$ sudo nano /etc/netplan/01-netcfg.yaml
  • Configure DHCP for automatic IP assignment.
network:  
  version: 2  
  renderer: networkd  
  ethernets:    
    enp0s3:      
      dhcp4: true      
      dhcp6: false
  • Apply the DHCP configuration.
$ sudo netplan apply
  • Verify dynamic IP assignment.
$ ip addr show enp0s3
$ dhclient -v enp0s3

Configure Static IP Using NetworkManager

NetworkManager provides both command-line and graphical tools for network configuration, working across all Ubuntu versions and offering user-friendly management options.

  • Check NetworkManager status and available connections.
$ sudo systemctl status NetworkManager
$ nmcli connection show
  • Create a new static IP connection.
$ sudo nmcli connection add type ethernet con-name "Static-Connection" ifname enp0s3
  • Configure the static IP parameters.
$ sudo nmcli connection modify "Static-Connection" ipv4.addresses 192.168.1.100/24
$ sudo nmcli connection modify "Static-Connection" ipv4.gateway 192.168.1.1
$ sudo nmcli connection modify "Static-Connection" ipv4.dns "8.8.8.8,1.1.1.1"
$ sudo nmcli connection modify "Static-Connection" ipv4.method manual
  • Activate the static connection.
$ sudo nmcli connection up "Static-Connection"
  • Verify the connection status.
$ nmcli connection show --active
$ ip addr show enp0s3

Configure Dynamic IP Using NetworkManager

NetworkManager simplifies DHCP configuration through both command-line tools and graphical interfaces available in Ubuntu Desktop environments.

  • Create a new DHCP connection.
$ sudo nmcli connection add type ethernet con-name "DHCP-Connection" ifname enp0s3
  • Set the connection to use DHCP.
$ sudo nmcli connection modify "DHCP-Connection" ipv4.method auto
  • Activate the DHCP connection.
$ sudo nmcli connection up "DHCP-Connection"
  • Verify automatic IP assignment.
$ nmcli connection show "DHCP-Connection"
$ ip addr show enp0s3

Configure IP Using Ubuntu GUI (Desktop Only)

Ubuntu Desktop provides graphical network configuration through the Settings application, offering an intuitive interface for users preferring visual network management.

  • Open the Settings application.
$ gnome-control-center

Or use the GUI: Activities → Settings → Network

  • Select your network interface from the list of available connections.
  • Click the gear icon next to your connection to access detailed settings.

For static IP configuration:

      • Switch IPv4 method to “Manual”
      • Enter IP address, netmask, and gateway
      • Add DNS servers in the DNS field
      • Click “Apply” to save changes

For DHCP configuration:

    • Set IPv4 method to “Automatic (DHCP)”
    • Click “Apply” to save changes
    • Toggle the connection off and on to apply new settings.

Configure Legacy Network Interfaces (Ubuntu 16.04 and Earlier)

Older Ubuntu versions use the traditional /etc/network/interfaces file for network configuration. This method also serves as a backup option on newer Ubuntu systems.

  • Check if the legacy configuration file exists.
$ ls -la /etc/network/interfaces
  • Edit the network interfaces file.
$ sudo nano /etc/network/interfaces
  • Configure static IP using the legacy format.
# Loopback interface  
auto lo  
iface lo inet loopback  

# Primary network interface - Static IP  
auto enp0s3  
iface enp0s3 inet static     
    address 192.168.1.100     
    netmask 255.255.255.0     
    gateway 192.168.1.1     
    dns-nameservers 8.8.8.8 1.1.1.1
  • Configure DHCP using the legacy format.
# Loopback interface  
auto lo   
iface lo inet loopback  

# Primary network interface - DHCP  
auto enp0s3  
iface enp0s3 inet dhcp
  • Restart networking to apply changes.
$ sudo systemctl restart networking

Temporary IP Configuration

Configure IP addresses temporarily for testing or troubleshooting without making permanent changes to your Ubuntu system configuration.

  • Assign a temporary static IP address.
$ sudo ip addr add 192.168.1.150/24 dev enp0s3
  • Set a temporary default gateway.
$ sudo ip route add default via 192.168.1.1
  • Remove temporary IP configuration.
$ sudo ip addr del 192.168.1.150/24 dev enp0s3
$ sudo ip route del default via 192.168.1.1
  • Bring interface up or down temporarily.
$ sudo ip link set enp0s3 down
$ sudo ip link set enp0s3 up

[!WARNING] Temporary configurations using the ip command do not persist across reboots. Use permanent configuration methods for production systems.

Manage DNS Configuration

Proper DNS configuration ensures domain name resolution works correctly regardless of your chosen IP addressing method in Ubuntu.

  • Check current DNS configuration.
$ systemd-resolve --status
$ cat /etc/resolv.conf
  • Configure DNS through systemd-resolved (Ubuntu 18.04+).
$ sudo nano /etc/systemd/resolved.conf

Add DNS configuration:

[Resolve]  
DNS=8.8.8.8 1.1.1.1  
FallbackDNS=192.168.1.1  
Domains=local
  • Restart systemd-resolved service.
$ sudo systemctl restart systemd-resolved
  • Test DNS resolution.
$ nslookup google.com
$ dig ubuntu.com

Verify Network Configuration

Comprehensive verification ensures your Ubuntu network configuration functions correctly and provides expected connectivity across different network layers.

  • Check IP address assignment and interface status.
$ ip addr show
$ ip link show
  • Test local network connectivity.
$ ping -c 4 192.168.1.1
$ arp -a
  • Test internet connectivity and routing.
$ ping -c 4 8.8.8.8
$ traceroute google.com
  • Verify DNS resolution functionality.
$ nslookup ubuntu.com
$ host canonical.com
  • Check network service status.
$ sudo systemctl status NetworkManager
$ sudo systemctl status systemd-networkd
$ sudo systemctl status systemd-resolved

Troubleshoot Common Ubuntu Networking Issues

Ubuntu network configuration problems require systematic troubleshooting approaches that consider the specific networking systems and tools available in Ubuntu.

Netplan Configuration Issues:

  • Syntax errors prevent configuration application. Use sudo netplan try to test safely.
  • YAML indentation problems cause parsing failures. Ensure consistent spacing.
  • Backend conflicts occur when mixing networkd and NetworkManager renderers.

NetworkManager Connection Problems:

  • Multiple connections for the same interface can cause conflicts.
  • Permissions issues prevent connection modifications.
  • Service conflicts with other network management systems.

DNS Resolution Failures:

  • systemd-resolved may conflict with traditional /etc/resolv.conf management.
  • DNS server accessibility issues prevent domain resolution.
  • Network interface DNS settings may override system-wide configuration.

Common Troubleshooting Commands:

  • Check network service logs for error messages.
$ sudo journalctl -u NetworkManager
$ sudo journalctl -u systemd-networkd
  • Reset network configuration to defaults.
$ sudo systemctl restart NetworkManager
$ sudo systemctl restart systemd-networkd
  • Flush DNS cache and restart resolution services.
$ sudo systemd-resolve --flush-caches
$ sudo systemctl restart systemd-resolved

Best Practices for Ubuntu Network Configuration

Implement consistent network management practices that align with Ubuntu’s networking architecture and provide reliable, maintainable configurations across different deployment scenarios.

For Ubuntu Server deployments:

  • Use Netplan with systemd-networkd backend for consistent, declarative configuration.
  • Implement static IP addresses for servers requiring predictable network identity.
  • Document network configurations and maintain backup copies of working settings.
  • Test configuration changes using netplan try before permanent application.

For Ubuntu Desktop systems:

  • NetworkManager provides user-friendly network management with GUI tools.
  • Dynamic IP addressing typically offers optimal flexibility for desktop environments.
  • Use connection profiles to manage multiple network configurations.
  • Enable automatic connection for frequently used networks.

General Ubuntu networking best practices:

  • Choose one primary network management system and avoid mixing methods.
  • Implement DNS redundancy using multiple DNS servers.
  • Monitor network configuration for unauthorized changes.
  • Document network settings and maintain configuration backups.
  • Test network changes in non-production environments first.

Conclusion

Effective IP address configuration provides the foundation for reliable Ubuntu network connectivity across server and desktop deployments. You have learned comprehensive methods for configuring both static and dynamic IP addresses using Ubuntu’s primary networking systems including Netplan, NetworkManager, GUI tools, and legacy configuration methods. The verification and troubleshooting techniques you implemented ensure network configurations function correctly and provide diagnostic tools for resolving connectivity issues specific to Ubuntu environments. Your Ubuntu system now has robust network configuration capabilities appropriate for various deployment scenarios and use cases.

Regular application of these Ubuntu networking practices ensures consistent connectivity, simplified management, and optimal network performance across your Ubuntu infrastructure while maintaining compatibility with Ubuntu’s evolving network management architecture.

Related guides

Account services are unavailable until the production backend is configured.