SDN開発エンジニアを目指した活動ブログ

〜SDNなオープンソース製品を実際に使って試してみる〜

vSRXを活用した、JUNOSのお勉強まとめ【JUNOS初期設定 + BGP基本編】

これから、しばらく、ネットワーク技術のお勉強に時間を費やしたいと思います。
ネットワークのお勉強の素材としては、「Junos設定&管理完全Bible」を選びました。
ただ、こちらの書籍なんですが、すでに、在庫が存在しておらず、中古品をゲットすることになりました。

gihyo.jp

◼︎ vSRX環境構築

以前のブログ記事「Mac OS X環境のVMware Fusion上で、vSRXを動かす」をそのまま活用します。
本来、vSRXは、Flowベースの仮想ファイアウォールなのですが、ルーティングの勉強用には、Packetベースに動作モードを変更しております。ご注意ください。
ttsubo.hatenablog.com

◼︎ vSRXトポロジ構成

Mac OS X環境で、複数台のvSRXを動作させたいところですが、今回は、vSRX2台構成としました。

                   +---------+                i-BGP                +--------+
... -------------+ | vSRX-1  | +---------------------------------+ | vSRX-2 | +---- ...
     172.16.0.1/24 |         | 192.168.0.1/30       192.168.0.2/30 |        | 172.16.1.1/24
                   +---------+                                     +--------+
                   < AS65000 >                                     < AS65000 >

◼︎ JUNOS基本設定

ネットワークエンジニア界隈で、よく使用されているJUNOS操作の習熟を目指して、最初から環境設定に取り掛かります。

(1) vSRXの初期設定

1. rootパスワードを設定する
初期状態では、rootユーザのパスワードは設定されていないので、パスワードを設定する

root# set system root-authentication plain-text-password 
New password:
Retype new password:

2. ホスト名を設定する

root# set system host-name vSRX-1
root# commit

3. タイムゾーンを設定する

root@vSRX-1# set system time-zone Asia/Tokyo 
root@vSRX-1# commit

4. 一般ユーザを作成する

root@vSRX-1# set system login user tsubo class super-user 
root@vSRX-1# set system login user tsubo authentication plain-text-password 
New password:
Retype new password:

5. vSRXの動作モードを変更する
vSRXは、通常、Flow-based forwardingモードで動作しているので、packet-based forwardingモードに変更しておきます。
動作モードの変更を有効にするために、vSRXを再起動します。

root@vSRX-1# delete security 
root@vSRX-1# set security forwarding-options family mpls mode packet-based    
root@vSRX-1# set security forwarding-options family inet6 mode packet-based
root@vSRX-1# commit
root@vSRX-1# exit 
Exiting configuration mode

root@vSRX-1> request system reboot
Reboot the system ? [yes,no] (no) yes 

Shutdown NOW!

すると、packet basedに変更されたことが確認できるようになります。

root@vSRX-1> show security flow status 
  Flow forwarding mode:
    Inet forwarding mode: packet based
    Inet6 forwarding mode: packet based
    MPLS forwarding mode: packet based
    ISO forwarding mode: drop
  Flow trace status
    Flow tracing status: off
  Flow session distribution
    Distribution mode: RR-based
  Flow ipsec performance acceleration: off
  Flow packet ordering
    Ordering mode: Hardware

6. rootユーザでのsshログインを許可する

root@vSRX-1# set system services ssh root-login allow

7. ge-0/0/0.0にアドレスを付与する

root@vSRX-1# set interfaces ge-0/0/0 unit 0 family inet address 192.168.0.1/24
root@vSRX-1# commit

root@vSRX-1# run show interfaces ge-0/0/0.0 brief 
  Logical interface ge-0/0/0.0 
    Flags: Up SNMP-Traps 0x4000 Encapsulation: ENET2
    Security: Zone: Null
    inet  192.168.0.1/24  

8. ループバックを設定する

root@vSRX-1# set interfaces lo0 unit 0 family inet address 10.0.0.1 
root@vSRX-1# commit

