DEV Community

Cover image for Netplan: Set static IP address
Sergio Peris
Sergio Peris

Posted on • Originally published at sertxu.dev

Netplan: Set static IP address

In order to set a static IP address to an interface using Netplan, we have to edit the desired Netplan yaml file.

Here is an example for configuring the interface eth0 with a static IP address.

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            dhcp4: false
            dhcp6: false
            addresses:
                - 192.168.1.100/24
            routes:
                - to: default
                  via: 192.168.1.1
            nameservers:
                addresses: [1.1.1.1, 8.8.8.8]
Enter fullscreen mode Exit fullscreen mode

Here we're setting the IP 192.168.1.100 as the static IP, 192.168.1.1 as the gateway, 1.1.1.1 and 8.8.8.8 as the DNS servers.

To apply the changes, we should run the command:

netplan apply
Enter fullscreen mode Exit fullscreen mode

Top comments (0)