how to determine network device names

Gene Heskett gheskett at shentel.net
Sun Nov 7 19:29:00 UTC 2021


On Sunday 07 November 2021 12:28:20 Little Girl wrote:

> Hey there,
>
> hput via ubuntu-users wrote:
> >ubuntu 21.04
> >I read that one can determine the possible name of a network device
> >by using 'lspci'
>
> [SNIP]
>
> >It seems like I should be able to piece together an enpxxx type
> >device name by extrapolating from those examples:
> >
> >I came up with `enp3s0' but of course when I try that with ifconfig.
> >
> >  ifconfig enp3s0
> >
> >I just get `error fetching interface information ... device not
> >found'
>
> Yep. That's no longer used. I've got a couple of options for you
> below, although neither of them uses lspci.
>
> This command will give it to you:
>
> ip address | grep "BROADCAST" | cut -d' ' -f2 | cut -d':' -f1
>
> How the command works:
> 	* The ip address command gets your network configuration and
> 	  passes it to the grep command.
> 	* The grep command finds a line of  content containing the
> 	  "BROADCAST" search term. It passes its findings to the first
> 	  cut command.
> 	* The first cut command removes all but the second field,
> 	  which is your iface plus a colon after it. It passes its
> 	  result to the next cut command.
> 	* The next cut command removes all but the first field, so it
> 	  removes the colon, which leaves you with your iface.

or a list of devices if there are more than one, like on a rpi4.

> This command will also give it to you:
>
> ip route | grep kernel | cut -f2 -d'/' | cut -f3 -d' '
>
> How the command works:
> 	* The ip address command gets your network routing table and
> 	  passes it to the grep command.
> 	* The grep command finds a line of content containing the
> 	  "kernel" search term. It passes its findings to the first
> 	  cut command.
> 	* The first cut command splits the input at forward
> 	  slashes and removes all but the second field, which
> 	  contains space-separated data. It passes its result to the
> 	  next cut command.
> 	* The next cut command splits the input at spaces and removes
> 	  all but the third field, which leaves you with your iface.
And this gives you the active interface's name, I presume, if its up.

Thank you for the lesson. One should, in case you have forgotten, make 
two line bash scripts out of these as they might come in handy for 
troube shooting later. call them ~/bin/list-ifaces and ~/bin-show-iface 
to differentiate between them. Don't forget to use a first line sh-bang, 
and to chmod +x both of them.

Thank you, Little Girl

Cheers, Gene Heskett.
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis
Genes Web page <http://geneslinuxbox.net:6309/gene>




More information about the ubuntu-users mailing list