Routing – ‘interface vlanX’ or ‘interface loopbackX’

layer2layer3routingswitchvlan

VLANs are a layer 2 concept. We can all agree on that but why, then, do we use the 'interface vlanX' to allow routing on a switch. If we want to setup a default gateway for VLAN X on a Layer 3 switch would be be able to accomplish the same goal with an 'interface loopbackX' command as an 'interface vlanX' command? Aren't they both just virtual interfaces that can be used to hold IP addresses and thus route?

Best Answer

When you create 'interface vlan x' you are creating a brand new logical interface that happens to be automagically associated with the corresponding L2 vlan. When you put an IP address on 'interface vlan x' then you are simply giving that logical interface an IP that is on the same broadcast domain (or subnet or vlan or L2 domain or whatever terminology you wish to use).

A loopback interface is a virtual interface that has no such magical association. It is not associated with a vlan, nor is it associated with a physical interface.

Routing is a different function entirely though. My windows 7 computer has a few virtual IP addresses, but it is unable to route traffic thru them because I have not told it to do so. This same logic applies to network devices, you can have an IP address on 'interface vlan x' of a cisco 2960, but this is a layer 2 switch and will be unable to route traffic.