Assigning a static IP address is an effective way to maintain consistent network identification for your Ubuntu systems. It provides reliability and control compared to dynamic addressing.

In this comprehensive 2600+ word guide, we will dig deep on configuring static IPs for both Ubuntu 18.04 desktop and server deployments.

Overview of Static vs Dynamic IP Addressing

By default, Ubuntu and most operating systems utilize dynamic IP assignment. This means your machine is automatically allocated an IP address by the network DHCP server when connecting.

The IP address can change on every reconnect – there is no permanency. This introduces certain downsides:

  • Lack of reliability: Applications relying on the system‘s IP for access can break when it changes
  • Difficulty directly addressing systems
  • Central DHCP server dependency

Static IP addressing provides benefits:

  • IP persistence across reboots
  • Fixed identification simplifies access to servers/services
  • Reduced reliance on DHCP servers
  • Custom network scheme flexibility

Common use cases taking advantage of these pros include:

  • Web/application servers
  • Database servers
  • Network devices like routers or print servers
  • IoT devices managed through a fixed control system
  • Workstations requiring secured access restrictions

We will focus on manually specifying a static IP that does not change to provide these advantages.

How IP Addressing Works on Ubuntu

Before diving into configuration, let‘s briefly discuss how Ubuntu handles IP assignment and network interfaces. This will provide essential background for configuring static IPs successfully.

Network Interfaces

The network interface represents your machine‘s connection to a computer network. This acts as an inlet/outlet enabling communications by assigning an IP address and routing packets.

You can inspect your current network interfaces using ip link:

$ ip link

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:8f:4a:3e brd ff:ff:ff:ff:ff:ff

This reveals two interfaces:

  • lo – The local loopback adapter used for internal communications.
  • ens160 – The physical ethernet interface connected to my network.

We will configure ens160 with our static IP. The name will likely differ on your Ubuntu OS.

Netplan vs NetworkManager

Ubuntu uses two primary network configuration systems:

Netplan – Applies network settings during initialization to ensure early availability. Uses YAML-based configuration files under /etc/netplan.

NetworkManager – A service that manages networks post-boot and can reapply changes on the fly. Used primarily on Ubuntu desktops.

So Netplan handles initial interface configuration, while NetworkManager enables dynamically reconfiguring connections after startup. We will leverage both for setting static IPs.

Configuring a Static IP on Ubuntu Desktop

The desktop version includes a GUI network dashboard that interfaces with NetworkManager. We can utilize this to easily assign our static IP address visually.

Accessing the Network Settings GUI

To open network settings on Ubuntu desktop:

  1. Go to Settings > Network
    • Alternatively right-click the connectivity icon for settings
  2. Identify the correct interface under Connections (likely "Wired Connection")
  3. Click the gear icon to adjust properties

You will be presented with the edit view:

Ubuntu Network Settings GUI

We need to switch the IPv4 configuration to manual mode.

Assigning a Static IPv4 Address

With the connection open in editing mode:

  1. Go to the IPv4 tab
  2. Change the IPv4 Method dropdown to Manual
  3. Enter your preferred static IP address details:
    • Address: 192.168.1.10
    • Netmask: 255.255.255.0
    • Gateway: 192.168.1.1
  4. Disable automatic DNS
  5. Add your chosen DNS servers – I‘m using Google‘s here
  6. Click Apply to save

Configuring a Static IP

These network changes do not apply instantly. We need to restart the interface first.

  1. Toggle Off and On the connection to restart networking
  2. Reopen settings and confirm static IP details match what you entered

With that your Ubuntu desktop now has a persistent static IP address assigned!

Setting a Static IP for Ubuntu Server

For Ubuntu Server we will directly configure the underlying Netplan network definition.

Editing the Netplan Configuration File

All network configs are handled through Netplan on server installs. To assign our static IP:

  1. Find your network interface name:

     $ ip link

    Mine is ens160 – yours may differ.

  2. Open the netplan config file to edit:

     $ sudo nano /etc/netplan/50-cloud-init.yaml 
  3. Modify the YAML file to match:

     network:
         version: 2
         ethernets:
             ens160:
                 addresses: [192.168.1.10/24]
                 gateway4: 192.168.1.1
                 nameservers:
                    addresses: [8.8.8.8,8.8.4.4]
  4. Save changes and exit the file

This configures the server‘s network interface statically.

Applying Netplan Config Changes

