Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jdavidzapatab/cf5db0beb6ab4d7e90ba01033aa06a1f to your computer and use it in GitHub Desktop.
Save jdavidzapatab/cf5db0beb6ab4d7e90ba01033aa06a1f to your computer and use it in GitHub Desktop.
Configure static IP for Ubuntu 22.04

Source: https://tecadmin.net/how-to-configure-static-ip-address-on-ubuntu-22-04/

  1. Find the Newtwork Interface name
sudo ip a

Capture the network interface name. It is NOT the lo but something like eth0 or ens160.

  1. Create or Edit a Netplan configuration file
sudo vi /etc/netplan/01-netcfg.yaml

The contents should be like this:

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            addresses:
                - 192.168.1.70/24
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
            routes:
                - to: default
                  via: 192.168.1.1

Notice here the eth0. Replace it with your network interface name. Also, set the static IPv4 address in the addresses section, with the correct submask bits size (/24 in this case). The correct IP to set depends on your network configuration so use one that works for you. Also in the routes section, in via, set the correct IPv4 for your Gateway (Router).

  1. Apply the netplan changes
sudo netplan apply 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment