How to add multiple ports to vlan on Cisco switch

KB ID 0001009 

Problem

If you have the same configuration that needs to be placed on multiple ports, then doing each one individually can be time consuming. To save time use the ‘interface range‘ command. Be aware this command is only available on devices running IOS versions newer than 12.0(7)XE, Release 12.1 E, and Release 12.1(5)T.

How to add multiple ports to vlan on Cisco switch

Solution

1. From configure terminal mode, I want to apply the same configuration to Gigabit Ethernet ports 3 and 4. Note: There is a space each side of the hyphen.

Petes-Switch(config)#interface range GigabitEthernet 0/3 - 4 Petes-Switch(config-if-range)#switchport mode access Petes-Switch(config-if-range)#switchport access vlan 123 Petes-Switch(config-if-range)#exit Petes-Switch(config)#

2. Let’s see if that worked;

Petes-Switch#show run Building configuration... Current configuration : 1888 bytes ! <------------config removed for the sake of brevity------------> ! interface GigabitEthernet0/3 switchport access vlan 123 switchport mode access ! interface GigabitEthernet0/4 switchport access vlan 123 switchport mode access ! <------------config removed for the sake of brevity------------> ! end

How To Configure Multiple Cisco ‘Non Contiguous’ Switch Ports

1. The process is the same as above, but you separate ranges, (or individual ports) with a comma. Note: There is a space each side of the comma.

Petes-Switch(config)#interface range GigabitEthernet 0/3 - 4 , GigabitEthernet 0/9 - 10 Petes-Switch(config-if-range)#switchport mode access Petes-Switch(config-if-range)#switchport access vlan 123 Petes-Switch(config-if-range)#exit Petes-Switch(config)#

2. Let’s see if that worked;

Petes-Switch#show run Building configuration... Current configuration : 1888 bytes ! <------------config removed for the sake of brevity------------> ! interface GigabitEthernet0/3 switchport access vlan 123 switchport mode access ! interface GigabitEthernet0/4 switchport access vlan 123 switchport mode access ! interface GigabitEthernet0/5 ! <------------config removed for the sake of brevity------------> ! interface GigabitEthernet0/9 switchport access vlan 123 switchport mode access ! interface GigabitEthernet0/10 switchport access vlan 123 switchport mode access ! <------------config removed for the sake of brevity------------> ! end

You can use the interface range command with the following interfaces;

  • FastEthernet
  • GigabitEthernet
  • TenGigabitEthernet
  • Port-Channel
  • VLAN

NA

  • If the switch is running IOS, then the only other option is to type your individual port configuration commands into a text file. Then you can copy/paste the contents of the text file into the CLI.

    If you use the interface range command, then the ports need to be in order.

  • its typically like this for example:

    int range gi0/1-24

    or sometimes you need spaces gi01 - 24

    Then what i do is go back and change the one or two that are different if there is a good size block of all the same vlan.

    How to add multiple ports to vlan on Cisco switch
    Spice (3) flagReport

    Was this post helpful? thumb_up thumb_down

  • As Matt stated, it is:

    int range fa0/1 - 24

    or

    int range gi0/1 - 2

    The spaces between the hyphen are usually required...

  • pretty sure you can do an "int ra gi 0/1 - 3, gi 0/5, gi 0/8, gi 0/9 - 15"

    Look at this

    Spice (2) flagReport

    Was this post helpful? thumb_up thumb_down

  • Oh and yes, you can do specific ranges with and without ports.

    For example:

    int range fa0/1 , fa0/3 , fa0/7 ,  fa0/10 - 24

    That would do ports 1, 3, 7, and 10 thru 24.

    The spaces are required between the commas and the hyphen.

  • Technically, I don't think you need a space before the comma, but you do need the spaces with the hyphens and after the comma.

  • shatteredhourglass wrote:

    pretty sure you can do an "int ra gi 0/1 - 3, gi 0/5, gi 0/8, gi 0/9 - 15"

    Look at this

    "Multiple Range" and Link to Back it up!

    Thanks that is what I was looking for!

    (yes I should also organize the ports - but this should make it more manageable!)

  • Take a look at the macros, too.  They can be very helpful!

  • shatteredhourglass wrote:

    Technically, I don't think you need a space before the comma, but you do need the spaces with the hyphens and after the comma.

    Tested on a switch, and yes, needed the spaces...

  • Derek_A wrote:

    shatteredhourglass wrote:

    Technically, I don't think you need a space before the comma, but you do need the spaces with the hyphens and after the comma.

    Tested on a switch, and yes, needed the spaces...

    Evidently that depends on version.  I tested on 12.2(53)SE2 an the space before comma was not needed.  Tested on 12.1(22)EA8a and it was required, even though the Cisco link provided states no space is needed before OR after a comma from Cisco IOS Release 12.0(7)XE, Release 12.1 E, and Release 12.1(5)T.

    Looks like someone at Cisco messed up...

    NOTE:  The link also states that you can have only (up to) 5 comma-separated ranges.

Just to add to what Mark has posted, you can have up to five parameters which can be handy when you need to skip some ports or deal with more than one line card, e.g.:

interface range g1/0/1 - 18 , g1/0/20 - 24 , g3/0/5 - 48 , g5/0/5 , g 7/0/22 - 24

PS:

You can also default interfaces using a range statement, e.g.:

default interface range g1/0/1 - 18 , g1/0/20 - 24 , g3/0/5 - 48 , g5/0/5 , g 7/0/22 - 24