Trace: linux_reference

LINUX REFERENCE

The Linux Command Line (ebook - authoritative)

Set a static IP

1. Install network-manager if it’s not already installed:

sudo apt install -y network-manager

2. Get the current IP address and the name of the Ethernet interface

ip a

3. Ping the desired static IP address to make sure some other machine isn’t already using it. (Command below assumes a desired IP address of 10.10.10.111)

ping -c 8 10.1.1.111

4. If a machine responds to the pings, find it, and shut it down (if it’s using back with

(Assuming an interface name of enp1s0)

Setting a Static IP Address on Ubuntu Server

Ubuntu Server 22.04/24.04LTS uses a utility called ‘netplan’ for networking. To set a static IP we need to edit the config file.

sudo nano /etc/netplan/0[hit tab to autocomplete whatever the filename is]

The static IP config should look similar to this:

network:
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 10.1.11.88/24
      nameservers:
        addresses: [1.1.1.2,9.9.9.9,8.8.8.8]
      routes:
        - to: default
          via: 10.1.1.1
  version: 2

Save the file and exit

Run the following command to set the permissions for the config file:

sudo chmod 0600 /etc/netplan/00-installer-config.yaml

To apply the changes run the following command:

 
sudo netplan apply

To confirm the settings, run the following to see the current IP:

ip addr show eth0

Run the following to see the default gateway:

ip route show

Run the following command to see the DNS servers being used:

resolvectl status

File/directory permissions/ownership