Config sub interface on Cisco Router

The configuration of the router is different when a router-on-a-stick configuration is used compared to legacy inter-VLAN routing. The figure shows that multiple subinterfaces are configured.

Each subinterface is created using the interface interface_id subinterface_id global configuration mode command. The syntax for the subinterface is the physical interface, in this case g0/0, followed by a period and a subinterface number. The subinterface number is configurable, but it typically reflects the VLAN number. In this example, the subinterfaces use 10 and 30 as subinterface numbers to make it easier to remember the VLANs with which they are associated. Subinterface GigabitEthernet0/0.10 is created using the interface g0/0.10 global configuration mode command.

Before assigning an IP address to a subinterface, the subinterface must be configured to operate on a specific VLAN using the encapsulation dot1q vlan_id command. In this example, subinterface G0/0.10 is assigned to VLAN 10.

Note: There is a native keyword option that can be appended to this command to set the IEEE 802.1Q native VLAN. In this example the native keyword option was excluded to leave the native VLAN default to VLAN 1.

Next, assign the IP address for the subinterface using the ip address ip_address subnet_mask subinterface configuration mode command. In this example, subinterface G0/0.10 is assigned the IP address 172.17.10.1 using the ip address 172.17.10.1 255.255.255.0 command.

This process is repeated for all router subinterfaces required to route between the VLANs configured on the network. Each router subinterface must be assigned an IP address on a unique subnet for routing to occur. For example, the other router subinterface, G0/0.30, is configured to use IP address 172.17.30.1, which is on a different subnet from subinterface G0/0.10.

After subinterfaces have been configured, they must be enabled.

Unlike a physical interface, subinterfaces are not enabled with the no shutdown command at the subinterface configuration mode level of the Cisco IOS software. Entering the no shutdown command at the subinterface level has no effect. Instead, when the physical interface is enabled with the no shutdown command, all the configured subinterfaces are enabled. Likewise, if the physical interface is disabled, all subinterfaces are disabled. In this example, the command no shutdown is entered in interface configuration mode for interface G0/0, which in turn, enables all of the configured subinterfaces.

Individual subinterfaces can be administratively shut down with the shutdown command.

If you are familiar with switches and VLANs you might know that you require a router if you want to communicate between VLANs. In this lesson, I’ll show you how you can use a router connected to a single switch as a “router on a stick”.





This is the topology we’ll use:

Config sub interface on Cisco Router

On the switch we have VLAN 10 and VLAN 20 and there’s only a single cable between the router and switch. The router needs access to both VLANs so the link between the router and switch will be a trunk!

It’s possible to create sub-interfaces on a router. These are virtual interfaces and on each sub-interface we can configure an IP address, basically it looks like this:

Config sub interface on Cisco Router

You can pick any number that you like but I decided to use the VLAN numbers, one sub-interface for VLAN 10 and another for VLAN 20.




Here’s what the configuration looks like on the router:

R1(config)#interface fastEthernet 0/0 R1(config-if)#no shutdown R1(config-if)#exit R1(config)#interface fastEthernet 0/0.10 R1(config-subif)#encapsulation dot1Q 10 R1(config-subif)#ip address 192.168.10.254 255.255.255.0 R1(config-subif)#exit R1(config)#interface fastEthernet 0/0.20 R1(config-subif)#encapsulation dot1Q 20 R1(config-subif)#ip address 192.168.20.254 255.255.255.0

Above you can see my two sub-interfaces and the IP addresses that I assigned to them. IP address 192.168.10.254 will be the default gateway for computers in VLAN 10 and 192.168.20.254 for computers in VLAN 20.

One important command is the encapsulation dot1Q. There is no way for our router to know which VLAN belongs to which sub-interface so we have to use this command. Fa0/0.10 will belong to VLAN 10 and Fa0/0.20 to VLAN 20. Let’s check the routing table:

R1#show ip route Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level ia - IS-IS inter area, * - candidate default, U - per-user static o - ODR, P - periodic downloaded static route Gateway of last resort is not set C 192.168.10.0/24 is directly connected, FastEthernet0/0.10 C 192.168.20.0/24 is directly connected, FastEthernet0/0.20

You can see both sub-interfaces in the routing table. This allows the router to route between the two VLANs. That’s all there is to it! Configure your computers so that the router’s IP address for the corresponding VLAN is their default gateway and you are ready to go.

Configurations

Want to take a look for yourself? Here you will find the final configuration of each device.

R1

hostname R1 ! interface FastEthernet0/0 no ip address duplex auto speed auto ! interface FastEthernet0/0.10 encapsulation dot1Q 10 ip address 192.168.10.254 255.255.255.0 ! interface FastEthernet0/0.20 encapsulation dot1Q 20 ip address 192.168.20.254 255.255.255.0 ! end

SW1

hostname SW1 ! interface FastEthernet0/1 switchport trunk encapsulation dot1q switchport mode trunk ! interface FastEthernet0/2 switchport access vlan 10 switchport mode access ! interface FastEthernet0/3 switchport access vlan 20 switchport mode access ! end

HOST1

hostname HOST1 ! no ip routing ! interface FastEthernet0/0 ip address 192.168.10.1 255.255.255.0 duplex auto speed auto ! ip default-gateway 192.168.10.254 ! end

HOST2

hostname HOST2 ! no ip routing ! interface FastEthernet0/0 ip address 192.168.20.1 255.255.255.0 duplex auto speed auto ! ip default-gateway 192.168.20.254 ! end

I hope you enjoyed this lesson! If you have any more questions just leave a comment below!

How do I create a sub interface on a Cisco router?

To assign a VLAN ID to a subinterface (or to modify the VLAN ID that is currently assigned to a subinterface), use the dot1q vlan command in subinterface configuration mode. To remove the VLAN ID assigned to a subinterface, use the no form of this command. Effective with Cisco IOS XR Release 3.7.

How do I find the sub interface on my Cisco router?

How to: Cisco IOS Sub Interface Command.
Step 1: Gain Access to the router & enter Configuration Terminal. R1#configuration terminal..
Step 2: Enter the interface Desired. R1(config)#interface fastethernet 0/0..
Step 3: Assign an IP to that address (unless it already exists ) ... .
Step 4: Put in the Sub Interface Commands..

What is sub interface in router?

Subinterfaces divide the parent interface into two or more virtual interfaces on which you can assign unique Layer 3 parameters such as IP addresses and dynamic routing protocols. The IP address for each subinterface should be in a different subnet from any other subinterface on the parent interface.