For any edits made to take effect:

$ sudo netplan apply

Now restart networking or reboot to have settings applied.

Confirm everything looks correct:

$ ip addr show ens160

You should see the statically assigned IP populated.

And our Ubuntu server now utilizes persistent static addressing!

Deploying Static IPs at Scale

When dealing with larger server deployments, manually managing static IPs does not scale well. We can improve this by automating configuration across nodes.

Configuration Management Tools

Powerful infrastructure automation tools like Ansible, Puppet or Chef allow codifying then pushing network changes:

# Ansible playbook example 

- name: Configure static IP
  become: true
  ansible.builtin.netplan:
     network:
         version: 2 
         ethernets:
             eth0:
                 addresses:
                   - 192.168.1.10/24
                 gateway4: 192.168.1.1
                 nameservers:
                     addresses: 
                       - 8.8.8.8
                       - 8.8.4.4
     state: present

This allows reliable control over static IPs enterprise-wide.

Cloud-Init for Cloud VMs

Cloud-Init is a widely used initialization system across cloud platforms like AWS, GCP and Azure. It applies early network customization for VMs spawned in these environments.

We can provide a cloud-init config on first boot to assign our static IP:

cloud_config.yaml

network: 
    version: 2
    ethernets:
        eth0:
            addresses: [192.168.1.10/24]
            gateway4: 192.168.1.1
            nameservers: 
                addresses: [8.8.8.8,8.8.4.4]               

Where this file gets consumed by the cloud provider to statically set our IP out-of-the-box on cloud VMs.

Troubleshooting Static IP Assignment Issues

Sometimes configuring a fixed IP does not work as expected. Let‘s discuss some common problems and how to debug them.

Connectivity Working But IP Not Static

If you can connect but notice your IP keeps changing on reconnects, double check:

  • DHCP vs static mixed config – Set ONLY a static IP, no dynamic as well
  • NetworkManager overriding – Disable NM management if configuring via Netplan

Restart networking and clear any old leases for a fresh binding.

No Connectivity After Changes

More commonly the static IP gets set incorrectly causing total disconnect.

Verify you have the right:

  • Gateway IP matching the network subnet range
  • Correct interface name
  • Valid DNS server IPs
  • Network cable firmly plugged in!

Also try restoring a dynamic IP first to eliminate other network issues.

Use ip addr, ping and netplan --debug apply to inspect currently applied configurations.

Issues Persist After Reboots

If problems recur across restarts, the IP may get overwritten somewhere:

  • Double check /etc/netplan and /etc/network/interfaces for mismatches
  • Comment out configurations in either location while testing to isolate

Boot problems are almost always incorrect network definitions conflicting. Streamline your config to one authoritative location.

Restarting networking and then the systemd-networkd/NetworkManager services after simplifying usually resolves netplan + networking service fights.

Additional Advanced Static IP Configuration

Beyond the basics, we can utilize some additional Netplan capabilities for further network control including:

Multiple IP Assignments

Adding multiple IPs to an interface for multi-homed routing:

network:
    ethernets:
        ens192:
            addresses:
              - 192.168.20.5/24
              - 10.10.10.5/32

Bonding Interfaces

Bind multiple physical NICs into a single logical interface for improved performance/redundancy.

network:
    version: 2
    ethernets:
       bond0:
          macaddress: 00:01:02:03:04:05
          bonded-interfaces:
            - eno1
            - eno2
          addresses: [192.168.0.10/24]
          gateway4: 192.168.0.1
          nameservers:
             addresses: [8.8.8.8, 8.8.4.4]

Bridges + VLANs

Segment networks virtually over the same physical layer 2 infrastructure:

network:
    version: 2
    ethernets:
        eno1:
            dhcp4: false
            bridges:
                br0:
                    addresses: [172.16.0.4/16]
                    id: br0
                    vlan: 20
                    mtu: 1500  
                    dhcp4: false

This gives you advanced modeling capabilities fully configurable from Netplan!

Conclusion

After reading this extensive guide, you should feel empowered configuring persistent static IP addresses within Ubuntu – improving reliability and admin control.

We covered the major methods for both desktop and server variants, along with scale and automation concerns around efficient deployment. Troubleshooting advice assists debugging common misconfigurations – saving you headaches!

Reach out with any other questions setting up fixed addressing. I appreciate feedback and am happy to help explain concepts or terminology from a networking perspective.

Similar Posts