create sub interface cisco router code example

Example: cisco router command create subinterface as dot1q

!-- Set the privileged mode


!-- and Telnet password on the switch.

switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
switch(config)#hostname 3512xl
3512xl(config)#enable password mysecret
3512xl(config)#line vty 0 4
3512xl(config-line)#login
3512xl(config-line)#password mysecret
3512xl(config-line)#exit
3512xl(config)#no logging console
3512xl(config)#^Z


!-- Set the IP address and default gateway for VLAN1 for management purposes.

3512xl#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
3512xl(config)#int vlan 1
3512xl(config-if)#ip address 10.10.10.2 255.255.255.0
3512xl(config-if)#exit
3512xl(config)#ip default-gateway 10.10.10.1
3512xl(config)#end

!-- Set the VTP Mode. !-- In our example, we have set the mode to be transparent. !-- Depending on your network, set the VTP Mode accordingly. !-- For details on VTP, !-- refer to !-- Creating and Maintaining VLANs on Catalyst 2900XL and 3500XL Switches.

3512xl#vlan database
3512xl(vlan)#vtp transparent
Setting device to VTP TRANSPARENT mode.


!-- Adding VLAN2. VLAN1 already exists by default.

3512xl(vlan)#vlan 2
VLAN 2 added:
Name: VLAN0002
3512xl(vlan)#exit
APPLY completed.
Exiting....


!-- Enable trunking on the interface fastEthernet 0/1.

3512xl#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
3512xl(config)#int fastEthernet 0/1
3512xl(config-if)#switchport mode trunk


!-- Enter the trunking encapsulation as either isl

3512xl(config-if)#switchport trunk encapsulation isl

!-- or as dot1q:


3512xl(config-if)#switchport trunk encapsulation dot1q

!-- In case of 2940/2950 series switches, none of the above two commands are used, !-- 2940/2950 series switches only support 802.1q encapsulation which is configured automatically, !-- when trunking is enabled on the interface by using switchport mode trunk command. !-- In case of dot1q, you need to make sure that !-- the native VLAN matches across the link. !-- On 3512XL, by default, the native VLAN is 1. !-- Depending on your network needs, you may change !-- the native VLAN to be other than VLAN1, !-- but it is very important that you change the native VLAN !-- on the router accordingly. !-- You may change the native VLAN, if needed, by using the following command: !-- 3512xl(config-if)#switchport trunk native vlan <vlan ID> !-- Allow all VLANs on the trunk.

3512xl(config-if)#switchport trunk allowed vlan all
3512xl(config-if)#exit


!-- The following set of commands will place FastEthernet 0/2 !-- into VLAN2 and enable portfast on the interface.

3512xl(config)#int fastEthernet 0/2
3512xl(config-if)#switchport access vlan 2
3512xl(config-if)#spanning-tree portfast
3512xl(config-if)#exit


!-- FastEthernet 0/3 is already in VLAN1 by default. !-- Enable portfast on the interface.

3512xl(config)#int fastEthernet 0/3
3512xl(config-if)#spanning-tree portfast
3512xl(config-if)#^Z

!-- For details on why to enable portfast, !-- refer to: !-- Using PortFast and Other Commands to Fix Workstation Startup Connectivity Delays. !-- Remember to save the configuration.

3512xl#write memory
Building configuration...

3512xl#

--------------------------------------------------------------------------------

3512xl#show running-config
Building configuration...

Current configuration:

!
version 12.0
no service pad
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname 3512xl
!
no logging console
enable password mysecret
!
!
!
!
!
ip subnet-zero
!
!
!
interface FastEthernet0/1
  switchport mode trunk
!

!-- If 802.1Q is configured, !-- you will instead see the following output !-- under interface FastEthernet0/1: !-- interface FastEthernet0/1 !-- switchport trunk encapsulation dot1q !-- switchport mode trunk

!
interface FastEthernet0/2
 switchport access vlan 2
 spanning-tree portfast
!
interface FastEthernet0/3
 spanning-tree portfast
!
interface FastEthernet0/4
!
interface FastEthernet0/5
!
interface FastEthernet0/6
!
interface FastEthernet0/7
!
interface FastEthernet0/8
!
interface FastEthernet0/9
!
interface FastEthernet0/10
!
interface FastEthernet0/11
!
interface FastEthernet0/12
!
interface GigabitEthernet0/1
!
interface GigabitEthernet0/2
!
interface VLAN1
 ip address 10.10.10.2 255.255.255.0
 no ip directed-broadcast
 no ip route-cache
!
ip default-gateway 10.10.10.1
!
line con 0
 transport input none
 stopbits 1
line vty 0 4
 password mysecret
 login
line vty 5 15
 login
!
end