Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Danny
Champion Champion
Champion
Jump to solution

One-liner for duplex settings summary

Hello CheckMates,

I'm looking for a One-liner that provides a nice summary about the duplex settings and interface driver (vendor) of every network port in a system. I offer a Thank You badge worth 500 points in rewards.

cpstat os -f ifconfig already provides a nice summary of interface statistics, though missing duplex settings and interface drivers to identify if it's an Intel or a Broadcom or other interface type.

Yuri Slobodyanyuk‌ was creating something that goes into the right direction, but his one-liner is based on ifconfig, so it doesn't show any disabled interfaces. /etc/sysconfig/hwconf or the cpstat command shown above might be a better start to get all the interfaces within a system.

I'm looking forward to your entries. The one-liner that provides the best result wins.

1 Solution

Accepted Solutions
PhoneBoy
Admin
Admin

In the interest of advancing the conversation, I will build on this a little. It's not perfect, but it gets closer to what i think you want:

[Expert@gateway:0]# ls -1 /sys/class/net | grep -v ^lo | xargs -I % sh -c 'ethtool %; ethtool -i %' | grep '^driver\|Speed\|Duplex\|Settings' | sed "s/^/ /g" | tr -d "\t" | tr -d "\n" | sed "s/Settings for/\nSettings for/g"                

Settings for eth0: Speed: 1000Mb/s Duplex: Full driver: e1000

Settings for eth1: Speed: 1000Mb/s Duplex: Full driver: e1000

Settings for eth2: Speed: 1000Mb/s Duplex: Full driver: e1000[Expert@gateway:0]#

No badges required for me Smiley Happy

View solution in original post

9 Replies
Timothy_Hall
Champion
Champion

From expert mode:

dmesg | grep ": eth" | grep -v TSO | sort | uniq
e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection
e1000: eth0: e1000_watchdog_task: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
e1000: eth1: e1000_probe: Intel(R) PRO/1000 Network Connection
e1000: eth1: e1000_watchdog_task: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None

or

grep ": eth" /var/log/messages* | grep -v TSO | cut -c66-999 | sort | uniq

 eth0: e1000_probe: Intel(R) PRO/1000 Network Connection
 eth0: e1000_watchdog_task: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
 eth1: e1000_probe: Intel(R) PRO/1000 Network Connection
 eth1: e1000_watchdog_task: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None

--
My book "Max Power: Check Point Firewall Performance Optimization"
now available via http://maxpowerfirewalls.com.

Gateway Performance Optimization R81.20 Course
now available at maxpowerfirewalls.com
Danny
Champion Champion
Champion

I've tested both One-liners on various Check Point Appliances and Open Servers without success. They don't reflect interfaces that start with names other than "eth" (e.g. Mgmt, Sync, Lan1, Lan2, ..) that somes Appliances use. But in general they don't work in most cases. Neither does dmesg contain any ": eth" entries nor does /var/log/messages always show the interface names before the Duplex setting or simply produces a big information overhead and no formatted summary. I'd still suggest that /etc/sysconfig/hwconf or the cpstat command are the best options to start from.

0 Kudos
Timothy_Hall
Champion
Champion
ls -1 /sys/class/net | grep -v ^lo | xargs -I % sh -c 'ethtool %; ethtool -i %' | grep '^driver\|Speed\|Duplex\|Settings' | tr -d "\t"  

Settings for eth0:
Speed: 1000Mb/s
Duplex: Full
driver: e1000
Settings for eth1:
Speed: 1000Mb/s
Duplex: Full
driver: e1000

--
My book "Max Power: Check Point Firewall Performance Optimization"
now available via http://maxpowerfirewalls.com.

Gateway Performance Optimization R81.20 Course
now available at maxpowerfirewalls.com
0 Kudos
PhoneBoy
Admin
Admin

In the interest of advancing the conversation, I will build on this a little. It's not perfect, but it gets closer to what i think you want:

