LoginSignup
7
9

More than 5 years have passed since last update.

Vagrant + VirtualBox + VyOSでeBGPによるルーティングをさくっと体験する

Last updated at Posted at 2019-02-10

はじめに

大規模ネットワークを支える技術で登場する「BGP」を学びたい気持ちがあり、連休中に色々やってみました。
今回の記事では、下記のように異なるAS番号を持つルーター同士をeBGPでつなげ、pingパケットのルーティングをゴールにお話ができればと思います。
(Vagrantがあれば誰でもサクッと試せるように、検証環境構築方法が下にありますmm)

スクリーンショット 2019-02-10 08.52.15.png

BGPとは?

BGPは、Border Gateway Protocolの略です。一言でいうと、通信をルーティングする為の仕組みの一つです。
今回は詳しい解説は飛ばしますが、インターネットの基幹に近い部分(通信プロバイダー等)やデータセンター内で主に利用されている仕組みです。

Border Gateway Protocol(ボーダ・ゲートウェイ・プロトコル、略称 : BGP)はインターネットの基幹となるルーティングプロトコルである。インターネットにおける最大の構成要素となる自律システム(Autonomous System:AS)の管理者のポリシーをAS間の経路制御に反映させる事を目的として設計された。
(出典元:https://ja.wikipedia.org/wiki/Border_Gateway_Protocol)

参考:インターネット10分講座:BGP
参考:データセンター内で使う BGP の基礎知識

必要なモノ

  • Vagrant (2.2.3)
  • VirtualBox (5.1.22)

環境作成

Vagrantを使って環境構築を進める前に、VyOSの設定・操作が可能になるプラグインを導入します。

$ vagrant plugin install vagrant-vyos

プラグインが導入できたら、下記を参考にVagrantfileを作成 & vagrant upします。
3つのVyOSのVMインスタンスが自動で作成され、Vagrantfileに書かれているIPアドレスが自動で付与されます。
※このファイルを変更する事によって、IPアドレスの初期値等を設定できます。

$ vim Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "higebu/vyos"

  config.vm.define :vyos1 do | vyos |
    vyos.vm.hostname = "vyos1"
    vyos.vm.network :private_network, ip: "192.168.33.1", virtualbox__intnet: "intnet1"
  end

  config.vm.define :vyos2 do | vyos |
    vyos.vm.hostname = "vyos2"
    vyos.vm.network :private_network, ip: "192.168.33.2", virtualbox__intnet: "intnet1"
    vyos.vm.network :private_network, ip: "192.168.34.1", virtualbox__intnet: "intnet2"
  end

  config.vm.define :vyos3 do | vyos |
    vyos.vm.hostname = "vyos3"
    vyos.vm.network :private_network, ip: "192.168.34.2", virtualbox__intnet: "intnet2"
  end
end
# VyOS1を起動
$ vagrant up vyos1
# VyOS2を起動
$ vagrant up vyos2
# VyOS3を起動
$ vagrant up vyos3

VyOSのProvision

VyOSにvagrant sshでログインし、configureモードでsetコマンドを叩く事でVyOSの設定がいじれます。
今回の設定では、最初にlo,dum0などのインターフェース設定&BGPによるピアリング&補助的なOSPFの設定をしています。

※ RT1,RT2,RT3が、192.168.33.0/24・192.168.34.0/24に対してルーティングできるようにOSPFをはっています。
これがないと、BGPでpingパケットがルーティングされても、帰り道でコケます。(RT3が192.168.33.0/24を知らないため)
StaticRoutingの設定をしても良いですが、横着しましたmm

VyOS1

$ vagrant ssh vyos1
vagrant@vyos1:~$ configure
# Interfaceの設定
vagrant@vyos1:~$ set interfaces loopback lo address 1.1.1.1/32
vagrant@vyos1:~$ set interfaces dummy dum0 address 11.11.11.11/32
# BGPの設定 (自AS番号=65121)
vagrant@vyos1:~$ set protocols bgp 65121 neighbor 192.168.33.2 remote-as '65122'
vagrant@vyos1:~$ set protocols bgp 65121 neighbor 192.168.33.2 soft-reconfiguration inbound
vagrant@vyos1:~$ set protocols bgp 65121 parameters router-id '1.1.1.1'
vagrant@vyos1:~$ set protocols bgp 65121 neighbor 192.168.33.2 update-source 192.168.33.1
vagrant@vyos1:~$ set protocols bgp 65121 network 11.11.11.11/32
# 192.168.33.0/24を広報する為の補助的なOSPF設定
# ※ StaticRoutingでも可能
vagrant@vyos1:~$ set protocols ospf area 0 network 192.168.33.0/24
vagrant@vyos1:~$ set protocols ospf passive-interface eth0
vagrant@vyos1:~$ set protocols ospf passive-interface lo
vagrant@vyos1:~$ set protocols ospf passive-interface dum0

VyOS2

$ vagrant ssh vyos2
vagrant@vyos2:~$ configure
# Interfaceの設定
vagrant@vyos2:~$ set interfaces loopback lo address 2.2.2.2/32 
vagrant@vyos2:~$ set interfaces dummy dum0 address 22.22.22.22/32
# BGPの設定 (自AS番号=65122)
vagrant@vyos2:~$ set protocols bgp 65122 neighbor 192.168.33.1 remote-as '65121'
vagrant@vyos2:~$ set protocols bgp 65122 neighbor 192.168.33.1 soft-reconfiguration inbound
vagrant@vyos2:~$ set protocols bgp 65122 neighbor 192.168.33.1 update-source 192.168.33.2
vagrant@vyos2:~$ set protocols bgp 65122 neighbor 192.168.34.2 remote-as '65123'
vagrant@vyos2:~$ set protocols bgp 65122 neighbor 192.168.34.2 soft-reconfiguration inbound
vagrant@vyos2:~$ set protocols bgp 65122 neighbor 192.168.34.2 update-source 192.168.34.1
vagrant@vyos2:~$ set protocols bgp 65122 parameters router-id '2.2.2.2'
vagrant@vyos2:~$ set protocols bgp 65122 network 22.22.22.22/32
# 192.168.33.0/24及び192.168.34.0/24を広報する為の補助的なOSPF設定
vagrant@vyos2:~$ set protocols ospf area 0 network 192.168.33.0/24
vagrant@vyos2:~$ set protocols ospf area 0 network 192.168.34.0/24
vagrant@vyos2:~$ set protocols ospf passive-interface eth0
vagrant@vyos2:~$ set protocols ospf passive-interface lo
vagrant@vyos2:~$ set protocols ospf passive-interface dum0

VyOS3

$ vagrant ssh vyos3
vagrant@vyos3:~$ configure
# Interfaceの設定
vagrant@vyos3:~$ set interfaces loopback lo address 3.3.3.3/32 
vagrant@vyos3:~$ set interfaces dummy dum0 address 33.33.33.33/32
# BGPの設定 (自AS番号=65123)
vagrant@vyos3:~$ set protocols bgp 65123 neighbor 192.168.34.1 remote-as '65122'
vagrant@vyos3:~$ set protocols bgp 65123 neighbor 192.168.34.1 soft-reconfiguration inbound
vagrant@vyos3:~$ set protocols bgp 65123 parameters router-id '3.3.3.3'
vagrant@vyos3:~$ set protocols bgp 65123 neighbor 192.168.34.1 update-source 192.168.34.2
vagrant@vyos3:~$ set protocols bgp 65123 network 33.33.33.33/32
# 192.168.34.0/24を広報する為の補助的なOSPF設定
vagrant@vyos3:~$ set protocols ospf area 0 network 192.168.34.0/24
vagrant@vyos3:~$ set protocols ospf passive-interface eth0
vagrant@vyos3:~$ set protocols ospf passive-interface lo
vagrant@vyos3:~$ set protocols ospf passive-interface dum0

設定確認

VyOS1

RT2,RT3のdum0がBGP経由で広報され、ルーティングテーブルに入っている事が確認できます。
(あと、OSPF経由で192.168.34.0/24も)


vagrant@vyos1:~$ show ip bgp
BGP table version is 0, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 11.11.11.11/32   0.0.0.0                  1         32768 i
*> 22.22.22.22/32   192.168.33.2             1             0 65122 i
*> 33.33.33.33/32   192.168.33.2                           0 65122 65123 i

Total number of prefixes 3
vagrant@vyos1:~$ show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
       I - ISIS, B - BGP, > - selected route, * - FIB route

S>* 0.0.0.0/0 [210/0] via 10.0.2.2, eth0
C>* 1.1.1.1/32 is directly connected, lo
C>* 10.0.2.0/24 is directly connected, eth0
C>* 11.11.11.11/32 is directly connected, dum0
B>* 22.22.22.22/32 [20/1] via 192.168.33.2, eth1, 01:47:36
B>* 33.33.33.33/32 [20/0] via 192.168.33.2, eth1, 01:41:05
C>* 127.0.0.0/8 is directly connected, lo
O   192.168.33.0/24 [110/10] is directly connected, eth1, 01:01:09
C>* 192.168.33.0/24 is directly connected, eth1
O>* 192.168.34.0/24 [110/20] via 192.168.33.2, eth1, 01:00:24

VyOS2

RT1,RT3のdum0がBGP経由で広報され、ルーティングテーブルに入っている事が確認できます。


vagrant@vyos2:~$ show ip bgp
BGP table version is 0, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 11.11.11.11/32   192.168.33.1             1             0 65121 i
*> 22.22.22.22/32   0.0.0.0                  1         32768 i
*> 33.33.33.33/32   192.168.34.2             1             0 65123 i

Total number of prefixes 3
vagrant@vyos2:~$ show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
       I - ISIS, B - BGP, > - selected route, * - FIB route

S>* 0.0.0.0/0 [210/0] via 10.0.2.2, eth0
C>* 2.2.2.2/32 is directly connected, lo
C>* 10.0.2.0/24 is directly connected, eth0
B>* 11.11.11.11/32 [20/1] via 192.168.33.1, eth1, 01:49:20
C>* 22.22.22.22/32 is directly connected, dum0
B>* 33.33.33.33/32 [20/1] via 192.168.34.2, eth2, 01:42:23
C>* 127.0.0.0/8 is directly connected, lo
O   192.168.33.0/24 [110/10] is directly connected, eth1, 01:01:48
C>* 192.168.33.0/24 is directly connected, eth1
O   192.168.34.0/24 [110/10] is directly connected, eth2, 01:01:48
C>* 192.168.34.0/24 is directly connected, eth2

VyOS3

RT1,RT2のdum0がBGP経由で広報され、ルーティングテーブルに入っている事が確認できます。
(あと、OSPF経由で192.168.33.0/24も)

vagrant@vyos3:~$ show ip bgp
BGP table version is 0, local router ID is 3.3.3.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 11.11.11.11/32   192.168.34.1                           0 65122 65121 i
*> 22.22.22.22/32   192.168.34.1             1             0 65122 i
*> 33.33.33.33/32   0.0.0.0                  1         32768 i

Total number of prefixes 3
vagrant@vyos3:~$ show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
       I - ISIS, B - BGP, > - selected route, * - FIB route

S>* 0.0.0.0/0 [210/0] via 10.0.2.2, eth0
C>* 3.3.3.3/32 is directly connected, lo
C>* 10.0.2.0/24 is directly connected, eth0
B>* 11.11.11.11/32 [20/0] via 192.168.34.1, eth1, 01:43:17
B>* 22.22.22.22/32 [20/1] via 192.168.34.1, eth1, 01:43:17
C>* 33.33.33.33/32 is directly connected, dum0
C>* 127.0.0.0/8 is directly connected, lo
O>* 192.168.33.0/24 [110/20] via 192.168.34.1, eth1, 01:01:00
O   192.168.34.0/24 [110/10] is directly connected, eth1, 01:01:50
C>* 192.168.34.0/24 is directly connected, eth1

Ping疎通テスト

VyOS1⇢dum0 on VyOS3

スクリーンショット 2019-02-10 09.27.51.png


vagrant@vyos1:~$ ping 33.33.33.33
PING 33.33.33.33 (33.33.33.33) 56(84) bytes of data.
64 bytes from 33.33.33.33: icmp_req=1 ttl=63 time=0.578 ms
64 bytes from 33.33.33.33: icmp_req=2 ttl=63 time=0.540 ms
64 bytes from 33.33.33.33: icmp_req=3 ttl=63 time=0.596 ms
^C
--- 33.33.33.33 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.540/0.571/0.596/0.030 ms
vagrant@vyos1:~$ traceroute  33.33.33.33
traceroute to 33.33.33.33 (33.33.33.33), 30 hops max, 60 byte packets
 1  192.168.33.2 (192.168.33.2)  0.797 ms  0.639 ms  0.576 ms
 2  33.33.33.33 (33.33.33.33)  1.650 ms  1.674 ms  1.631 ms

VyOS3⇢dum0 on VyOS1

スクリーンショット 2019-02-10 09.28.15.png


vagrant@vyos3:~$ ping 11.11.11.11
PING 11.11.11.11 (11.11.11.11) 56(84) bytes of data.
64 bytes from 11.11.11.11: icmp_req=1 ttl=63 time=0.652 ms
64 bytes from 11.11.11.11: icmp_req=2 ttl=63 time=0.581 ms
64 bytes from 11.11.11.11: icmp_req=3 ttl=63 time=0.624 ms
^C
--- 11.11.11.11 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.581/0.619/0.652/0.029 ms
vagrant@vyos3:~$ traceroute  11.11.11.11
traceroute to 11.11.11.11 (11.11.11.11), 30 hops max, 60 byte packets
 1  192.168.34.1 (192.168.34.1)  0.252 ms  0.203 ms  0.210 ms
 2  11.11.11.11 (11.11.11.11)  0.479 ms  0.404 ms  0.615 ms

最後に

無事、BGPを使ったパケットのルーティング動作について確認する事ができました。
Vagrant + VirtualBox + VyOSの活用で、サクッとネットワーク周りの仮想環境が構築できるので、ぜひコレを種に色々遊んで頂ければと思います。

7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9