How to know the network name

Little Girl littlergirl at gmail.com
Sat Oct 23 18:36:25 UTC 2021


Hey there,

Jerry Geis wrote:

>I need to know the correct ens4 type network name so when the
>machine reboots and tries to install Ubuntu 20.04 with a static
>address - all is correct. How do I get  that name?

This command will give it to you, although it's at least a little bit
clumsy and could be done more elegantly:

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 searches for BROADCAST and finds a line of
	  content containing the 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 and leaves you with your iface.

Those last two cuts are the clumsy part that someone more well-versed
in Bash could probably rewrite into one step.

-- 
Little Girl

There is no spoon.




More information about the ubuntu-users mailing list