NIC naming

Chad J. Milios milios at ccsys.com
Mon Oct 26 20:44:19 UTC 2015


On 10/26/2015 2:16 PM, Terje Elde wrote:
>
>> On 26 Oct 2015, at 17:30, Matthew Seaman <matthew at freebsd.org> wrote:
>>
>> This probably doesn't solve your problem, which appears to be knowing
>> which of the ethernet ports on your machine is em0 -- the usual method
>> to do that is by ifconfig'ing everything else down and then testing with
>> a network cable until you find the working port.  However it might help
>> clarify the system configuration.
> ifconfig will give you the MAC of the card. I'm not sure if there's a standard tool for it, but it should be easy to do something like "rename the card with MAC address X to Y"

you can put the following one-liner (fix if your email client breaks) 
directly into /etc/rc.conf or /etc/rc.conf.local (replace 
01:23:45:67:89:ab with your "main" card's MAC address and that interface 
will always be named, in this example net0:

eval setvar `ifconfig | while read a b; do if [ "$b" != "${b#flags=}" ]; 
then c=${a%:}; fi; if [ "$a" = ether -a "$b" = 01:23:45:67:89:ab ]; then 
echo ifconfig_${c}_name net0; fi; done`

> Personally, I've started renaming along the lines of renaming em0 to em_lan0, em1 to em_wan1 and so on. Makes it a bit easier to see what's going on, both for when another admin might inherit the box, and also for myself, if I haven't touched the box in a few years.

you may replace net0 with legal names such as up0, up1, down0, down1, 
down2, down4 (or in#, out#, wan#, lan#) etc. whatever makes most sense 
to describe your use case (just not wlan#. use wifi# or wphy# for your 
wlan#'s phy interface):

name_mac () {
eval setvar `ifconfig | while read a b; do if [ "$b" != "${b#flags=}" ]; 
then c=${a%:}; fi; if [ "$a" = ether -a "$b" = $2 ]; then echo 
ifconfig_${c}_name $1; fi; done`
}

name_mac up0 aa:aa:aa:aa:aa:aa
name_mac down0 bb:bb:bb:bb:bb:bb
name_mac down1 cc:cc:cc:cc:cc:cc

> Sure, you could argue all of this should be documented somewhere as well - and you wouldn't be wrong - but renaming makes things obvious where the next admin will look, not just in some doc that might be somewhere he didn't.
>
> Terje

-Chad J. Milios
P.S. any snippets of code contained in this email are hereby placed in 
the public domain.



More information about the freebsd-questions mailing list