root@vSRX-1# run show interfaces lo0.0 brief  
  Logical interface lo0.0 
    Flags: Down SNMP-Traps Encapsulation: Unspecified
    Security: Zone: Null
    inet  10.0.0.1         --> 0/0

(2) BGP基本設定

1. 対向vSRXとの疎通性を確認しておく

root@vSRX-1# run ping 192.168.0.2 count 5   
PING 192.168.0.2 (192.168.0.2): 56 data bytes
64 bytes from 192.168.0.2: icmp_seq=0 ttl=64 time=3.993 ms
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=1.605 ms
64 bytes from 192.168.0.2: icmp_seq=2 ttl=64 time=1.101 ms
64 bytes from 192.168.0.2: icmp_seq=3 ttl=64 time=3.063 ms
64 bytes from 192.168.0.2: icmp_seq=4 ttl=64 time=1.969 ms

--- 192.168.0.2 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.101/2.346/3.993/1.046 ms

2. routing-optionを設定する

root@vSRX-1# set routing-options router-id 10.0.0.1 autonomous-system 65000 
root@vSRX-1# show | compare 
[edit]
+  routing-options {
+      router-id 10.0.0.1;
+      autonomous-system 65000;
+  }

root@vSRX-1# commit

3. protocolsを設定する

root@vSRX-1# set protocols bgp group INTERNAL type internal neighbor 192.168.0.2
root@vSRX-1# show | compare                                                 
[edit]
+  protocols {
+      bgp {
+          group INTERNAL {
+              type internal;
+              neighbor 192.168.0.2;
+          }
+      }
+  }

root@vSRX-1# commit  

4. BGP Peerの状態を確認しておく

root@vSRX-1> show bgp neighbor    
Peer: 192.168.0.2+55175 AS 65000 Local: 192.168.0.1+179 AS 65000
  Type: Internal    State: Established    Flags: <Sync>
  Last State: OpenConfirm   Last Event: RecvKeepAlive
  Last Error: Open Message Error
  Options: <Preference Refresh>
  Holdtime: 90 Preference: 170
  Number of flaps: 0
  Error: 'Open Message Error' Sent: 3 Recv: 0
  Peer ID: 10.0.0.2        Local ID: 10.0.0.1          Active Holdtime: 90
  Keepalive Interval: 30         Group index: 0    Peer index: 0   
  BFD: disabled, down
  NLRI for restart configured on peer: inet-unicast
  NLRI advertised by peer: inet-unicast
  NLRI for this session: inet-unicast
  Peer supports Refresh capability (2)
  Stale routes from peer are kept for: 300
  Peer does not support Restarter functionality
  NLRI that restart is negotiated for: inet-unicast
  NLRI of received end-of-rib markers: inet-unicast
  NLRI of all end-of-rib markers sent: inet-unicast
  Peer supports 4 byte AS extension (peer-as 65000)
  Peer does not support Addpath
  Table inet.0 Bit: 10000
    RIB State: BGP restart is complete
    Send state: in sync
    Active prefixes:              0
    Received prefixes:            0
    Accepted prefixes:            0
    Suppressed due to damping:    0
    Advertised prefixes:          0
  Last traffic (seconds): Received 3    Sent 3    Checked 83  
  Input messages:  Total 6      Updates 1       Refreshes 0     Octets 158
  Output messages: Total 6      Updates 0       Refreshes 0     Octets 177
  Output Queue[0]: 0            (inet.0, inet-unicast)

(3) down-link側の設定

1. ge-0/0/1.0にアドレスを付与する

root@vSRX-1# set interfaces ge-0/0/1 unit 0 family inet address 172.16.0.1/24 
root@vSRX-1# show | compare                                                      
[edit interfaces]
+   ge-0/0/1 {
+       unit 0 {
+           family inet {
+               address 172.16.0.1/24;
+           }
+       }
+   }

root@vSRX-1# commit 


