10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BGP経路広告のための検証環境(Docker上のVyOS:4台)構築手順

Posted at

はじめに

※ これは、簡易的な検証環境を作るための作業メモである。

VyOSをOpen vSwitchを使って制御し、BGPの経路広告の検証を行うことが可能な環境を構築する。

今回は、ホストの上に、Docker上のコンテナでVyOSを4台たて、ホストにOpen vSwitchを使いネットワークを構築する。(BGPの経路広告は、gobgpを使う予定)

ネットワーク図
                -- VyOS:router2 --
VyOS:router1 --+                  +-- VyOS:router4 -- control_server
                -- VyOS:router3 --

VyOS

  • ソフトウェアベースのルーティング、ファイアウォール、VPNなどの機能を提供してくれるオープンソースのネットワーク・オペレーティング・システム

dockerイメージを取得し、以下のようにvyosのコンテナを起動(4コンテナを構築)

docker pull kurochan/vyos:latest

docker run -d --name router1 --net=none --privileged -v /lib/modules:/lib/modules kurochan/vyos:latest /sbin/init
docker run -d --name router2 --net=none --privileged -v /lib/modules:/lib/modules kurochan/vyos:latest /sbin/init
docker run -d --name router3 --net=none --privileged -v /lib/modules:/lib/modules kurochan/vyos:latest /sbin/init
docker run -d --name router4 --net=none --privileged -v /lib/modules:/lib/modules kurochan/vyos:latest /sbin/init

Open vSwitch

SDNを実現する仮想スイッチ。

  • 複数の物理サーバや、ハイパーバイザ型の仮想マシン、コンテナ間のトラフィックを細かく制御でき、大規模な仮想化基盤及びクラウド基盤にも対応

Open vSwitchのインストール

今回、ホストOSは、「Debian GNU/Linux 9」を利用。

apt-get install build-essential fakeroot
cd <任意のディレクトリ>
wget http://openvswitch.org/releases/openvswitch-2.8.1.tar.gz

// debian/controlの中に、依存パッケージが何か書かれているのでinstall
apt-get install <依存パッケージ>

// 何もでなければ依存パッケージのインストールが通ったということ
dpkg-checkbuilddeps

// build(結構長い)
fakeroot debian/rules binary

cd ..
sudo dpkg -i openvswitch-common_2.6.1-1_amd64.deb ovn-common_2.6.1-1_amd64.deb
sudo dpkg -i openvswitch-dev_2.6.1-1_amd64.deb
sudo dpkg -i openvswitch-switch_2.6.1-1_amd64.deb python-openvswitch_2.6.1-1_all.deb 
sudo dpkg -i ovn-docker_2.6.1-1_amd64.deb
sudo dpkg -i openvswitch-datapath-dkms_2.6.1-1_all.deb

現在起動しているサービスの一覧を表示 (--all を付けると全サービスがリストされる)

systemctl -t service --all

open vswitchの自動起動

systemctl start openvswitch-switch.service 
systemctl enable openvswitch-switch.service 

ブリッジの設定

ovs-vsctl add-br switch12
ovs-vsctl add-br switch13
ovs-vsctl add-br switch42
ovs-vsctl add-br switch43
ovs-vsctl add-br switch45

switch設定

ovs-docker add-port switch12 eth0 router1 --ipaddress=172.16.0.1/30
ovs-docker add-port switch12 eth0 router2 --ipaddress=172.16.0.2/30

ovs-docker add-port switch13 eth1 router1 --ipaddress=172.16.0.5/30
ovs-docker add-port switch13 eth0 router3 --ipaddress=172.16.0.6/30

ovs-docker add-port switch42 eth0 router4 --ipaddress=172.16.0.9/30
ovs-docker add-port switch42 eth1 router2 --ipaddress=172.16.0.10/30

ovs-docker add-port switch43 eth1 router4 --ipaddress=172.16.0.13/30
ovs-docker add-port switch43 eth1 router3 --ipaddress=172.16.0.14/30

ovs-docker add-port switch45 eth2 router4 --ipaddress=172.16.0.17/30
ovs-docker add-port switch45 eth1 nobushi --ipaddress=172.16.0.18/30

VyOSの設定

このあたりは、docker-compose.ymlをしっかりかいて、rancherでサービスで展開できるようには後々修正したい。

Router1の設定

docker exec -it router1 /bin/bash
router1
su - vyos
config
set system host-name router1
set interfaces ethernet eth0 address '172.16.0.1/30'
set interfaces ethernet eth1 address '172.16.0.5/30'
set interfaces loopback lo address '1.1.1.1/32'
set protocols bgp 65001 neighbor 172.16.0.2 remote-as '65002'
set protocols bgp 65001 neighbor 172.16.0.6 remote-as '65003'
set protocols bgp 65001 network '192.168.0.0/24'
set protocols bgp 65001 parameters router-id '1.1.1.1'
set protocols static route 192.168.0.0/24 next-hop 172.16.0.1
commit
save
exit

