Post

Set a Static IP Address on Ubuntu

This guide explains how to configure a static IP address on Ubuntu using the netplan configuration system. Setting a static IP is useful for servers or devices that need a consistent network address.


1. Locate the Network Configuration File

1
2
cd /etc/netplan/
ls

This will list the available .yaml files. Typically, there is only one file, such as 01-netcfg.yaml or a similarly named file.


2. Edit the Configuration File

Open the configuration file for editing. Replace <netcfg> with the actual filename you found in the previous step:

1
sudo nano /etc/netplan/<netcfg>.yaml

Modify the file to include the static IP configuration. Below is an example configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
network:
  version: 2
  renderer: networkd
  ethernets:
    enp5s0: # Replace with your network interface name
      dhcp4: no
      dhcp6: no
      addresses: [157.80.92.139/24] # Replace with your desired static IP and subnet mask
      routes: 
        - to: default
          via: 157.80.92.11 # Replace with your router's IP address
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4] # Replace with your preferred DNS servers

Note: Ensure that the static IP address is within the same subnet as your router and does not conflict with other devices on the network.


3. Apply the Configuration

1
sudo netplan apply

This will activate the static IP settings.


4. Verify the Configuration

To confirm that the static IP address has been applied, use the following command:

1
ip a

Reference

Ubuntu 22.04 LTSで固定IPアドレスの設定

This post is licensed under CC BY 4.0 by the author.