Friday, 5 September 2008

Two useful network-related commands

mtrudel@laptopl-mtrudel:~$ sudo ethtool eth0
[sudo] password for mtrudel:
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pumbag
Wake-on: g
Current message level: 0x00000001 (1)
Link detected: yes


ethtool is a command that gives you information on the capabilities of your network card, and the network that it is connected to. The most interesting things are the Speed and Duplex lines, which are somewhat useful when diagnosing some very specific problems. Some people may already know of mii-tool which is also available on default installs of ubuntu, however, you should know that mii-tool doesn't support Gigabit ethernet, and as such may give you weird results in that case. ethtool, on the other hand, works fine on gig.

Another cool command I found out about recently, is an implementation of a CDP listener on linux: cdpr. cdpr is available with a simple sudo apt-get install cdpr. cdpr listens for CDP advertisements coming from Cisco hardware, which will let you know what switch you are connected to, some additional information about the switch, and more importantly, which port you are connected in. That's pretty neat for large offices, especially if you're not sure where all the wired are going, and which is which when in a wiring cabinet. To use cdpr:

mtrudel@laptopl-mtrudel:~$ sudo cdpr
cdpr - Cisco Discovery Protocol Reporter
Version 2.2.1
Copyright (c) 2002-2006 - MonkeyMental.com

1. eth0 (No description available)
2. tun0 (No description available)
3. any (Pseudo-device that captures on all interfaces)
4. lo (No description available)
Enter the interface number (1-4):1
Using Device: eth0
Warning opening device (arptype 65534 not supported by libpcap - falling back to cooked socket)
Waiting for CDP advertisement:
(default config is to transmit CDP packets every 60 seconds)
Device ID
value: switch4529
Addresses
value: 192.168.45.29
Port ID
value: FastEthernet0/33


Now I'd just need to walk over to that switch to do whatever I may need to do directly on it... or telnet, ssh, or point a browser to it if I needed to change the configuration.

1 comment:

Unknown said...

ethtool is something I use on a daily basis (mii-tool is getting less useful all the time), but I had never heard of cdpr. It's always a pain to call up the network guys to trace cables or MAC's. CDP is such an obvious way to collect the data, but I never really thought about it.

I'm also intrigued by the cdprs.php script to collect data. Cool stuff. Thanks for posting.