[44net] Cisco IOS Example? Sat Feb 15 22:11:18 PST 2014 The following is a good cisco example with loopback1 as your 44.X address: interface tunnel 746651648 description Link to 44.129.0.0 ip unnumbered loopback1 tunnel source OUTSIDEIPADDRESS tunnel destination 118.22.1.194 ip tcp adjust-mss 1436 tunnel mode ipip ! ip route 44.129.0.0 255.255.0.0 tunnel746651648 ! ip route 118.22.1.194 255.255.255.255 99.119.146.22 I route each gateway to my default, and any other essential routes are static assigned without a default gateway set. If I had a little more time to spend with it I would have set the 44/8 up in a VRF or did some additional policy routing to make things cleaner. I additionally wrote a script to convert the encap file to a loadable config, but the 26XXxm is short on nvram and can not save the config even with config compression enabled. I think AH6BW has a better version of this script. 73, Jason KY9J -------------- next part -------------- #!/usr/bin/perl #encapconvert.pl V0.1 10-31-12 #Script created by Jason Begley KY9J ky9j.com ky9j[at]arrl.net #This script is used for converting the encap.txt file from the AMPR net #into a loadable config file for use on cisco routers. It is advised to use #this on a 2600 or better router due to interface limits. # my ($line); my %nets = (); my $net = undef; my $mask = undef; ##### #Below are user defined varibles my $loop = "loopback1"; #LOOPBACK INT CHANGE IF ALREADY IN USE my $outip = "xxx.xxx.xxx.xxx"; #YOUR PUBLIC IP ADDRESS my $loopip = "xxx.xxx.xxx.xxx"; #YOUR AMPR IP ADDRESS #EO user defined varibles ##### my $file = $ARGV[0]; my $debug = $ARGV[1]; if(!$file) { usage(); exit; } if($file =~ /--help/) { usage(); exit; } open (MYFILE, '>cisco-config.txt'); print MYFILE "!\ninterface $loop\nip address $loopip 255.255.255.255\n!\n"; close (MYFILE); open(ENCAP, $file); @line = ; close (ENCAP); @line = grep (!/^\s*$/,@line); @line = grep (!/^#/,@line); chomp(@line); foreach $line(@line) { $n1 = $n2 = $n3 = $n4 = undef; @ln = (split(/ +/, $line)); ($n, $s) = (split(/\//, $ln[2])); ($n1, $n2, $n3, $n4) = split(/\./, $n); $gw = $ln[4]; $gw =~ s/\s*$//; if ($n1 == '') { $n1='0'}; if ($n2 == '') { $n2='0'}; if ($n3 == '') { $n3='0'}; if ($n4 == '') { $n4='0'}; if ($s == '1') { $mask='128.0.0.0'}; if ($s == '2') { $mask='192.0.0.0'}; if ($s == '3') { $mask='224.0.0.0'}; if ($s == '4') { $mask='240.0.0.0'}; if ($s == '5') { $mask='248.0.0.0'}; if ($s == '6') { $mask='252.0.0.0'}; if ($s == '7') { $mask='254.0.0.0'}; if ($s == '8') { $mask='255.0.0.0'}; if ($s == '9') { $mask='255.128.0.0'}; if ($s == '10') { $mask='255.192.0.0'}; if ($s == '11') { $mask='255.224.0.0'}; if ($s == '12') { $mask='255.240.0.0'}; if ($s == '13') { $mask='255.248.0.0'}; if ($s == '14') { $mask='255.252.0.0'}; if ($s == '15') { $mask='255.254.0.0'}; if ($s == '16') { $mask='255.255.0.0'}; if ($s == '17') { $mask='255.255.128.0'}; if ($s == '18') { $mask='255.255.192.0'}; if ($s == '19') { $mask='255.255.224.0'}; if ($s == '20') { $mask='255.255.240.0'}; if ($s == '21') { $mask='255.255.248.0'}; if ($s == '22') { $mask='255.255.252.0'}; if ($s == '23') { $mask='255.255.254.0'}; if ($s == '24') { $mask='255.255.255.0'}; if ($s == '25') { $mask='255.255.255.128'}; if ($s == '26') { $mask='255.255.255.192'}; if ($s == '27') { $mask='255.255.255.224'}; if ($s == '28') { $mask='255.255.255.240'}; if ($s == '29') { $mask='255.255.255.248'}; if ($s == '30') { $mask='255.255.255.252'}; if ($s == '31') { $mask='255.255.255.254'}; if ($s == '32') { $mask='255.255.255.255'}; if ($s == '') { $mask='255.255.255.255'}; $net = "$n1.$n2.$n3.$n4"; $ifid = cipdec(1, $net); $wmask = do_subtract($mask); print "*ip info*\n"; print "NET:$n\nBITS:$s MASK:$mask-$wmask\nGW:$gw\nIF:$ifid\n\n"; open (MYFILE, '>>cisco-config.txt'); if ($debug != NULL) { print "LINE:$line"; print "\n!\n"; print "interface tunnel $ifid\n"; print "description Link to $net\n"; print "ip unnumbered $loop\n"; print "tunnel source $outip\n"; print "tunnel destination $gw\n"; print "tunnel mode ipip\n!\n"; } if ($gw != $outip) { print MYFILE "!\n"; print MYFILE "interface tunnel $ifid\n"; print MYFILE "description Link to $net\n"; print MYFILE "ip unnumbered $loop\n"; print MYFILE "tunnel source $outip\n"; print MYFILE "tunnel destination $gw\n"; print MYFILE "ip tcp adjust-mss 1436\n"; print MYFILE "ip access-group acl_44 in\n!\n"; print MYFILE "tunnel mode ipip\n!\n"; print MYFILE "ip route $net $mask tunnel$ifid\n!\n"; } } print MYFILE "!\nend\n!\n"; close (MYFILE); sub usage { print << "EOT"; *** This script is for creating a loadable config (copy tftp run) for cisco routers *** *** Please note that this was tested to work on 2651XM or better, expect poor resp- *** *** -onse on smaller/slower platforms. *** *** Edit this file and change varibles as noted to your values. *** *** File \"cisco-config.txt\" will be generated in this directory for tftp upload *** *** Run as follows: *** *** perl encapconvert.pl encap.txt *** EOT } ######################################################## # Sub cipdec # USAGE: For converting IP to DEC values and reverse # # my ($err, $ret) = cipdec(1, $ip); #1 =from ip to dec, 2 = from dec to ip # if($err != 0) { print "MAIN: ERR ON \"$ret\"\n"; next; } # sub cipdec { my $debug = 0; my (@oct, $opt, $var, $err, $ret, $errmsg); my ($oct1, $oct2, $oct3, $oct4); my ($dec1, $dec2, $dec3); $opt = shift(@_); #1 =from ip to dec, 2 = from dec to ip $var = shift(@_); # IP or a DEC $err = 0; $ret = 0; if($debug == 1) { print "SUB TEST: OPT=\"$opt\"\n"; print "SUB TEST: VAR=\"$var\"\n"; } if($opt == 1) #1 =from ip to dec { my $ip = $var; if(!($ip) || ($ip eq "") || !($ip =~ /\./)) { if($debug == 1) { print "NO . in IP.. Next\n"; } $err = 1; $ret = "ERR: IP WITH NO \".\""; return($err, $ret); } @oct = split(/\./, $ip); my $numoct = @oct; if($numoct != 4) { if($debug == 1) { print "--INVALID IP: \"$ip\"\n"; } $err = 1; $ret = "ERR: OCT CT \"$ip\""; return($err, $ret); } foreach my $val (@oct) { if(!(defined $val) || ($val eq "") || ($val =~ /\D/) || ($val > 255) || ($val < 0)) { if($debug == 1) { print "--INVALID IP: \"$ip\"\n"; } $err = 1; $ret = "ERR: OCT SIZE \"$ip:$val\""; return($err, $ret); } # EO IF oct container } #EO FOREACH OCT $ret += ($oct[0] * (256**3)); #Convert 1st octet to decimal and add $ret += ($oct[1] * (256**2)); #Convert 2nd octet to decimal and add $ret += $oct[2] * 256; #Convert 3rd octet to decimal and add $ret += $oct[3]; #Add the 4th octet to decimal if(($ret < 0) || ($ret > 4294967296)) #0.0.0.0 or 255.255.255.255 = Err { if($debug == 1) { print "--INVALID IP: \"$ip\"\n"; } $err = 1; $ret = "ERR: DEC SIZE \"$ip\""; return($err, $ret); } #EO DEC Size return($err, $ret); } #EO OPT == 1 if($opt == 2) #1 = dec to ip { $oct1 = 0; $oct2 = 0; $oct3 = 0; $oct4 = 0; my $dec = $var; if($debug == 1) { print "SUB TEST: DEC=\"$dec\"\n"; } if(!(defined $dec) || ($dec eq "") || ($dec < 1) || ($dec > 4294967295)) #0.0.0.0 or 255.255.255.255 = Err { if($debug == 1) { print "--INVALID DEC: \"$dec\"\n"; } $err = 1; $ret = "ERR: DEC SIZE \"$dec\""; return($err, $ret); } #EO DEC Size if($dec >= 256**3) { $oct1 = ($dec / 256**3); my @num = split(/\./, $oct1); $oct1 = $num[0]; if($debug == 1) { print "OCT1: \"$oct1\"\n"; } $dec1 = ($oct1 * 256**3); $dec = $dec - $dec1; } if($dec >= 256**2) { $oct2 = ($dec / 256**2); my @num = split(/\./, $oct2); $oct2 = $num[0]; if($debug == 1) { print "OCT2: \"$oct2\"\n"; } $dec2 = ($oct2 * 256**2); $dec = $dec - $dec2; } if($dec >= 256) { $oct3 = ($dec / 256); my @num = split(/\./, $oct3); $oct3 = $num[0]; if($debug == 1) { print "OCT3: \"$oct3\"\n"; } $dec3 = $oct3 * 256; $dec = $dec - $dec3; } $oct4 = $dec; if($debug == 1) { print "OCT4: \"$oct4\"\n"; } $ret = "$oct1.$oct2.$oct3.$oct4"; return($err, $ret); } #EO If $opt == 2 $err = 1; $ret = "I'm lost and sent to leftovers"; return($err, $ret); } ################### EO SUB CIPDEC################################# ### wildcard sub ### sub do_subtract( ) { local($ip) = @_; # break up the bytes of the incoming IP address $_ = $ip; ($a, $b, $c, $d) = split(/\./); if ($a > 255 || $b > 255 || $c > 255 || $d > 255 || /[^0-9.]/) { print "invalid input mask or wildcard\n"; exit( ); } $a = 255 - $a; $b = 255 - $b; $c = 255 - $c; $d = 255 - $d; return ($a . "." . $b . "." . $c . "." . $d); } ### EO wildcard sub ###