M HYPE SPLASH
// news

How do I set a static IP in Ubuntu 20.04.3 LTS?

By Abigail Rogers

I'm trying to set up a lab computer as a ssh server following this guide. One of the steps is setting up a static IP address. So, I was glad to find this answer. Following it, I created /etc/netplan/50-cloud-init.yaml file, pasted

network: ethernets: enp0s3: addresses: [desired_ip_address/24] gateway4: my_router_ip_address dhcp4: no nameservers: addresses: [1.1.1.1,8.8.8.8] optional: true version: 2

and run

sudo ip addr flush my_ethernet_num
sudo systemctl restart networking.service

where my_ethernet_num == enp9s0. Buuuut, after this ip a showed no ip address for the Ethernet:

svyatoslav@svyatoslav-desktop ~> ip a (base)
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: enp9s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether a8:a1:59:4b:e8:bb brd ff:ff:ff:ff:ff:ff
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:f3:38:2f:33 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever

and sudo lshw -C network yielded *-network DISABLED. Then I tried to use that guide (section 'Static IP Address Assignment'). I created /etc/netplan/99_config.yaml, pasted the necessary code, run sudo netplan apply. Nothing changed except that I STOPPED SEEING wired connections in network settings... I tried the answer from here, and the 'Wired' section returned. But I can't change anything (for example, I can't pick 'Manual' option).

Screenshot

So, the questions are: how can I return the ability of changing it (in order to follow one more guide), or is there any other solution that will succeed in setting static ip address?...

--EDIT from 12/05/2021--

Here are all of my .yaml files showed by ls -al /etc/netplan:

01-network-manager-all.yaml:

# Let NetworkManager manage all devices on this system
network: version: 2 renderer: NetworkManager

50-cloud-init.yaml:

network: ethernets: enp0s3: adresses: [192.168.0.116/24] gateway: 93.175.20.231 dhcp4: no nameservers: addresses: [1.1.1.1,8.8.8.8] optional: true version: 2

99_config.yaml:

network: version: 2 renderer: networkd ethernets: eth0: addresses: - 192.168.0.116/24 gateway4: 192.168.0.1 nameservers: search: [mydomain, otherdomain] addresses: [192.168.0.1, 8.8.8.8]
10

1 Answer

Pick ONE of the following two configurations...


Server installation with static IP...

Delete /etc/netplan/01-network-manager-all.yaml

Delete /etc/netplan/50-cloud-init.yaml

Edit /etc/netplan/99_config.yaml to look EXACTLY like this...

Note: regarding 192.168.0.116, make sure this address is outside of the DHCP range set in your router, and is not already used elsewhere.

Note: For DNS nameservers, settle on servers from one source... Google, Cloudflare, OpenDNS, etc. (3 max).

network: version: 2 renderer: networkd ethernets: enp9s0: addresses: [192.168.0.116/24] gateway4: 192.168.0.1 nameservers: addresses: [192.168.0.1, 8.8.8.8] optional: true

sudo netplan generate

sudo netplan apply

reboot


Desktop installation with static IP...

Delete /etc/netplan/50-cloud-init.yaml

Delete /etc/netplan/99_config.yaml

Edit /etc/netplan/01-network-manager-all.yaml to look EXACTLY like this...

Note: Use the NetworkManager GUI to setup your static IP for "Wired Connection".

# Let NetworkManager manage all devices on this system
network: version: 2 renderer: NetworkManager

sudo netplan generate

sudo netplan apply

reboot


Note: See for examples and design info about netplan.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy