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 liketimeout ... 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.