Posted: . At: 11:16 AM. This was 6 years ago. Post ID: 12308
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Returning just the interface name with Linux.


The network adapter name is easy to return on Linux. This simple one-liner will give this information to the user.

jason@Yog-Sothoth » ~ » $ ip -o -4 route show to default | awk '{print $5}'
enp0s25

Using this information to get information about a network adapter.

jason@Yog-Sothoth » ~ » $ ethtool -T `ip -o -4 route show to default | awk '{print $5}'`
Time stamping parameters for enp0s25:
Capabilities:
	hardware-transmit     (SOF_TIMESTAMPING_TX_HARDWARE)
	software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)
	hardware-receive      (SOF_TIMESTAMPING_RX_HARDWARE)
	software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)
	software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
	hardware-raw-clock    (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
	off                   (HWTSTAMP_TX_OFF)
	on                    (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
	none                  (HWTSTAMP_FILTER_NONE)
	all                   (HWTSTAMP_FILTER_ALL)
	ptpv1-l4-sync         (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)
	ptpv1-l4-delay-req    (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)
	ptpv2-l4-sync         (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)
	ptpv2-l4-delay-req    (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)
	ptpv2-l2-sync         (HWTSTAMP_FILTER_PTP_V2_L2_SYNC)
	ptpv2-l2-delay-req    (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ)
	ptpv2-event           (HWTSTAMP_FILTER_PTP_V2_EVENT)
	ptpv2-sync            (HWTSTAMP_FILTER_PTP_V2_SYNC)
	ptpv2-delay-req       (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)

Getting IP address information from the active network adapter.

ason@Yog-Sothoth » ~ » $ ifconfig `ip -o -4 route show to default | awk '{print $5}'`
enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fdc8:1451:5fa9:4700:f50e:cce8:bb61:9131  prefixlen 64  scopeid 0x0<global>
        inet6 fdc8:1451:5fa9:4700:a099:dc55:dcdf:85be  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::79c1:da6a:20ed:3d13  prefixlen 64  scopeid 0x20<link>
        ether d0:50:99:0d:ab:0f  txqueuelen 1000  (Ethernet)
        RX packets 321273  bytes 451154182 (451.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 185381  bytes 15916566 (15.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf3900000-f3920000

How to return the MAC address of a network interface on Linux.

jason@Yog-Sothoth » ~ » $ ifconfig `ip -o -4 route show to default | awk '{print $5}'` | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
d0:50:99:0d:ab:0f

This is a long one-liner, but works very well. Would be very good to have in a script.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.