Skip to content

Instantly share code, notes, and snippets.

@ceccillia
Created September 18, 2023 09:54
Show Gist options
  • Save ceccillia/c058cdeff88f2c80ed5232756f7cd464 to your computer and use it in GitHub Desktop.
Save ceccillia/c058cdeff88f2c80ed5232756f7cd464 to your computer and use it in GitHub Desktop.
Set static IP ubuntu22.04

Configuring Static IP Addresses With Networkd

To configure a static IP address using the new NetPlan tool, the file should look like this: IPv4 address (192.168.1.212), Gateway (192.168.1.2), DNS Servers (8.8.8.8,8.8.4.4)

Run the commands below to create a new network configuration file

sudo vi /etc/netplan/01-netcfg.yaml

Then configure IPv4 addresses as shown below… take notes of the format the lines are written…

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

Exit and save your changes by running the commands below

sudo netplan apply

You can add IPv6 addresses line, separated by a comma.. example below.

This file describes the network interfaces available on your system

For more information, see netplan(5).

network:
 version: 2
 renderer: networkd
 ethernets:
   ens33:
     dhcp4: no
     dhcp6: no
     addresses: [192.168.1.2/24, '2001:1::2/64']
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]

Save your changes, apply and you’re done.

This is how to set static IP addresses on Ubuntu 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment