Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Oct 2015 17:05:30 -0400
From:      Jake <milios@ccsys.com>
To:        Terje Elde <terje@elde.net>, Matthew Seaman <matthew@freebsd.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: NIC naming
Message-ID:  <B088249F-6293-48CF-94C9-83E1488C5239@ccsys.com>
In-Reply-To: <562E909B.5050408@ccsys.com>
References:  <562E4D92.3000308@gmail.com> <562E551F.6060406@freebsd.org> <0746B048-19AB-4AA6-8439-4DF7A08D10AE@elde.net> <562E909B.5050408@ccsys.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
> On Oct 26, 2015, at 4:44 PM, Chad J. Milios <milios@ccsys.com> wrote:
>=20
>> On 10/26/2015 2:16 PM, Terje Elde wrote:
>>=20
>>> On 26 Oct 2015, at 17:30, Matthew Seaman <matthew@freebsd.org> wrote:
>>>=20
>>> 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 sta=
ndard tool for it, but it should be easy to do something like "rename the ca=
rd with MAC address X to Y"
>=20
> you can put the following one-liner (fix if your email client breaks) dire=
ctly 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 t=
his example net0:
>=20
> eval setvar `ifconfig | while read a b; do if [ "$b" !=3D "${b#flags=3D}" ]=
; then c=3D${a%:}; fi; if [ "$a" =3D ether -a "$b" =3D 01:23:45:67:89:ab ]; t=
hen echo ifconfig_${c}_name net0; fi; done`
>=20
>> Personally, I've started renaming along the lines of renaming em0 to em_l=
an0, 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.
>=20
> you may replace net0 with legal names such as up0, up1, down0, down1, down=
2, down4 (or in#, out#, wan#, lan#) etc. whatever makes most sense to descri=
be your use case (just not wlan#. use wifi# or wphy# for your wlan#'s phy in=
terface):
>=20
> name_mac () {
> eval setvar `ifconfig | while read a b; do if [ "$b" !=3D "${b#flags=3D}" ]=
; then c=3D${a%:}; fi; if [ "$a" =3D ether -a "$b" =3D $2 ]; then echo ifcon=
fig_${c}_name $1; fi; done`
> }
>=20
> 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
>=20
>> 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 nex=
t admin will look, not just in some doc that might be somewhere he didn't.
>>=20
>> Terje
>=20
> -Chad J. Milios
> P.S. any snippets of code contained in this email are hereby placed in the=
 public domain.
>=20

Both of those should say "elif" near the middle there instead of "fi; if" to=
 be a tiny bit faster, but either way works. Doh! I just did this little hac=
k now. I've always just went with the straight ifconfig_phy0_name=3Dnet0; if=
config_phoo0_name=3Dnet1; ifconfig_phum0_name=3Dnet2; myself and don't move c=
ards around much.=



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?B088249F-6293-48CF-94C9-83E1488C5239>