Router2の設定

docker exec -it router2 /bin/bash
router2
su - vyos
config
set system host-name router2
set interfaces ethernet eth0 address '172.16.0.2/30'
set interfaces ethernet eth1 address '172.16.0.10/30'
set interfaces loopback lo address '1.1.1.2/32'
set protocols bgp 65002 neighbor 172.16.0.1 remote-as '65001'
set protocols bgp 65002 neighbor 172.16.0.9 remote-as '65004'
set protocols bgp 65002 network '192.168.1.0/24'
set protocols bgp 65002 parameters router-id '1.1.1.2'
set protocols static route 192.168.1.0/24 next-hop 172.16.0.2
commit
save
exit

Router3の設定

docker exec -it router3 /bin/bash
router3
su - vyos
config
set system host-name router3
set interfaces ethernet eth0 address '172.16.0.6/30'
set interfaces ethernet eth1 address '172.16.0.14/30'
set interfaces loopback lo address '1.1.1.3/32'
set protocols bgp 65003 neighbor 172.16.0.5 remote-as '65001'
set protocols bgp 65003 neighbor 172.16.0.13 remote-as '65004'
set protocols bgp 65003 network '192.168.2.0/24'
set protocols bgp 65003 parameters router-id '1.1.1.3'
set protocols static route 192.168.2.0/24 next-hop 172.16.0.6
commit
save
exit

Router4の設定

docker exec -it router4 /bin/bash
router4
su - vyos
config
set system host-name router4
set interfaces ethernet eth0 address '172.16.0.9/30'
set interfaces ethernet eth1 address '172.16.0.13/30'
set interfaces ethernet eth2 address '172.16.0.17/30'
set interfaces loopback lo address '1.1.1.4/32'
set policy community-list 100 rule 100 action 'permit'
set policy community-list 100 rule 100 description 'r3only'
set policy community-list 100 rule 100 regex '65004:500'
set policy community-list 101 rule 100 action 'permit'
set policy community-list 101 rule 100 description 'r2r3'
set policy community-list 101 rule 100 regex '65004:501'
set policy community-list 102 rule 100 action 'permit'
set policy community-list 102 rule 100 description 'r2only'
set policy community-list 102 rule 100 regex '65004:502'
set policy route-map 222 rule 100 action 'permit'
set policy route-map 222 rule 100 match community community-list '101'
set policy route-map 222 rule 100 set local-preference '200'
set policy route-map 222 rule 101 action 'permit'
set policy route-map 222 rule 101 match community community-list '102'
set policy route-map 222 rule 101 set local-preference '250'
set policy route-map 333 rule 100 action 'permit'
set policy route-map 333 rule 100 match community community-list '100'
set policy route-map 333 rule 100 set local-preference '250'
set policy route-map 333 rule 101 action 'permit'
set policy route-map 333 rule 101 match community community-list '101'
set policy route-map 333 rule 101 set local-preference '200'
set protocols bgp 65004 neighbor 172.16.0.10 remote-as '65002'
set protocols bgp 65004 neighbor 172.16.0.10 route-map export '222'
set protocols bgp 65004 neighbor 172.16.0.14 remote-as '65003'
set protocols bgp 65004 neighbor 172.16.0.14 route-map export '333'
set protocols bgp 65004 neighbor 172.16.0.18 remote-as '65004'
set protocols bgp 65004 network '192.168.0.0/16'
set protocols bgp 65004 network '192.168.3.0/24'
set protocols bgp 65004 parameters router-id '1.1.1.4'
set protocols static route 192.168.3.0/24 next-hop 172.16.0.9
set protocols static route 192.168.0.0/16 next-hop 172.16.0.9
commit
save
exit

これで、構築完了。以下、確認内容。

router4での結果

root@router4:/# show ip bgp
BGP table version is 0, local router ID is 1.1.1.4
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
*> 192.168.0.0/16   172.16.0.9               0         32768 i
*  192.168.0.0      172.16.0.14                            0 65003 65001 i
*>                  172.16.0.10                            0 65002 65001 i
*  192.168.1.0      172.16.0.14                            0 65003 65001 65002 i
*>                  172.16.0.10              0             0 65002 i
*> 192.168.2.0      172.16.0.14              0             0 65003 i
*                   172.16.0.10                            0 65002 65001 65003 i
*> 192.168.3.0      172.16.0.9               0         32768 i
Total number of prefixes 5

10
10
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
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?