Score:0

Ubuntu 20.04 netplan static default route lost after reboot

ax flag

this is a new Ubuntu 20.04 install and I have ip and static route configured in netplan like below:

$cat /etc/netplan/lan.yaml 

network:
  renderer: networkd
  ethernets:
    lan:
      dhcp4: false 
      addresses: [10.11.1.9/16]
      nameservers:
         addresses: [10.11.1.29,8.8.8.8]
      routes: 
      - to: default 
        via: 10.11.1.1
  version: 2

I have udev rule for the lan interface

$sudo cat /etc/udev/rules.d/70-my-net-names.rules 

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="0c:c4:7a:0d:28:50", NAME="lan"

after reboot, I had to run netplan apply at command line, no error and the default route is restored. I found a few people having same issues but with different network configurations, does not seem to apply to my situation, not a netplan expert and not sure how to debug this thing when ubuntu reboot. I made a systemd service to execute netplan apply after network target as a workaround

$ sudo cat /etc/systemd/system/my-netplan.service 
[Unit]
Description=run netplan apply at startup
After=network.target
#After=network-online.target

[Service]
ExecStart=/usr/sbin/netplan apply

[Install]
WantedBy=multi-user.target
ru flag
if `lan` wasn't connected and the link state UP when you loaded up, then that's why you need to do `netplan apply` a second time. Also, you don't need `udev` rules to make this work, you can do a `match` section to match the interface MAC directly within netplan.
monkincloud avatar
ax flag
`lan` is always connected, you mean the lan link could be down at early boot stage and netplan could not apply the setting? you mean I could set the interface to custom name in netplan with `match` to the MAC address? is it the `set-name` for?
monkincloud avatar
ax flag
``` sudo cat /etc/netplan/lan.yaml network: renderer: networkd ethernets: eno1: dhcp4: false addresses: [10.11.1.9/16] match: macaddress: 0c:c4:7a:0d:28:50 set-name: lan nameservers: addresses: [10.11.1.29,8.8.8.8] routes: - to: via: 10.11.1.1 version: 2 ```
ru flag
Case in point: I have a system that does NOT keep the LAN port active when the system is off. When I turn on or reboot the system, LAN shuts and then unshuts. It's connected to a Cisco switch which tries to do STP and trunk / anti-routing-loop stuff on the port. It takes a full minute for the LAN port to go from "Negotiating" to "No response, assuming endpoint system" on the switch before it even offers the full LAN. During that minute of config, "LAN" is not 'link: UP' because the link hasn't negotiated (speed, etc.) (1/2)
ru flag
As such, it's possible your actual LAN *link* is not UP when it's being run into here. Also, you need to put your code pastes for YAML and such as edits to your question, not as comments.
us flag
why are you setting a udev rule rather than a `match:` rule in your netplan yaml to match on mac address? It's possible you're seeing an issue because of netplan and udev racing each other.
monkincloud avatar
ax flag
thanks, the problem is resolved as both of you suggested
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.