03-28-2022 05:49 AM
Hi All,
I am working on a software which collects information from Cisco devices and I have a situation where the software need to differentiate between L3 Switch and L3 Router from running-config or show command.
Is there a way to distinguish between L3 Switch and L3 router by looking into the configuration file?
Since both device type run on IOS software and all the commands are same on L3 switch and L3 router.
Regards,
Madhukar
03-28-2022 06:19 AM - edited 03-28-2022 06:25 AM
Hello madhukarsaxena1991@gmail.com ,
>> Since both device type run on IOS software and all the commands are same on L3 switch and L3 router.
s there a way to distinguish between L3 Switch and L3 router by looking into the configuration file?
use show version
use show inventory
Anyway the main different in config is that :
The L3 switch is running spanning-tree the routers do not unless they have installed an "etherswitch module"
you need to get and parse outpur of show how inventory
Finally the no switchport command may be present under the routed ports.
Hope to help
Giuseppe
03-28-2022 06:19 AM
For switches you may need to validate first if they are L3 switches as many of them are not. You can look for "ipservices"
the command may vary between platform.
To differenciate Switches and Routers you can use the command "show tech" which is present in all devices and look for "Hardware:"
03-28-2022 08:27 AM
show CDP
simply it inform you that this is R or S.
03-29-2022 09:00 AM - edited 03-29-2022 09:01 AM
again check CDP, it give you the best way to identify if this Device is S or R.
03-30-2022 08:30 AM - edited 03-30-2022 09:04 AM
Yea but, this assumes your devices support CDP (should be true for [all?] Cisco devices) and if it's enabled (some security folk like to disable it, just for the fact if reveals too much information, easily).
Also, although CDP will "classify" device as a router or switch (or something else), as @Richard Burts notes, router vs. switch can be very fuzzy. Does it matter what the device "is" vs., perhaps, what it's doing?
03-30-2022 10:19 AM
The suggestion of using CDP to get classification of switch or router is creative, and is probably as close to having a single command to differentiate switch or router as we are likely to get. @Joseph W. Doherty has identified some challenges about using CDP. I believe that there is a different (and probably more important) challenge in using CDP. The original post describes running software that would connect to a device and be able to categorize that device as switch or router. What CDP does is to categorize the neighbor, but provides no information about the device on which it is running.
You could get the desired results if we significantly redesign the software. The new software would need to map the enterprise network, identifying network devices (or be provided that information as part of its implementation/configuration). It would then connect to each network device and determine who its network neighbors were. It would need to verify that the identified neighbor was a device existing in the network database, and then could use CDP to categorize the neighbor. When a device has multiple neighbors then the software would want to verify that each neighbor provided the same classification. What I have described is pretty much developing an NMS. And I do not assume that the original post is looking for an NMS solution.
Which leads me back to a point I made in a previous response. I do not believe that the original request for some single command that would characterize a device as switch or router is feasible. So I would like to understand what it is that they are attempting to accomplish and whether distinguishing between switch or router is really meaningful.
03-28-2022 08:37 AM
"Is there a way to distinguish between L3 Switch and L3 router by looking into the configuration file?"
By JUST looking at a config file? Hmm, that might be very difficult, especially if you want results to be 100% correct.
As some of the other posters have noted, there are configuration settings often seen in switches, but not routers, and the converse, but the problem is, even if some option is commonly found on one device, and uncommonly on the other, it might also be seen for the latter.
Then, there's also the problem, what's a router vs. a L3 switch. For example, Cisco used to have 6500 L3 "switches" and 7600 "routers", but they often could use some, but not all, of each other's line cards or sups, and at one point, I recall, they could actually run the same IOS image. (IMO they were, basically, the same overall hardware platform, but for marketing reasons, sold as two different device types.)
Possibly, the strongest clue, in a config file, that you're dealing with a L3 switch, rather than a router, the former often will have many more ports, especially many ports in the same port bank, e.g. g1/1/1 .. g1/1/48.
Otherwise, you'll need access to information "beyond" the config file, using various show (or equivalent SNMP) system informational commands (as suggested by the other posters). With such show commands, you should be able to have 100% accuracy what the device is (at least as far as Cisco classifies it).
03-28-2022 10:24 AM
03-29-2022 02:43 AM
Thanks Joseph for explanation.
I tried to find out a show command to differentiate both type of devices but did not found any specific command which will give 100% accurate result all time.
Example: Command - "show mac address-table"
This command show up in a Switch and not present for a Router. However if there is a switching module installed into the router, the "show mac address-table" would show you the MAC addresses.
For my software to work 100% correctly, I need a command which will always give same result no matter if router working as a switch or vice-versa.
-Madhukar
03-29-2022 03:07 AM - edited 03-29-2022 03:07 AM
As others have said there really isn't a single command that can do that for you ie. your program will have to do some of the work.
If it was me I would have a file with all possible device names and whether it is a router or switch, have your program read that in and then parse the output of "sh version" to get the device type.
Whatever you do will require some intelligence built into your program.
Jon
03-29-2022 08:57 AM
The distinction between router and Layer 3 switch is very blurred (and gets more so as Cisco produces new versions and new products). It used to be true that a fairly good distinction was whether the device supported NAT (for routers = yes and for switch = no). But that is less and less true. And there are many routers whose running config does not contain any NAT statements. So that would certainly not be a productive approach for you.
I do not believe that there is any single command that you could use that would reliably differentiate whether you are dealing with router or with Layer 3 switch. And I am not sure that there is any reasonable couple of commands that could do that. And I wonder why it is important to make the distinction? I could understand perhaps wanting a report which differentiated what type of operating system was in use. In the good old days Router or Switch was a useful distinction. In todays environment why does that matter? What would the report (or the people who read the report) do differently if it were a router or a switch?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide