1

I have a Devuan system with an inconveniently large number of physical network interfaces. I occasionally have to disconnect the cables and it's a pain to make sure they get reconnected to the same interface.

I also use expressive interface names; instead of ethX I have names like intra or mgmt or someprovider, based on the purpose of the interface. These names are referenced in firewall rules etc.

I wrote a script that runs at boot and figures out which interface is plugged into what, then renames them accordingly. I'm not satisifed with this solution because it involves a lot of custom scripting; I'd like something more mainstream, if possible.

The script currently identifies networks in the following ways:

  • It can temporarily configure the interface with an address and see if it can ping or arping a specific destination (this works for uplinks -- I ping the upstream router).
  • It can listen on the interface using tcpdump to see if there is traffic from any of a number of specific MAC addresses, at least one of which will likely send something within a few seconds. I know this isn't foolproof, but it's good enough for me. (I use something like timeout ... tcpdump -c 1 -i interfacename "(ether host foo) or (ether host bar) or ...".) This works well for internal networks where I don't have anything specific to ping but where I can expect almost constant traffic.
  • It can configure a temporary IP on the interface and run nmap -sn -oG against an IP range to see how many hosts are present and reachable from that range. This is a useful heuristic for some internal networks that will contain many hosts but where I don't know for sure which ones.

I'm looking for a way to preferably integrate this with ifupdown. I've looked at mappings, but it seems to me that with a map script I can only choose a logical configuration to apply to a physical interface, not rename the interface. interfaces(5) says that Lines beginning with "rename" are used to rename interfaces. It takes one or more arguments in the form of "CUR=NEW", where CUR is the name of an existing interface, and NEW is the new name. This becomes very powerful when combined with pattern matching for the CUR interface.; however, pattern matching also doesn't help me.

If it were possible to use the result of a mapping in a rename statement somehow, that might work.

I've also looked at the whereami package, but it didn't look promising.

What I would most like is a way to have ifupdown rename a network interface based on something an if-pre-up script or a mapping script outputs.

András Korn
  • 651
  • 5
  • 15
  • Do you have a label maker? :) I'm surprised that, given those names, the switchports used are irrelevant. – Mark Wagner Jul 31 '19 at 21:48
  • 1
    I do have a label maker. :) The issue is not that I can't connect the cables to the requisite ports; it's that the box is in an awkward location and I can't really see the network ports when I plug the cables in (I'd have to use a mirror or something). The switchports are not irrelevant, but the cables stay connected to the switchports when I unplug the other end. The idea is to have the computer discover which interface is plugged into which switch and rename it accordingly. My current solution works; I'd just like to improve it. Unfortunately, most of the switches are dumb (no LLDP, no IP). – András Korn Aug 01 '19 at 08:40

1 Answers1

0

Thinking about it I've come to the conclusion that I can do this with pre-up scripts, like this:

iface intra inet static
    pre-up find-interface intra
    address ...

The find-interface script then does its magic to discover which ethX (or enX or whatever) interface should be intra, renames it, and ifupdown takes it from there.

I published my find-interface script at https://gist.github.com/akorn/7b96e78c7d1b3ca70e35261f9b1a2f2b in case anyone else finds it useful.

András Korn
  • 651
  • 5
  • 15