I have a question regarding secondary IP address on a interface and about routed sub-interfaces.
Do both options accomplish the same?
Why would I add a secondary IP address on a interface? A real world example. Please explain.
If we configure an IP to an interface, we assume that all devices are part of the same network.
If I add a secondary IP to the same interface, it means we could have devices from a different network, why not using a different port?
Regarding routed sub-interface, a real wold example could be when we have multiple VLANs on a switch. We then configure the switch connection to the router as Trunk. On the router we create sub-interfaces for each VLAN to route traffic between VLANs, right? The idea to use sub-interfaces is due to not enough ports for all VLANs, am I correct?
Is there another deployment for using routed sub-interfaces besides VLANs routing?
These are two different things. Let’s look at your questions about subinterfaces first:
Yes you are correct. The topology you describe is also called “Router on a stick” and you can find out more about it at the following lesson:
Subinterfaces are also used when configuring frame relay topologies where a single serial interface must be configured to terminate multiple PVCs, where there is an IP subnet per PVC. Take a look at this lesson for such a topology:
Subinterfaces are used when you need to logically separate a physical interface into discrete logical interfaces, where each one corresponds to a particular subnet, and each one belongs to a logically separate broadcast domain/network segment.
Secondary IP addresses are different in that they can be assigned to a physical interface, but do not constitute a logically separate broadcast domain/segment. In addition, any packets generated by the Cisco IOS software exiting from that particular interface always use the primary IP address.
This Cisco documentation describes some situations in which they are useful, but they are all non-best-practice solutions. Such solutions should only be used if you need to get a network up and running quickly, and temporarily, until better network solutions can be found.
In general, don’t use secondary IP addresses, but just know they exist if you need them in a pinch.