how to determine network device names

Little Girl littlergirl at gmail.com
Mon Nov 8 12:21:15 UTC 2021


Hey there,

Gene Heskett wrote:
> Little Girl wrote:

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

Ah, good to know. Thanks. I've only got one device on this machine,
so I never would have realized that.

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

Also good to know.

>Thank you for the lesson.

The same right back at you. As I mentioned above, since I've only got
one device on this machine, I didn't even realize the top one would
give you a list of multiple devices.

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

Good idea. Thanks.

-- 
Little Girl

There is no spoon.




More information about the ubuntu-users mailing list