Rubyで多数のCiscoルータで複数のコマンドを実行する

Rubyと[expect4r](https://github.com/jesnault/expect4r)を使ってCiscoルータのコンフィグや状態を一括して取得します。
環境等は以前投稿した[Rubyのexpect4rでCiscoルータにTelnet/SSHしてコマンド実行する](http://qiita.com/kooshin/items/27f2b9ed5c8896279bcf)を参照してください。

## 目的
ルータが多数あると、いちいち書くルータにTELNET/SSHして、
コマンドを実行することが非常に面倒です。

ルータ上でVRFで似たような設定がある場合は、少しパラメータが違うだけで
大量にコマンドを実行しなくてはいけないことがあります。

そこでRubyと[expect4r](https://github.com/jesnault/expect4r)を使って、Ciscoルータでコマンドを実行します。
その際、少しだけパラメータが違うコマンドを複数実行もします。

## 概要
2台のCisco1812JでVRFが10個ある状態で、コマンドを実行します。
各ルータで``show interface description``と``show running-config``の他に、
サンプルとしてVRFごとのBGPテーブルを確認する``show bgp vpnv4 unicast vrf *``を実行します。
実際は``show bgp vpnv4 unicast all``でコマンドをVRF単位の実行は不要ですが。。。

## 環境
![図.png](https://qiita-image-store.s3.amazonaws.com/0/12026/70b4fb09-4613-41d8-1ceb-6cca55795770.png)


## スクリプト
ルータR1（192.168.88.101）とルータR2（192.168.88.102）にVRFが定義してあり、
VRF1とVRF2のBGPテーブルを表示する方法です。

サンプルでは、2台のルータにTELNETして、コマンドを実行しています。

```rb:sample3.rb
require 'expect4r'

# 接続先ルータ一覧
HOSTS = %w{
  192.168.88.101
  192.168.88.102
}
USERNAME = 'cisco'
PASSWORD = 'cisco'
ENABLE_PASSWORD = 'cisco'

HOSTS.each do |host|
  puts '*' * 60
  puts host
  puts '*' * 60
  ios = Expect4r::Ios.new_telnet(
    host: host,
    user: USERNAME,
    pwd: PASSWORD,
    enable_password: ENABLE_PASSWORD
  )
  # インタフェース状態を表示
  puts ios.show_int_desc

  # VRF1とVRF2のBGPテーブルを表示
  %w|VRF1 VRF2|.each do |vrf|
    puts ios.exec "show bgp vpnv4 unicast vrf #{vrf}"
  end

  # コンフィグを表示する
  puts ios.show_run
  puts
  puts
end
```

## 結果
```zsh:実行結果
% ruby sample3.rb
************************************************************
192.168.88.101
************************************************************
show int desc
Load for five secs: 12%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:07.653 JST Mon Nov 23 2015

Interface                      Status         Protocol Description
BR0                            admin down     down     
BR0:1                          admin down     down     
BR0:2                          admin down     down     
Fa0                            up             up       MANAGEMENT
Fa1                            up             up       WAN
Fa1.101                        up             up       USER1-WAN
Fa1.102                        up             up       USER2-WAN
Fa1.103                        up             up       USER3-WAN
Fa1.104                        up             up       USER4-WAN
Fa1.105                        up             up       USER5-WAN
Fa1.106                        up             up       USER6-WAN
Fa1.107                        up             up       USER7-WAN
Fa1.108                        up             up       USER8-WAN
Fa1.109                        up             up       USER9-WAN
Fa1.110                        up             up       USER10-WAN
Fa2                            admin down     down     
Fa3                            admin down     down     
Fa4                            admin down     down     
Fa5                            admin down     down     
Fa6                            admin down     down     
Fa7                            admin down     down     
Fa8                            admin down     down     
Fa9                            admin down     down     
Lo0                            up             up       RouterID
Lo101                          up             up       USER1-LAN1
Lo102                          up             up       USER1-LAN2
Lo201                          up             up       USER2-LAN1
Lo202                          up             up       USER2-LAN2
Lo301                          up             up       USER3-LAN1
Lo302                          up             up       USER3-LAN2
Lo401                          up             up       USER4-LAN1
Lo402                          up             up       USER4-LAN2
Lo501                          up             up       USER5-LAN1
Lo502                          up             up       USER5-LAN2
Lo601                          up             up       USER6-LAN1
Lo602                          up             up       USER6-LAN2
Lo701                          up             up       USER7-LAN1
Lo702                          up             up       USER7-LAN2
Lo801                          up             up       USER8-LAN1
Lo802                          up             up       USER8-LAN2
Lo901                          up             up       USER9-LAN1
Lo902                          up             up       USER9-LAN2
Lo1001                         up             up       USER10-LAN1
Lo1002                         up             up       USER10-LAN2
Vl1                            up             down     
R1#
show bgp vpnv4 unicast vrf VRF1
Load for five secs: 0%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:07.905 JST Mon Nov 23 2015

BGP table version is 51, local router ID is 192.168.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, x best-external, f RT-Filter
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
Route Distinguisher: 64512:1 (default for vrf VRF1)
*> 10.0.1.0/24      0.0.0.0                  0         32768 i
*> 10.0.2.0/24      192.168.1.2              0             0 64513 i
*> 192.168.0.0      0.0.0.0                  0         32768 i
*  192.168.1.0/30   192.168.1.2              0             0 64513 i
*>                  0.0.0.0                  0         32768 i
*> 192.168.2.0      192.168.1.2              0             0 64513 i
R1#
show bgp vpnv4 unicast vrf VRF2
Load for five secs: 0%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:08.133 JST Mon Nov 23 2015

BGP table version is 51, local router ID is 192.168.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, x best-external, f RT-Filter
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
Route Distinguisher: 64512:2 (default for vrf VRF2)
*> 10.0.1.0/24      0.0.0.0                  0         32768 i
*> 10.0.2.0/24      192.168.1.2              0             0 64513 i
*> 192.168.0.0      0.0.0.0                  0         32768 i
*  192.168.1.0/30   192.168.1.2              0             0 64513 i
*>                  0.0.0.0                  0         32768 i
*> 192.168.2.0      192.168.1.2              0             0 64513 i
R1#
show run
Load for five secs: 0%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:08.361 JST Mon Nov 23 2015

Building configuration...

Current configuration : 10514 bytes
!
! Last configuration change at 17:09:31 JST Mon Nov 23 2015 by cisco
! NVRAM config last updated at 17:09:44 JST Mon Nov 23 2015 by cisco
! NVRAM config last updated at 17:09:44 JST Mon Nov 23 2015 by cisco
version 15.1
service timestamps debug datetime msec localtime show-timezone year
service timestamps log datetime msec localtime show-timezone year
no service password-encryption
!
hostname R1
!
boot-start-marker
boot-end-marker
!
!
vrf definition VRF1
 description USER1
 rd 64512:1
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF10
 description USER10
 rd 64512:10
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF2
 description USER2
 rd 64512:2
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF3
 description USER3
 rd 64512:3
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF4
 description USER4
 rd 64512:4
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF5
 description USER5
 rd 64512:5
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF6
 description USER6
 rd 64512:6
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF7
 description USER7
 rd 64512:7
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF8
 description USER8
 rd 64512:8
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF9
 description USER9
 rd 64512:9
 !
 address-family ipv4
 exit-address-family
!
logging buffered 4096
logging console informational
enable password cisco
!
no aaa new-model
!
clock timezone JST 9 0
crypto pki token default removal timeout 0
!
!
dot11 syslog
no ip source-route
!
!
!
!
!
ip cef
no ip domain lookup
ip domain name cisco.com
no ipv6 cef
!
multilink bundle-name authenticated
!
!
!
license udi pid CISCO1812-J/K9 sn *
username cisco password 0 cisco
!
!
ip ssh version 2
! 
!
!
!
!
!
!
interface Loopback0
 description RouterID
 ip address 192.168.0.1 255.255.255.255
!
interface Loopback101
 description USER1-LAN1
 vrf forwarding VRF1
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback102
 description USER1-LAN2
 vrf forwarding VRF1
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback201
 description USER2-LAN1
 vrf forwarding VRF2
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback202
 description USER2-LAN2
 vrf forwarding VRF2
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback301
 description USER3-LAN1
 vrf forwarding VRF3
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback302
 description USER3-LAN2
 vrf forwarding VRF3
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback401
 description USER4-LAN1
 vrf forwarding VRF4
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback402
 description USER4-LAN2
 vrf forwarding VRF4
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback501
 description USER5-LAN1
 vrf forwarding VRF5
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback502
 description USER5-LAN2
 vrf forwarding VRF5
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback601
 description USER6-LAN1
 vrf forwarding VRF6
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback602
 description USER6-LAN2
 vrf forwarding VRF6
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback701
 description USER7-LAN1
 vrf forwarding VRF7
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback702
 description USER7-LAN2
 vrf forwarding VRF7
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback801
 description USER8-LAN1
 vrf forwarding VRF8
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback802
 description USER8-LAN2
 vrf forwarding VRF8
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback901
 description USER9-LAN1
 vrf forwarding VRF9
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback902
 description USER9-LAN2
 vrf forwarding VRF9
 ip address 192.168.0.1 255.255.255.0
!
interface Loopback1001
 description USER10-LAN1
 vrf forwarding VRF10
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback1002
 description USER10-LAN2
 vrf forwarding VRF10
 ip address 192.168.0.1 255.255.255.0
!
interface BRI0
 no ip address
 encapsulation hdlc
 shutdown
!
interface FastEthernet0
 description MANAGEMENT
 ip address 192.168.88.101 255.255.255.0
 duplex auto
 speed auto
!
interface FastEthernet1
 description WAN
 no ip address
 logging event subif-link-status
 logging event subif-link-status ignore-bulk
 duplex auto
 speed auto
!
interface FastEthernet1.101
 description USER1-WAN
 encapsulation dot1Q 101
 vrf forwarding VRF1
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.102
 description USER2-WAN
 encapsulation dot1Q 102
 vrf forwarding VRF2
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.103
 description USER3-WAN
 encapsulation dot1Q 103
 vrf forwarding VRF3
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.104
 description USER4-WAN
 encapsulation dot1Q 104
 vrf forwarding VRF4
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.105
 description USER5-WAN
 encapsulation dot1Q 105
 vrf forwarding VRF5
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.106
 description USER6-WAN
 encapsulation dot1Q 106
 vrf forwarding VRF6
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.107
 description USER7-WAN
 encapsulation dot1Q 107
 vrf forwarding VRF7
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.108
 description USER8-WAN
 encapsulation dot1Q 108
 vrf forwarding VRF8
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.109
 description USER9-WAN
 encapsulation dot1Q 109
 vrf forwarding VRF9
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet1.110
 description USER10-WAN
 encapsulation dot1Q 110
 vrf forwarding VRF10
 ip address 192.168.1.1 255.255.255.252
!
interface FastEthernet2
 no ip address
 shutdown
!
interface FastEthernet3
 no ip address
 shutdown
!
interface FastEthernet4
 no ip address
 shutdown
!
interface FastEthernet5
 no ip address
 shutdown
!
interface FastEthernet6
 no ip address
 shutdown
!
interface FastEthernet7
 no ip address
 shutdown
!
interface FastEthernet8
 no ip address
 shutdown
!
interface FastEthernet9
 no ip address
 shutdown
!
interface Vlan1
 no ip address
!
router bgp 64512
 bgp router-id 192.168.0.1
 bgp log-neighbor-changes
 no bgp default ipv4-unicast
 timers bgp 30 90
 !
 address-family ipv4 vrf VRF1
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER1
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF10
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER10
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF2
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER2
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF3
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER3
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF4
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER4
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF5
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER5
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF6
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER6
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF7
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER7
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF8
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER8
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF9
  network 10.0.1.0 mask 255.255.255.0
  network 192.168.0.0
  network 192.168.1.0 mask 255.255.255.252
  neighbor 192.168.1.2 remote-as 64513
  neighbor 192.168.1.2 description R2-USER9
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 next-hop-self
  neighbor 192.168.1.2 soft-reconfiguration inbound
 exit-address-family
!
ip forward-protocol nd
no ip http server
no ip http secure-server
!
!
ip route 0.0.0.0 0.0.0.0 FastEthernet0 192.168.88.1
!
logging origin-id hostname
!
!
!
!
snmp-server community public RO
snmp-server ifindex persist
snmp-server chassis-id R1
!
!
control-plane
!
!
!
line con 0
line aux 0
line vty 0 4
 exec-timeout 5 0
 logging synchronous
 login local
 exec prompt timestamp
 transport input telnet ssh
line vty 5 15
 exec-timeout 5 0
 logging synchronous
 login local
 exec prompt timestamp
 transport input telnet ssh
!
ntp server 133.243.238.244
end

R1#


************************************************************
192.168.88.102
************************************************************
show int desc
Load for five secs: 9%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:11.206 JST Mon Nov 23 2015

Interface                      Status         Protocol Description
BR0                            admin down     down     
BR0:1                          admin down     down     
BR0:2                          admin down     down     
Fa0                            up             up       MANAGEMENT
Fa1                            up             up       WAN
Fa1.101                        up             up       USER1-WAN
Fa1.102                        up             up       USER2-WAN
Fa1.103                        up             up       USER3-WAN
Fa1.104                        up             up       USER4-WAN
Fa1.105                        up             up       USER5-WAN
Fa1.106                        up             up       USER6-WAN
Fa1.107                        up             up       USER7-WAN
Fa1.108                        up             up       USER8-WAN
Fa1.109                        up             up       USER9-WAN
Fa1.110                        up             up       USER10-WAN
Fa2                            admin down     down     
Fa3                            admin down     down     
Fa4                            admin down     down     
Fa5                            admin down     down     
Fa6                            admin down     down     
Fa7                            admin down     down     
Fa8                            admin down     down     
Fa9                            admin down     down     
Lo0                            up             up       RouterID
Lo101                          up             up       USER1-LAN1
Lo102                          up             up       USER1-LAN2
Lo201                          up             up       USER2-LAN1
Lo202                          up             up       USER2-LAN2
Lo301                          up             up       USER3-LAN1
Lo302                          up             up       USER3-LAN2
Lo401                          up             up       USER4-LAN1
Lo402                          up             up       USER4-LAN2
Lo501                          up             up       USER5-LAN1
Lo502                          up             up       USER5-LAN2
Lo601                          up             up       USER6-LAN1
Lo602                          up             up       USER6-LAN2
Lo701                          up             up       USER7-LAN1
Lo702                          up             up       USER7-LAN2
Lo801                          up             up       USER8-LAN1
Lo802                          up             up       USER8-LAN2
Lo901                          up             up       USER9-LAN1
Lo902                          up             up       USER9-LAN2
Lo1001                         up             up       USER10-LAN1
Lo1002                         up             up       USER10-LAN2
Vl1                            up             down     
R2#
show bgp vpnv4 unicast vrf VRF1
Load for five secs: 9%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:11.462 JST Mon Nov 23 2015

BGP table version is 51, local router ID is 192.168.0.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, x best-external, f RT-Filter
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
Route Distinguisher: 64513:1 (default for vrf VRF1)
*> 10.0.1.0/24      192.168.1.1              0             0 64512 i
*> 10.0.2.0/24      0.0.0.0                  0         32768 i
*> 192.168.0.0      192.168.1.1              0             0 64512 i
*  192.168.1.0/30   192.168.1.1              0             0 64512 i
*>                  0.0.0.0                  0         32768 i
*> 192.168.2.0      0.0.0.0                  0         32768 i
R2#
show bgp vpnv4 unicast vrf VRF2
Load for five secs: 9%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:11.698 JST Mon Nov 23 2015

BGP table version is 51, local router ID is 192.168.0.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, x best-external, f RT-Filter
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
Route Distinguisher: 64513:2 (default for vrf VRF2)
*> 10.0.1.0/24      192.168.1.1              0             0 64512 i
*> 10.0.2.0/24      0.0.0.0                  0         32768 i
*> 192.168.0.0      192.168.1.1              0             0 64512 i
*  192.168.1.0/30   192.168.1.1              0             0 64512 i
*>                  0.0.0.0                  0         32768 i
*> 192.168.2.0      0.0.0.0                  0         32768 i
R2#
show run
Load for five secs: 9%/0%; one minute: 1%; five minutes: 1%
Time source is NTP, 17:23:11.922 JST Mon Nov 23 2015

Building configuration...

Current configuration : 10514 bytes
!
! Last configuration change at 17:17:56 JST Mon Nov 23 2015 by cisco
! NVRAM config last updated at 17:18:02 JST Mon Nov 23 2015 by cisco
! NVRAM config last updated at 17:18:02 JST Mon Nov 23 2015 by cisco
version 15.1
service timestamps debug datetime msec localtime show-timezone year
service timestamps log datetime msec localtime show-timezone year
no service password-encryption
!
hostname R2
!
boot-start-marker
boot-end-marker
!
!
vrf definition VRF1
 description USER1
 rd 64513:1
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF10
 description USER10
 rd 64513:10
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF2
 description USER2
 rd 64513:2
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF3
 description USER3
 rd 64513:3
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF4
 description USER4
 rd 64513:4
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF5
 description USER5
 rd 64513:5
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF6
 description USER6
 rd 64513:6
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF7
 description USER7
 rd 64513:7
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF8
 description USER8
 rd 64513:8
 !
 address-family ipv4
 exit-address-family
!
vrf definition VRF9
 description USER9
 rd 64513:9
 !
 address-family ipv4
 exit-address-family
!
logging buffered 4096
logging console informational
enable password cisco
!
no aaa new-model
!
clock timezone JST 9 0
crypto pki token default removal timeout 0
!
!
dot11 syslog
no ip source-route
!
!
!
!
!
ip cef
no ip domain lookup
ip domain name cisco.com
no ipv6 cef
!
multilink bundle-name authenticated
!
!
!
license udi pid CISCO1812-J/K9 sn *
username cisco password 0 cisco
!
!
ip ssh version 2
! 
!
!
!
!
!
!
interface Loopback0
 description RouterID
 ip address 192.168.0.2 255.255.255.255
!
interface Loopback101
 description USER1-LAN1
 vrf forwarding VRF1
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback102
 description USER1-LAN2
 vrf forwarding VRF1
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback201
 description USER2-LAN1
 vrf forwarding VRF2
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback202
 description USER2-LAN2
 vrf forwarding VRF2
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback301
 description USER3-LAN1
 vrf forwarding VRF3
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback302
 description USER3-LAN2
 vrf forwarding VRF3
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback401
 description USER4-LAN1
 vrf forwarding VRF4
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback402
 description USER4-LAN2
 vrf forwarding VRF4
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback501
 description USER5-LAN1
 vrf forwarding VRF5
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback502
 description USER5-LAN2
 vrf forwarding VRF5
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback601
 description USER6-LAN1
 vrf forwarding VRF6
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback602
 description USER6-LAN2
 vrf forwarding VRF6
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback701
 description USER7-LAN1
 vrf forwarding VRF7
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback702
 description USER7-LAN2
 vrf forwarding VRF7
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback801
 description USER8-LAN1
 vrf forwarding VRF8
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback802
 description USER8-LAN2
 vrf forwarding VRF8
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback901
 description USER9-LAN1
 vrf forwarding VRF9
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback902
 description USER9-LAN2
 vrf forwarding VRF9
 ip address 192.168.2.1 255.255.255.0
!
interface Loopback1001
 description USER10-LAN1
 vrf forwarding VRF10
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback1002
 description USER10-LAN2
 vrf forwarding VRF10
 ip address 192.168.2.1 255.255.255.0
!
interface BRI0
 no ip address
 encapsulation hdlc
 shutdown
!
interface FastEthernet0
 description MANAGEMENT
 ip address 192.168.88.102 255.255.255.0
 duplex auto
 speed auto
!
interface FastEthernet1
 description WAN
 no ip address
 logging event subif-link-status
 logging event subif-link-status ignore-bulk
 duplex auto
 speed auto
!
interface FastEthernet1.101
 description USER1-WAN
 encapsulation dot1Q 101
 vrf forwarding VRF1
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.102
 description USER2-WAN
 encapsulation dot1Q 102
 vrf forwarding VRF2
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.103
 description USER3-WAN
 encapsulation dot1Q 103
 vrf forwarding VRF3
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.104
 description USER4-WAN
 encapsulation dot1Q 104
 vrf forwarding VRF4
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.105
 description USER5-WAN
 encapsulation dot1Q 105
 vrf forwarding VRF5
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.106
 description USER6-WAN
 encapsulation dot1Q 106
 vrf forwarding VRF6
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.107
 description USER7-WAN
 encapsulation dot1Q 107
 vrf forwarding VRF7
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.108
 description USER8-WAN
 encapsulation dot1Q 108
 vrf forwarding VRF8
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.109
 description USER9-WAN
 encapsulation dot1Q 109
 vrf forwarding VRF9
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet1.110
 description USER10-WAN
 encapsulation dot1Q 110
 vrf forwarding VRF10
 ip address 192.168.1.2 255.255.255.252
!
interface FastEthernet2
 no ip address
 shutdown
!
interface FastEthernet3
 no ip address
 shutdown
!
interface FastEthernet4
 no ip address
 shutdown
!
interface FastEthernet5
 no ip address
 shutdown
!
interface FastEthernet6
 no ip address
 shutdown
!
interface FastEthernet7
 no ip address
 shutdown
!
interface FastEthernet8
 no ip address
 shutdown
!
interface FastEthernet9
 no ip address
 shutdown
!
interface Vlan1
 no ip address
!
router bgp 64513
 bgp router-id 192.168.0.2
 bgp log-neighbor-changes
 no bgp default ipv4-unicast
 timers bgp 30 90
 !
 address-family ipv4 vrf VRF1
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER1
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF10
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER10
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF2
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER2
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF3
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER3
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF4
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER4
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF5
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER5
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF6
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER6
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF7
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER7
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF8
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER8
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
 !
 address-family ipv4 vrf VRF9
  network 10.0.2.0 mask 255.255.255.0
  network 192.168.1.0 mask 255.255.255.252
  network 192.168.2.0
  neighbor 192.168.1.1 remote-as 64512
  neighbor 192.168.1.1 description R1-USER9
  neighbor 192.168.1.1 activate
  neighbor 192.168.1.1 next-hop-self
  neighbor 192.168.1.1 soft-reconfiguration inbound
 exit-address-family
!
ip forward-protocol nd
no ip http server
no ip http secure-server
!
!
ip route 0.0.0.0 0.0.0.0 FastEthernet0 192.168.88.1
!
logging origin-id hostname
!
!
!
!
snmp-server community public RO
snmp-server ifindex persist
snmp-server chassis-id R1
!
!
control-plane
!
!
!
line con 0
line aux 0
line vty 0 4
 exec-timeout 5 0
 logging synchronous
 login local
 exec prompt timestamp
 transport input telnet ssh
line vty 5 15
 exec-timeout 5 0
 logging synchronous
 login local
 exec prompt timestamp
 transport input telnet ssh
!
ntp server 133.243.238.244
end

R2#
```