How to identify the switch port an interface is connected to?
Solution 1
You can use arping
(from the iputils-arping
package, in Ubuntu):
arping -I enp0s25 10.10.10.2
will ping 10.10.10.2 using ARP on interface enp0s25
, even if the interface doesn’t yet have an IP address. If you use an IP address corresponding to a machine connected to another port on your switch, you can use that to identify which port each interface is connected to: arping
will switch to unicast ARP as soon as it receives a reply.
Solution 2
I would say the best way to solve this is actually from the switch itself.
Assuming it's a cisco switch:
# starting on your linux host
ip link show # note the mac addresses
ssh ${user}@${switch} # or however you normally connect to the switch
show mac address-table address ${mac-address} # note the mac address is in a weird format ####.####.####
That will show you which port has received traffic from the corresponding mac address. You may need to cause the interface to send some traffic in order to update the mac address table (even DHCP attempt) would suffice.
You could also toggle the link lights on the switch using:
ip link set ${interface} down
To shut-down an interface, which should turn off the link light.
Then:
ip link set ${interface} up
To turn the interface back on.
Solution 3
You can use lldpctl
.
$ apt install lldpd
$ service start lldpd
$ # wait few seconds
$ lldpctl
-------------------------------------------------------------------------------
LLDP neighbors:
-------------------------------------------------------------------------------
Interface: eno1, via: LLDP, RID: 2, Time: 0 day, 00:01:34
Chassis:
ChassisID: mac xx:xx:xx:xx:xx:xx
SysName: xxx.net
SysDescr: Cisco Nexus Operating System (NX-OS) Software 7.0(3)I7(5a)
TAC support: http://www.cisco.com/tac
Copyright (c) 2002-2018, Cisco Systems, Inc. All rights reserved.
Capability: Bridge, on
Capability: Router, on
Port:
PortID: ifname Ethernet1/22 <- here is the switch port number
PortDescr: serv01
TTL: 120
VLAN: 202, pvid: yes
Unknown TLVs:
TLV: OUI: 00,01,42, SubType: 1, Len: 1 01
Related videos on Youtube
Dominick Pastore
Updated on September 18, 2022Comments
-
Dominick Pastore almost 2 years
Is there a way to send some (non-broadcast) packets out on an Ethernet interface that doesn't have an IP address assigned to it? Thus allowing me to see which light blinks on the network switch?
The issue is I have a server with three network interfaces. I know which three switch ports they are connected to, but not which interface name goes with each physical jack on the server. If they all had addresses, I could just use ping, but I was hoping to figure out which is which before I configure them. The back of the server is tough to get to, too. I'd have to move the rack. Otherwise, I could just use
ethtool -p
.Edit: This is on a Linux server. Ubuntu, to be specific, though I imagine this wouldn't be distro-specific.
-
infixed about 6 yearsI'm pretty sure that ethernet switches care more about MAC addresses than IP addresses
-
Dominick Pastore about 6 yearsMe too, which is why I assume it's possible to send packets without an IP address, but I don't know what command might do it.
-
infixed about 6 yearsBut if you send a packet with an unknown MAC, it will probably repeat it on all ports, making blink detection sort of useless. So that implies you need to send to known MAC, which would likely show on two lights.
arping
yourself? I don't know. I think a link up/down loop like Centimane's answer implies shows promise -
Dominick Pastore about 6 yearsKnown MAC is okay. I know what most of the ports on the switch are connected to, so I can just send to any of those and know which light is the unknown interface. (In fact, this is what I ended up doing.) I do like Centimane's approach too, though.
-
-
Dominick Pastore about 6 yearsAh, I tried this using
arping
from theapring
package and it sent only broadcast packets, which was not helpful. Switching to theiputils-apring
package worked. (It looks like the version in thearping
package can send unicast packets to a MAC address though, which I didn't try before installing the other.) -
Dominick Pastore about 6 years+1 This is a good option too. No need to even get up with this one. It's an HP switch though, so I'd have to look up the equivalent commands, and I already figured it out with
arping
. -
ilkkachu about 6 years@Dominick
sh mac
, and then hit tab to complete the command or see the possible arguments. Especially withshow
commands, which won't break anything, you can pretty much get to the right direction by tabbing and guessing... -
Stephen Kitt about 5 yearsThis is indeed a nice approach; given the context of the question one can assume the switch involved does support LLDP ;-). (As a side note,
apt install lldpd
will start the service for you, you shouldn’t need theservice start
command.) -
albttx about 5 yearsI had to
service start
that why i wrote it :) -
Stephen Kitt about 5 yearsThat’s weird — most Debian/Ubuntu packages automatically start their services, and I checked on a clean VM on my end (and
lldpd
was started by the package). Oh well :-/.