0

Background

I'm currently using netplan to configure a number of Ubuntu Server 18.04 machines. I have a number of machines (specialized test units with HASP dongles installed) that are literally bolted to hand carts, and are frequently wheeled around the office(s) where they are used. Typically, I just have link-local addressing and mDNS enabled, and when an engineer takes the device to another lab and connects it to the lab switch, they can just ping the broadcast address for 169.254/16, find out the IP of the device, and proceed to use it. For reasons I'd rather not discuss, DHCP is not available under any circumstances in some labs.


Problem

We've hired some contract Windows developers that are not versed in computer networking (also the default Windows ping utility apparently can't ping broadcast addresses). We need to find a way to make it dead easy for these developers to identify the device on the network, without requiring changes to how these devices are deployed in Linux labs.

The solution that we've been tasked with implementing (i.e. I have to implement this functionality specifically, so it's not an x-y problem, for all intents and purposes), is:

  • Have DHCP enabled by default on the network interface for the device.
  • If DHCP isn't accessible, check a flag (i.e. existence of a file, for example) to decide whether to do one of the following:
    • Enable link-local addressing and mDNS, or...
    • Fall back to a default static IP address.

Question

How can I accomplish this in Ubuntu using netplan, i.e.:

  1. How would I configure netplan to attempt DHCP, and then fall back to LL/mDNS on failure?
  2. How would I configure netplan to attempt DHCP, and then fall back to a pre-defined static IP on failure?

If need be, I can live without the "act on whether or not file exists" logic (i.e. I could write some scripts to do that), but how would I configure netplan via yaml files to try to use DHCP, and then fall back to LL/mDNS or a static IP?


Work So Far

I've found various posts on the topic, but none so far that involve/require the use of netplan.

Edit: Here's a question that comes close, but only want the IP address statically assigned to the interface on DHCP lease-request failure: I don't want the IP address assigned unconditionally.


Thank you.

1

netplan does not support a fallback in the way you describe. It does support using both link-local and DHCP addresses on the same interface. (It also supports both static and DHCP addresses on the same interface, but this is a much less common configuration and you also explicitly say this is not what you want.)

To assign a static IP as a fallback, I would suggest writing your own systemd unit that runs After=network-online.target and checks whether an IP address has been assigned, assigning one yourself if not.

  • Do you have a minimal example/skeleton of such a systemd unit that operates on a single interface, i.e. eth0? – Cloud Dec 19 '19 at 2:36
  • sorry, I do not. but any series of commands you would use from the commandline to check whether the address has been assigned to the interface, and assign one if not, can be made into a script that can then be run as the ExecStart of the unit. – slangasek Dec 20 '19 at 5:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.