Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Webcast-Catalyst9k
New Member

Creating Multiple Subinterfaces (through script)

Hi,

I am attempting to create several subinterfaces on a serial port to simulate customer connections. Given this will be 50-100 subinterfaces, is there a script that can be used for this?

1 ACCEPTED SOLUTION

Accepted Solutions
New Member

Re: Creating Multiple Subinterfaces (through script)

Hold on a sec. You actually try to create a variable as a number! that's not allowed

If you want from 50 to 100 subinterfaces, the correct syntax is

#!/usr/bin/perl

for ($i = 50; $i <= 100; $i++)

{

print "int Serial0/0.$i\n";

print "ip address 192.168.1.$i 255.255.255.0\n";

print "no shut\n\n";

}

8 REPLIES
New Member

Re: Creating Multiple Subinterfaces (through script)

int range fa0/0.1 - FastEthernet 0/0.100

no shut

will create 100 sub interfaces.

Now that won't save you of putting in ip addresses on those. If you need to do that.

New Member

Re: Creating Multiple Subinterfaces (through script)

this will only work for ethernet interfaces,not serial.

New Member

Re: Creating Multiple Subinterfaces (through script)

Yep sorry..you're right.. I did not see you are looking for serial

However here is a script in perl. You need to have perl to run this. (there is a windows version called active perl. or just go on any linux and create this file and name it script.pl and execute it with : perl script.pl

#!/usr/bin/perl

for ($i = 0; $i <= 100; $i++)

{

print "int Serial0/0.$i\n";

print "ip address 192.168.1.$i 255.255.255.0\n";

print "no shut\n\n";

}

____

Modify the iteration of i according to how many ifaces you need

New Member

Re: Creating Multiple Subinterfaces (through script)

I've tried the script on a linux box

#!/usr/bin/perl

for ($50 = 0; $50 <= 100; $50++)

{

print "int Serial0/0.$50\n";

print "ip address 192.168.1.$50 255.255.255.0\n";

print "no shut\n\n";

}

I keep getting the below error

"Modification of a read-only value attempted at subint.pl line 7."

New Member

Re: Creating Multiple Subinterfaces (through script)

Hold on a sec. You actually try to create a variable as a number! that's not allowed

If you want from 50 to 100 subinterfaces, the correct syntax is

#!/usr/bin/perl

for ($i = 50; $i <= 100; $i++)

{

print "int Serial0/0.$i\n";

print "ip address 192.168.1.$i 255.255.255.0\n";

print "no shut\n\n";

}

New Member

Re: Creating Multiple Subinterfaces (through script)

thanks for that!

Ran it and worked as i was hoping for

New Member

Re: Creating Multiple Subinterfaces (through script)

Or there you go mate, an even more simple solution create a cisco.bat file in windows with this content. Play out with the for loop to generate as many interfaces as you need:

ECHO OFF

for /L %%N in (0, 1, 100) do (echo int Serial0/0.%%N

echo ip address 192.168.1.%%N 255.255.255.0

echo no shut

)

Hall of Fame Super Gold

Re: Creating Multiple Subinterfaces (through script)

For scripting in router, try "tclsh".

Although most cisco test engineers uses external tcl scripts on their workstations.

435
Views
0
Helpful
8
Replies
CreatePlease to create content