2. Export policy作成と適用
自分が保持している経路を、BGP Peerに対して、アドバタイズするには、Export policyを作成して、BGPピアのGroupに適用する必要があるようです。

root@vSRX-1# set policy-options policy-statement export-bgp term 1 from route-filter 172.16.0.0/24 exact    
root@vSRX-1# set policy-options policy-statement export-bgp term 1 then accept 
root@vSRX-1# set protocols bgp group INTERNAL export export-bgp  
root@vSRX-1# show | compare 
[edit protocols bgp group INTERNAL]
+    export export-bgp;
[edit]
+  policy-options {
+      policy-statement export-bgp {
+          term 1 {
+              from {
+                  route-filter 172.16.0.0/24 exact;
+              }
+              then accept;
+          }
+      }
+  }

root@vSRX-1# commit 

すると、自分が保持している経路をアドバタイズするようになりました。

root@vSRX-1> show route advertising-protocol bgp 192.168.0.2 

inet.0: 6 destinations, 6 routes (6 active, 0 holddown, 0 hidden)
  Prefix                  Nexthop              MED     Lclpref    AS path
* 172.16.0.0/24           Self                         100        I

さらに、対向側でもExport policy作成と適用してみると、アドバタイズされた経路を受信できるようになりました。

root@vSRX-1> show route receive-protocol bgp 192.168.0.2 

inet.0: 6 destinations, 6 routes (6 active, 0 holddown, 0 hidden)
  Prefix                  Nexthop              MED     Lclpref    AS path
* 172.16.1.0/24           192.168.0.2                  100        I

(4) エンド端末間での疎通確認

tsubo@pc1:~$ ping 172.16.1.2
PING 172.16.1.2 (172.16.1.2) 56(84) bytes of data.
64 bytes from 172.16.1.2: icmp_seq=1 ttl=62 time=83.3 ms
64 bytes from 172.16.1.2: icmp_seq=2 ttl=62 time=0.584 ms
64 bytes from 172.16.1.2: icmp_seq=3 ttl=62 time=0.701 ms
64 bytes from 172.16.1.2: icmp_seq=4 ttl=62 time=0.634 ms
64 bytes from 172.16.1.2: icmp_seq=5 ttl=62 time=0.678 ms
^C
--- 172.16.1.2 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 0.584/17.194/83.377/33.091 ms

◼︎ 最終的なコンフィグ内容の確認

root@vSRX-1> show configuration | display set 
set version 15.1X49-D15.4
set system host-name vSRX-1
set system time-zone Asia/Tokyo
set system root-authentication encrypted-password "$1$XvI2vVPR$7lnJdb5gNeg4zql8lZ/1Q1"
set system login user tsubo uid 2000
set system login user tsubo class super-user
set system login user tsubo authentication encrypted-password "$1$THS.KlMg$SvjUk8SUxyDY3rDRGT3hK/"
set system services ssh root-login allow
set system services web-management http interface fxp0.0
set system syslog user * any emergency
set system syslog file messages any any
set system syslog file messages authorization info
set system syslog file interactive-commands interactive-commands any
set system license autoupdate url https://ae1.juniper.net/junos/key_retrieval
set security forwarding-options family inet6 mode packet-based
set security forwarding-options family mpls mode packet-based
set interfaces ge-0/0/0 unit 0 family inet address 192.168.0.1/24
set interfaces ge-0/0/1 unit 0 family inet address 172.16.0.1/24
set interfaces fxp0 unit 0
set interfaces lo0 unit 0 family inet address 10.0.0.1/32
set routing-options router-id 10.0.0.1
set routing-options autonomous-system 65000
set protocols bgp group INTERNAL type internal
set protocols bgp group INTERNAL export export-bgp
set protocols bgp group INTERNAL neighbor 192.168.0.2
set policy-options policy-statement export-bgp term 1 from route-filter 172.16.0.0/24 exact
set policy-options policy-statement export-bgp term 1 then accept

◼︎ 最後に

まぁ、今回は、単に、BGPを動かしただけなので、これといったコメントはありません。
以上です。