how to determine network device names
Ralf Mardorf
kde.lists at yahoo.com
Sun Nov 7 18:01:09 UTC 2021
Hi,
Little Girl's second option doesn't work for me. Maybe because I'm
running Ubuntu in "container".
[root at archlinux rocketmouse]# systemd-nspawn -bqD /mnt/moonstudio
[snip]
[weremouse at moonstudio ~]$ lsb_release -a
LSB Version: core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 16.04.7 LTS
Release: 16.04
Codename: xenial
On Sun, 7 Nov 2021 12:28:20 -0500, Little Girl wrote:
>ip address | grep "BROADCAST" | cut -d' ' -f2 | cut -d':' -f1
[weremouse at moonstudio ~]$ ip address | grep "BROADCAST" | cut -d' ' -f2 | cut -d':' -f1
enp3s0
>ip route | grep kernel | cut -f2 -d'/' | cut -f3 -d' '
[weremouse at moonstudio ~]$ ip route | grep kernel | cut -f2 -d'/' | cut -f3 -d' '
[weremouse at moonstudio ~]$ ip route
default via 192.168.1.1 dev enp3s0 proto dhcp src 192.168.1.4 metric 1002
192.168.1.0/24 dev enp3s0 proto dhcp scope link src 192.168.1.4 metric 1002
Little Girl's second option fixed to work for me:
$ ip route | grep default | awk '{printf $5 "\n"}'
enp3s0
Another option, I'm usually using:
[weremouse at moonstudio ~]$ basename $(ls -d /sys/class/net/enp?s0)
enp3s0
In a script e.g. like this:
dhcpcd $(basename $(ls -d /sys/class/net/enp?s0))
Something to keep in mind when using the output for scripts is, that
it's possible to have more than just one "enp*" device.
Regards,
Ralf
More information about the ubuntu-users
mailing list