[Expert@gateway:0]# ls -1 /sys/class/net | grep -v ^lo | xargs -I % sh -c 'ethtool %; ethtool -i %' | grep '^driver\|Speed\|Duplex\|Settings' | sed "s/^/ /g" | tr -d "\t" | tr -d "\n" | sed "s/Settings for/\nSettings for/g"                

Settings for eth0: Speed: 1000Mb/s Duplex: Full driver: e1000

Settings for eth1: Speed: 1000Mb/s Duplex: Full driver: e1000

Settings for eth2: Speed: 1000Mb/s Duplex: Full driver: e1000[Expert@gateway:0]#

No badges required for me Smiley Happy

Danny
Champion Champion
Champion

Thanks! This is extactly what I was looking for.

I've added this One-liner to our ccc-script.

0 Kudos
PhoneBoy
Admin
Admin

Give the points/badge to Tim, all I did was make the output slightly prettier. Smiley Happy

0 Kudos
Danny
Champion Champion
Champion

I gave Tim a badge with 1000 points.

nmelay
Collaborator

Here's a somewhat cleaned-up version, and restricted to real NICs only (skips bonds, VLANs, loopback) :

 

[Expert@gateway:0]# ls /sys/class/net | xargs -I % sh -c "[ -e /sys/class/net/%/device ] && (ethtool % | egrep 'Settings|Speed|Duplex' | sed -r 's/\!( \(255\))?//'; echo -e '\t'; ethtool -i % | grep driver) | tr -d '\n' && echo"
Settings for Mgmt:      Speed: 1000Mb/s Duplex: Full    driver: igb
Settings for eth1:      Speed: 1000Mb/s Duplex: Full    driver: igb
Settings for eth2:      Speed: 1000Mb/s Duplex: Full    driver: igb
Settings for eth3:      Speed: Unknown  Duplex: Unknown driver: igb
Settings for eth4:      Speed: 1000Mb/s Duplex: Full    driver: igb
Settings for eth5:      Speed: 1000Mb/s Duplex: Full    driver: igb

 

And here's a more complete version (not sure this still registers as a one-liner though :P) :

 

[Expert@gateway:0]# (echo Interface Link Speed Duplex Auto-neg Driver; for n in /sys/class/net/*; do [ -e $n/device ] && (n=${n/*\/}; echo $(echo $n; e=$(ethtool $n); for i in 'Link detected' Speed Duplex 'Auto-negotiation'; do echo "$e" | sed -n "/\t$i: /{s///;s/\!//;s/ (255)//;p}"; done; ethtool -i $n | sed -n '/driver: /s///p')); done) | column -t
Interface  Link  Speed     Duplex   Auto-neg  Driver
Mgmt       yes   1000Mb/s  Full     on        igb
eth1       yes   1000Mb/s  Full     on        igb
eth2       yes   1000Mb/s  Full     on        igb
eth3       no    Unknown   Unknown  on        igb
eth4       yes   1000Mb/s  Full     on        igb
eth5       yes   1000Mb/s  Full     on        igb

 

0 Kudos
Yuri_Slobodyany
Collaborator

Indeed old habits die hard - in the Linux world ifconfig is long gone.
A fix would be (I will update the blog post as well) to replace ifconfig with ip add :

for ii in $(ip address | awk -F: ' /UP/ {print $2}') ;do ethtool  $ii; done | egrep 'Settings|Speed|Duplex'
Settings for lo:
Settings for eth1:
        Speed: 1000Mb/s
        Duplex: Full
Settings for eth5:
        Speed: 1000Mb/s
        Duplex: Full
Settings for eth2:
        Speed: 100Mb/s
        Duplex: Full

BTW Regarding disabled/downed interfaces - I just couldn't think of possible reason to learn their state...

Thanks @https://community.checkpoint.com/people/dantr917b8439-9d5c-34f0-b86a-f0e1b0a14cbd  for reminding me I have it at all Smiley Happy .

https://www.linkedin.com/in/yurislobodyanyuk/
0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events