Static IP and routes with netplan on Ubuntu
-
Phase 0: Before you start
-
Phase 1: The origins and OS architecture
-
Phase 2: Day-to-day administration and the command builder
-
Phase 3: Enterprise infrastructure and storage
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Every Ubuntu server you meet at work gets its address from a small YAML file, and setting a netplan static IP means writing that file correctly and applying it without cutting off your own SSH session. One wrong space in that file and the server either refuses the change or comes back with no network at all.
In Lesson 31 you did the same job on Rocky Linux with nmcli. Now you’ll do it the Ubuntu way on ubu01: read the file the installer wrote, rewrite it with a static address, a default route, an extra route and DNS, check it with netplan generate, and apply it with netplan try so a mistake rolls itself back after two minutes.
Where this lesson fits
Lesson 32 of 82 in Linux Administration · Phase 2: Day-to-day administration and the command builder · Before this: Lesson 31, static IP and routes with nmcli · Next: Lesson 33, SSH keys and hardening
| Time | You need | By the end you can |
|---|---|---|
| About 50 minutes | ubu01 (Ubuntu Server 26.04 LTS from Lesson 2), its VirtualBox console window open as a fallback, and an SSH session as student | Write a netplan file with a static IP, a default route, an extra route and DNS, apply it safely with netplan try, and read the error messages when the YAML is wrong |
What it is, in one line
netplan reads YAML files in /etc/netplan, turns them into settings for systemd-networkd or NetworkManager, and those programs put the address, routes and DNS on the network card.
In Simple Words
The tiffin order slip
Think of a tiffin service in your colony. You don’t walk into the kitchen and cook; you fill a slip that says your flat number, how many rotis and which sabzi, and the kitchen staff read the slip and pack the box.
If you write “rotis” in the wrong column or leave the flat number blank, the manager sends the slip back before anything is cooked. And a good manager lets you taste the first box and send it back within two minutes if it’s wrong, so you’re never stuck with a bad lunch.
The netplan file is the slip, systemd-networkd is the kitchen, and netplan try is that two-minute taste test.
Engineer's View
What netplan is and what it writes
netplan isn’t a network daemon. It’s a translator: netplan generate reads every *.yaml file in /lib/netplan, /etc/netplan and /run/netplan (in that order of priority, files merged in name order), and writes config files for a renderer. On Ubuntu Server the renderer is systemd-networkd and the files land in /run/systemd/network/.
On Ubuntu Desktop it’s NetworkManager, and netplan writes /run/NetworkManager/system-connections/ instead.
| YAML key | What it sets | Example on ubu01 |
|---|---|---|
network: version: 2 | The schema version, always 2 | top of every file |
renderer | Which backend applies it (networkd or NetworkManager) | left out on servers, networkd is the default |
ethernets: enp0s3: | One block per network card, by interface name | enp0s3 is VirtualBox NIC1 |
dhcp4: false | Turns DHCP for IPv4 off | static address only |
addresses: | A list of IP/prefix entries; the prefix is required | 10.10.10.21/24 |
routes: | A list of routes, each with to and via | to: default via 10.10.10.1 |
nameservers: | DNS servers and search domains for this link | 10.10.10.1, saatlab.test |
Three version details matter at work. gateway4 still works but has been deprecated for years and prints a warning; write a route with to: default instead. netplan wants the YAML files readable by root only (mode 600) and warns when they aren’t. And on Ubuntu 26.04 (netplan 1.2) the commands you’ll use are generate, try, apply, get and status.
Cloud images add one more layer. cloud-init writes /etc/netplan/50-cloud-init.yaml from the cloud’s metadata and can rewrite it at boot. A server built from the Ubuntu ISO, like ubu01, normally has cloud-init networking switched off by a file in /etc/cloud/cloud.cfg.d/ that contains network: {config: disabled}. If that file is missing, your edits can be overwritten on the next boot.
How it works, step by step
Here is what happens between saving a YAML file and the address showing up on the card. The diagram below shows the full path.
1You write YAML in /etc/netplan
Files are read in name order, so 50-cloud-init.yaml is read before 60-office.yaml, and a later file can add to or override keys from an earlier one. Indentation is the structure: two spaces per level, never tabs. A key in the wrong column belongs to a different parent and means something else, or nothing.
2netplan generate translates it
generate parses every file, checks the keys and values, and stops with the file name, line and column if anything is wrong. When the YAML is valid it writes one .network file per interface into /run/systemd/network/. Nothing has changed on the card yet.
3netplan apply hands it to the renderer
apply runs generate, then tells systemd-networkd to reload. networkd reads the new files and changes the address, routes and DNS on the live interface. systemd-resolved picks up the DNS servers and search domains for that link.
4The kernel holds the result
What you see with ip addr and ip route is the kernel’s table, filled in by networkd. Routes networkd adds show proto static; the subnet route that comes with the address shows proto kernel.
5netplan try adds a safety net
try does the same as apply, then waits 120 seconds (change it with --timeout). If you press Enter, the new config stays. If you don’t, because your SSH session froze after a wrong address, netplan puts the old config back on its own.
The picture below compares the commands and when to use each one.
6Check what is live, not what is written
A file can be correct and still not be applied, or applied and then overwritten by cloud-init. After every change, read the live state: ip -br addr, ip route, resolvectl status enp0s3 and netplan status. If the live state and the file disagree, the file isn’t what’s running.
One limit to remember: try can’t roll back changes to bonds and bridges, so it refuses those and tells you to use apply directly. For those, always work from the VirtualBox console or the server’s remote console (iLO, iDRAC), never from an SSH session that runs over the link you’re changing.
Hands-on lab: give ubu01 a static IP, an extra route and DNS with netplan
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the server name, the user, the disk or device name, the path and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
You’ll work on ubu01 as student with sudo. Keep the VirtualBox console window of ubu01 open next to your SSH session: if the network change goes wrong, you log in there and fix it. Take a snapshot first (VBoxManage snapshot ubu01 take before-l32 on the laptop).
The address stays 10.10.10.21, so the rest of the course still works when you finish.
1Read what the installer wrote
Run this:
ls -l /etc/netplan/
sudo cat /etc/netplan/50-cloud-init.yaml
ip -br addr show enp0s3You should see something like this:
total 4
-rw------- 1 root root 249 Oct 21 10:14 50-cloud-init.yaml
network:
version: 2
ethernets:
enp0s3:
addresses:
- "10.10.10.21/24"
nameservers:
addresses:
- 10.10.10.1
search:
- saatlab.test
routes:
- to: "default"
via: "10.10.10.1"
enp0s3 UP 10.10.10.21/24 fe80::a00:27ff:fe5e:7d21/64The installer turned your answers from Lesson 2 into YAML: one address, DNS 10.10.10.1 with the search domain saatlab.test, and a default route. The file is mode 600 (root only), which is what netplan expects. Some installs name it 00-installer-config.yaml instead; use whatever name ls shows in every command below.
✅ Checkpoint: You can point at the address, the gateway and the DNS server in the file, and ip shows the same address on enp0s3.
2Find out who owns the file
Run this:
grep -r "config: disabled" /etc/cloud/cloud.cfg.d/
networkctl listYou should see something like this:
/etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg:network: {config: disabled}
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 enp0s3 ether routable configured
2 links listed.The first line says cloud-init won’t touch networking on this server, so editing 50-cloud-init.yaml is safe. If grep prints nothing (common on cloud images and VM templates), create the switch yourself before you edit anything:
echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfgnetworkctl answers the second question: enp0s3 is “configured” by systemd-networkd, so networkd is the renderer here.
✅ Checkpoint: You know whether cloud-init can rewrite your netplan file, and networkctl shows enp0s3 as routable and configured.
3Back up and write the new file
Paste this whole block:
sudo cp /etc/netplan/50-cloud-init.yaml /root/50-cloud-init.yaml.$(date +%Y%m%d).bak
sudo tee /etc/netplan/50-cloud-init.yaml >/dev/null <<'EOF'
network:
version: 2
ethernets:
enp0s3:
dhcp4: false
addresses:
- 10.10.10.21/24
routes:
- to: default
via: 10.10.10.1
- to: 10.50.0.0/16
via: 10.10.10.1
nameservers:
search: [saatlab.test]
addresses: [10.10.10.1]
EOF
sudo chmod 600 /etc/netplan/50-cloud-init.yaml
sudo ls -l /root/*.bak /etc/netplan/You should see something like this:
-rw------- 1 root root 249 Oct 27 11:02 /root/50-cloud-init.yaml.20261027.bak
/etc/netplan/:
total 4
-rw------- 1 root root 307 Oct 27 11:02 50-cloud-init.yamlThe backup goes to /root, not /etc/netplan, because netplan reads every .yaml file in that folder and a copy named 50-cloud-init.yaml.bak is harmless but a copy named old.yaml would be applied too. The new file adds dhcp4: false to make the intent clear, and a second route: traffic for 10.50.0.0/16 (say, the office network) goes via 10.10.10.1. In a real data centre that would be a different router; the lab only has one, but the route still shows up and gets used.
Try it yourself: build this netplan file for your own interface and addresses in the Command Builder.
✅ Checkpoint: The backup exists in /root and the new file is mode 600.
4Check it with netplan generate
Run this:
sudo netplan generate && echo "YAML OK"
sudo cat /run/systemd/network/10-netplan-enp0s3.networkYou should see this:
YAML OK
[Match]
Name=enp0s3
[Network]
LinkLocalAddressing=ipv6
Address=10.10.10.21/24
DNS=10.10.10.1
Domains=saatlab.test
[Route]
Destination=0.0.0.0/0
Gateway=10.10.10.1
[Route]
Destination=10.50.0.0/16
Gateway=10.10.10.1No warnings and “YAML OK” means the file parsed cleanly. The second command shows the translation: each YAML route became a [Route] section for networkd, and the search domain became Domains. This is the file networkd will read, which is useful when you want to know what netplan asked networkd to do.
✅ Checkpoint: generate prints nothing before “YAML OK”, and the .network file has two [Route] sections.

5Apply safely with netplan try
Run this, then press Enter when the countdown starts:
sudo netplan tryYou should see something like this:
Do you want to keep these settings?
Press ENTER before the timeout to accept the new configuration
Changes will revert in 108 seconds
Configuration accepted.try applied the config and started the 120-second countdown. Your SSH session kept working, so you pressed Enter and netplan kept the new settings. Had the session frozen, you’d do nothing: after two minutes netplan prints “Reverting.” and puts the old config back, and your SSH session comes back on its own.
On a remote server this is the command to use every time.
✅ Checkpoint: netplan printed “Configuration accepted.” and your SSH session is still alive.
6Read the live routes and DNS
Run this:
ip route
ip route get 10.50.1.10
resolvectl status enp0s3 | head -n 6You should see something like this:
default via 10.10.10.1 dev enp0s3 proto static
10.10.10.0/24 dev enp0s3 proto kernel scope link src 10.10.10.21
10.50.0.0/16 via 10.10.10.1 dev enp0s3 proto static
10.50.1.10 via 10.10.10.1 dev enp0s3 src 10.10.10.21 uid 1000
cache
Link 2 (enp0s3)
Current Scopes: DNS
Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 10.10.10.1
DNS Servers: 10.10.10.1
DNS Domain: saatlab.testBoth routes are in the kernel with proto static, which means networkd added them from your file. ip route get asks the kernel “which way would you send this packet?” and the answer is via 10.10.10.1, out of enp0s3, from 10.10.10.21. resolvectl shows DNS 10.10.10.1 and the search domain on this link, so ping rocky01 would try rocky01.saatlab.test too.
✅ Checkpoint: ip route shows the default route and 10.50.0.0/16, both proto static.
7Ask netplan what it thinks is live
Run this:
sudo netplan get ethernets.enp0s3.routes
netplan status enp0s3You should see something like this:
- to: "default"
via: "10.10.10.1"
- to: "10.50.0.0/16"
via: "10.10.10.1"
Online state: online
DNS Addresses: 127.0.0.53 (stub)
DNS Search: saatlab.test
● 2: enp0s3 ethernet UP (networkd: enp0s3)
MAC Address: 08:00:27:5e:7d:21 (Intel Corporation)
Addresses: 10.10.10.21/24
fe80::a00:27ff:fe5e:7d21/64 (link)
DNS Addresses: 10.10.10.1
DNS Search: saatlab.test
Routes: default via 10.10.10.1 (static)
10.10.10.0/24 from 10.10.10.21 (link)
10.50.0.0/16 via 10.10.10.1 (static)
fe80::/64 metric 256netplan get reads the merged YAML (all files together), which is how you check what a stack of files adds up to. netplan status reads the live state from networkd and the kernel and shows it next to what netplan manages. The 127.0.0.53 at the top is systemd-resolved’s local stub, which forwards to 10.10.10.1.
✅ Checkpoint: Both routes appear in netplan get and in the Routes lines of netplan status.
8Prove the change survives a reboot
Run this:
sudo reboot
# log in again after about 30 seconds, then:
ip -br addr show enp0s3; ip route | grep 10.50You should see something like this:
enp0s3 UP 10.10.10.21/24 fe80::a00:27ff:fe5e:7d21/64
10.50.0.0/16 via 10.10.10.1 dev enp0s3 proto staticSame address and the extra route is back, so the file is what the server boots with and cloud-init left it alone. Most “the IP changed after the patch reboot” tickets come from skipping this step.
✅ Checkpoint: After the reboot ubu01 is still 10.10.10.21 with the 10.50.0.0/16 route.
Break It, Then Fix It
Take a snapshot of ubu01 first (VBoxManage snapshot ubu01 take before-l32-break). Do these from the VirtualBox console window or with netplan try, so a bad config can’t cut you off. Work on a copy of the file in each step and restore the good one at the end.
1Indent with a tab
Many editors put a tab when you press the Tab key. Make that mistake on purpose:
sudo sed -i 's/^ dhcp4: false/\tdhcp4: false/' /etc/netplan/50-cloud-init.yaml
sudo netplan generateYou’ll get this error:
/etc/netplan/50-cloud-init.yaml:5:1: Invalid YAML: tabs are not allowed for indent:
dhcp4: false
^YAML allows only spaces for indentation, and netplan points at line 5, column 1, where the tab is. Nothing was applied, because generate stopped first. A space too many or too few gives “inconsistent indentation” with the same file, line and column format.
Fix: replace the tab with six spaces and check again. In vim, :set expandtab and :retab do it for the whole file.
sudo sed -i 's/^\tdhcp4: false/ dhcp4: false/' /etc/netplan/50-cloud-init.yaml
sudo netplan generate && echo "YAML OK"YAML OK✅ Checkpoint: generate prints “YAML OK” again.
2Use the wrong key name
Change addresses to address (it’s an easy slip):
sudo sed -i 's/^ addresses:$/ address:/' /etc/netplan/50-cloud-init.yaml
sudo netplan generateYou’ll get this error:
/etc/netplan/50-cloud-init.yaml:6:7: Error in network definition: unknown key 'address'
address:
^netplan only accepts the keys in its schema, and it tells you the one it didn’t know. Writing nameserver: instead of nameservers: gives the same kind of error, and an address without a prefix, like 10.10.10.21, gives “address ‘10.10.10.21’ is missing /prefixlength”.
Fix: use the documented key names (man netplan or the YAML reference linked below).
sudo sed -i 's/^ address:$/ addresses:/' /etc/netplan/50-cloud-init.yaml
sudo netplan generate && echo "YAML OK"YAML OK✅ Checkpoint: generate is clean again.
3Copy an old guide that uses gateway4
Many blog posts still show this. Write it to a test file and generate:
sudo cp /etc/netplan/50-cloud-init.yaml /root/good.yaml
sudo tee /etc/netplan/50-cloud-init.yaml >/dev/null <<'EOF'
network:
version: 2
ethernets:
enp0s3:
dhcp4: false
addresses: [10.10.10.21/24]
gateway4: 10.10.10.1
nameservers:
addresses: [10.10.10.1]
EOF
sudo chmod 600 /etc/netplan/50-cloud-init.yaml
sudo netplan generateYou’ll get this warning:
** (generate:2214): WARNING **: 11:24:05.172: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.It still works today, which is why people ignore it, but deprecated keys get removed in some release, and a server that’s fine now fails after an upgrade. It also hides the extra route you wrote earlier, because this version of the file doesn’t have one.
Fix: put the good file back.
sudo cp /root/good.yaml /etc/netplan/50-cloud-init.yaml
sudo chmod 600 /etc/netplan/50-cloud-init.yaml
sudo netplan generate && echo "YAML OK"✅ Checkpoint: No gateway4 warning, and sudo grep -c "to: default" /etc/netplan/50-cloud-init.yaml prints 1.
4Leave the file world-readable
Run this:
sudo chmod 644 /etc/netplan/50-cloud-init.yaml
sudo netplan generateYou’ll get this warning:
** (generate:2231): WARNING **: 11:26:41.903: Permissions for /etc/netplan/50-cloud-init.yaml are too open. Netplan configuration should NOT be accessible by others.netplan files can hold Wi-Fi passwords and VPN keys, so netplan wants them readable by root only. It still applies the file, which is why this warning sits unnoticed on many servers until a security scan flags it.
Fix:
sudo chmod 600 /etc/netplan/50-cloud-init.yaml
sudo netplan generate && echo "YAML OK"✅ Checkpoint: generate prints only “YAML OK”.
5Apply a wrong gateway and let try save you
Change the gateway to an address nobody has, then try it and press nothing:
sudo sed -i '0,/via: 10.10.10.1/s//via: 10.10.10.254/' /etc/netplan/50-cloud-init.yaml
sudo netplan try --timeout 30
# in a second terminal or the console, within 30 seconds:
ping -c 2 -W 2 1.1.1.1You should see something like this:
Do you want to keep these settings?
Press ENTER before the timeout to accept the new configuration
Changes will revert in 1 seconds
Reverting.While the countdown ran, the ping to the internet failed (100% packet loss), because the default route pointed at 10.10.10.254. You didn’t press Enter, so netplan restored the previous state from its own backup. Note that try put the old state back on the card, but your edited file is still on disk, so the next boot or apply would use it.
Fix: put the gateway back in the file and apply it.
sudo cp /root/good.yaml /etc/netplan/50-cloud-init.yaml
sudo chmod 600 /etc/netplan/50-cloud-init.yaml
sudo netplan try✅ Checkpoint: ip route shows default via 10.10.10.1 and ping -c 2 1.1.1.1 works.
This happened at work
The box office server that changed its address
My team lead tells this one about a cinema ticketing app in Ahmedabad. Bookings for a big Friday release were opening at 6 p.m. on Thursday, and that afternoon the team had patched and rebooted the API servers one by one. Three came back fine.
The fourth came back with a 10.20.x address from DHCP instead of its static one, so the load balancer marked it down and the payment gateway, which only accepted callbacks from listed IPs, would have rejected it anyway.
The first guess was the patch. Someone opened the netplan file and found it correct: static address, routes, DNS. They ran netplan apply from the console and the right address came back, and everyone relaxed until a second reboot that evening did the same thing again.
This server had been built from a cloud image template, not the ISO, and nobody had switched off cloud-init networking. At every boot cloud-init rewrote 50-cloud-init.yaml with DHCP from the template’s metadata, and the hand-edited static config lived only until the next reboot. The other three servers had been built from the ISO, which is why only one misbehaved.
They added 99-disable-network-config.cfg with network: {config: disabled}, rewrote the file, rebooted twice to prove it, and checked the other templates the same night. The build checklist now ends with “reboot and compare ip addr with the netplan file”, and the template itself has cloud-init networking off.
Common mistakes and troubleshooting
| Mistake | What happens | What to do instead |
|---|---|---|
| Indenting with tabs or uneven spaces | “tabs are not allowed” or “inconsistent indentation”, nothing applied | Two spaces per level; set your editor to insert spaces |
netplan apply over SSH on a remote server | A wrong address or route cuts your session and you need the console | Use netplan try, which reverts after 120 seconds unless you press Enter |
Copying gateway4 from an old guide | Deprecation warning now, breakage after a future upgrade | Use routes with to: default and via |
Keeping a backup copy as .yaml in /etc/netplan | netplan reads it too and merges it with the real file | Keep backups in /root or name them with a non-yaml ending |
| Editing 50-cloud-init.yaml on a cloud image without switching cloud-init off | The file is rewritten at the next boot | Add network: {config: disabled} in /etc/cloud/cloud.cfg.d first |
| Leaving the file mode 644 | “Permissions … are too open” warning and a finding in security scans | chmod 600 every file in /etc/netplan |
| Trusting the file instead of the live state | The file is right but something else is running | Check ip route, resolvectl and netplan status after every change |
Interview questions
Click a question to open it. Each one is written the way an interviewer would ask it. Under it you will see why they ask it and one way you could answer, in your own words.
Fresher level
1. How do you set a static IP on an Ubuntu server? Walk me through it.
Why they ask this: They want to hear the file, the keys and the apply step, and whether you know the safe way to apply over SSH.
How you might answer: I edit the YAML in /etc/netplan, for example 50-cloud-init.yaml, set dhcp4: false, add the address with its prefix like 10.10.10.21/24, a route with to: default and via the gateway, and nameservers. I keep the file mode 600.
Then I run sudo netplan generate to catch YAML errors and sudo netplan try to apply it, pressing Enter only when my SSH session still works. Last I check ip route and resolvectl status.
2. What is the difference between netplan try and netplan apply?
Why they ask this: A simple question that shows whether you have applied network changes on a remote server without a console.
How you might answer: apply makes the change straight away and keeps it. try makes the same change but waits, 120 seconds by default, for me to press Enter, and puts the old config back if I don’t.
So on any server I reach over the network I use try. I use apply from the console, or for bonds and bridges where try refuses because it can’t roll those back.
2–5 years experience
3. A server you configured with a static IP comes back on DHCP after every reboot. What do you check?
Why they ask this: They’re testing whether you know about cloud-init and the layers above netplan, which trips up many people on cloud images.
How you might answer: My first suspect is cloud-init rewriting 50-cloud-init.yaml at boot. I’d look in /etc/cloud/cloud.cfg.d for a file with network: {config: disabled} and check the netplan file’s timestamp after a reboot.
If cloud-init is the cause, I add the disable file, rewrite the YAML and reboot to prove it. I’d also run netplan get to see whether another YAML file in /etc/netplan or /run/netplan is merging in a dhcp4: true.
4. How would you add a route to 10.50.0.0/16 through a second router on Ubuntu, and prove the server uses it?
Why they ask this: They want the YAML syntax and a way to verify routing that goes beyond “I can see it in the file”.
How you might answer: I’d add an entry under routes with to: 10.50.0.0/16 and via the router’s address, on the interface in the same subnet as that router, then generate and try.
To prove it, ip route should show it with proto static, and ip route get 10.50.1.10 should name that router as the next hop. Then I’d test the real path with tracepath or a connection to a host in that network.
Senior level
5. You must change the IP of 30 Ubuntu servers in one evening. How do you plan it so you don’t lose any of them?
Why they ask this: Seniors are expected to think about rollback, console access and automation, not only the YAML.
How you might answer: I’d confirm console access (iLO, iDRAC or the hypervisor) for every server first, and lower DNS TTLs a day before. The new YAML would come from a template through Ansible, with netplan generate run as a check before anything is applied.
On each server I’d apply with netplan try or a scheduled revert, update DNS and the load balancer, and verify from a separate host. I’d do a small batch first, and keep the old files in /root so rolling back is a copy and an apply.
6. Ubuntu has netplan, RHEL has NetworkManager keyfiles. How would you keep network config consistent across a mixed estate?
Why they ask this: They want to see whether you understand what each layer does and can design one source of truth.
How you might answer: Underneath, both end up as addresses and routes in the kernel, so I’d keep the intent (IP, prefix, gateway, routes, DNS) in one inventory, like Ansible host vars or a CMDB, and render it per OS: netplan YAML on Ubuntu, nmcli or keyfiles on RHEL 9 and 10.
I’d also standardise the checks, ip route and ip route get plus a DNS lookup, so verification is the same on both families even though the config files differ.
Quick quiz
Q1. Where does netplan write config for systemd-networkd on Ubuntu Server?
/etc/systemd/network//run/systemd/network//etc/netplan/backend//var/lib/netplan/
Show answer
B — generate writes files like 10-netplan-enp0s3.network into /run/systemd/network/.
Q2. What replaces the deprecated gateway4 key?
- gateway: 10.10.10.1
- A route with to: default and via: 10.10.10.1
- default-gateway: 10.10.10.1
- nameservers: gateway
Show answer
B — Default routes are written under routes with to: default.
Q3. You run netplan try and your SSH session freezes. What happens if you do nothing?
- The server reboots
- The new config stays forever
- After the timeout, netplan puts the old config back
- netplan deletes the YAML file
Show answer
C — try waits 120 seconds by default for Enter and reverts if it doesn’t get it.
Q4. netplan generate prints “Invalid YAML: tabs are not allowed for indent”. What do you do?
- Run netplan apply anyway
- Replace the tab with spaces at the line and column shown
- Change the file to mode 777
- Reinstall netplan
Show answer
B — YAML indentation must be spaces; the message gives the file, line and column.
Q5. Which file setting stops cloud-init rewriting the netplan file at boot?
network: {config: disabled}in /etc/cloud/cloud.cfg.d/renderer: networkddhcp4: falsechmod 600on the YAML
Show answer
A — That cloud-init setting switches off its network config; the others are netplan settings.
Quick recap
- netplan translates YAML in /etc/netplan into systemd-networkd (server) or NetworkManager (desktop) config.
- A static setup is
dhcp4: false, addresses with a prefix, routes withto: default, and nameservers; keep the file mode 600. netplan generatechecks the YAML,netplan tryapplies with a 120-second rollback,netplan applyapplies for good.- Error messages give file, line and column: tabs, wrong indentation and unknown keys are the usual causes.
- On cloud images, switch off cloud-init networking or your file is rewritten at boot.
- Check the live state with
ip route,ip route get,resolvectlandnetplan status, and reboot once to prove it.
Next lesson
Lesson 33: SSH keys, config file and hardening → You’ll create the ed25519 key that the rest of the course uses, log in from ubu01 to rocky01 without a password, write an SSH config file, jump through ubu01 from your laptop, and switch off password logins safely.
Further reading: netplan static IP
Want to go deeper into netplan static IP? Read the netplan YAML reference, the Ubuntu Server networking guide, the netplan-try man page and cloud-init’s network configuration page. You can also see the full plan for this course on the undefined course page.
