News & Updates

How to Assign a Static IP in Ubuntu: Easy Step-by-Step Guide

By Sofia Laurent 239 Views
how to assign static ip inubuntu
How to Assign a Static IP in Ubuntu: Easy Step-by-Step Guide

Assigning a static IP address in Ubuntu provides consistent network identification, which is essential for servers, network printers, or any device requiring reliable remote access. This configuration prevents the address from changing after a reboot or network cycle, eliminating the frustration of tracking a moving target. While Dynamic Host Configuration Protocol (DHCP) handles most client devices automatically, a static assignment gives you precise control over network parameters.

Understanding Network Profiles in Modern Ubuntu

Recent versions of Ubuntu utilize Netplan as the primary configuration framework for network management. This system translates YAML configuration files into the specific settings required by NetworkManager or systemd-networkd. Before diving into the commands, it is crucial to identify the active network interface and the Netplan profile currently governing it. Misconfiguring these files can lead to connectivity loss, so precision is key.

Identifying Your Network Interface

You must determine the exact name of your network interface, such as "ens33" or "enp0s3," rather than relying on older names like "eth0." The terminal provides direct commands to reveal this information without installing additional software. Running these commands ensures you apply the static IP to the correct physical or virtual adapter.

Checking Available Interfaces

ip link – Lists all network interfaces recognized by the kernel.

nmcli device status – Shows devices managed by NetworkManager and their state.

ls /sys/class/net/ – Displays the directory of network interfaces.

Configuring Static IP via Netplan YAML

The standard method involves editing the YAML file located in the "/etc/netplan/" directory. This file dictates how the system connects to the network upon boot. You will replace the DHCP configuration with a structured static block, defining the address, gateway, and DNS servers explicitly.

Example Netplan Configuration

Open the existing YAML file, typically named "00-installer-config.yaml," using a text editor with sudo privileges. Replace the DHCP settings with the following structure, adjusting the IP, gateway, and DNS to match your local network schema.

Configuration Parameter
Description
Example Value
addresses
The static IP and subnet mask in CIDR notation
192.168.1.100/24
gateway4
The default gateway for internet access
192.168.1.1
nameservers
DNS servers for domain resolution
8.8.8.8, 1.1.1.1

network: version: 2 ethernets: ens33: addresses: [192.168.1.100/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 1.1.1.1]

Applying the Changes Securely

S

Written by Sofia Laurent

Sofia Laurent is a Senior Editor exploring design, lifestyle, and global trends. She blends editorial clarity with a refined point of view.