Quick & Dirty: Ubuntu 20LTS Static IP

Submitted by Xilodyne on Mon, 09/28/2020 - 17:55

Ubuntu 20LTS static IPv4 & IPv6

In a default install of Ubuntu 20LTS, the /etc/network/interfaces file is empty.

Instead, update the /etc/netplan/00-installer-config.yaml.
Then run sudo netplan apply.

(Below, change X.X.X.40 to your IP address.)

IPv4

Add IPv4 static:  https://www.linuxtechi.com/assign-static-ip-address-ubuntu-20-04-lts/

IPv6

(This article references /etc/netplan/01-netcfg.yaml which doesn't exists, use 00-installer-config.yaml instead.)

Add IPv6 static:  https://www.transip.eu/knowledgebase/entry/3412-adding-ipv4-ipv6-address-ubuntu/?utm_source=knowledge%20base/

Failure sudo netplan apply
$ sudo netplan apply
/etc/netplan/00-installer-config.yaml:6:25: Invalid YAML: did not find expected node content:
                        ::X.X.X.40/24]

I choose to match my IPv6 (::X.X.X.40) address to my IPv4 address (X.X.X.40).  However, this doesn't work correctly in the yaml file.  It is necessary to add a zero before the IPv6 address:  0::X.X.X.40

https://github.com/getdnsapi/getdns/issues/358

 


My final version of /etc/netplan/00-installer-config.yaml (change X.X.X to your IP address).

I only use IPv6 internally, thus neither a IPv6 gateway not nameserver is configured.

/etc/netplan/00-installer-config.yaml

$ cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
            addresses: [X.X.X.40/24,
                        0::X.X.X.40/24]
            gateway4: X.X.X.1
            nameservers:
                    addresses: [4.2.2.2,
                                8.8.8.8]
  version: 2

ifconfig

$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet X.X.X.40  netmask 255.255.255.0  broadcast X.X.X.255
        inet6 ::X.X.X.40  prefixlen 24  scopeid 0x80<compat,global>
        inet6 fe80::20c:29ff:fe25:c48f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:25:c4:8f  txqueuelen 1000  (Ethernet)
        RX packets 68127  bytes 85069439 (85.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11523  bytes 1003547 (1.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 297  bytes 28838 (28.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 297  bytes 28838 (28.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0