LoginSignup
8
5

More than 5 years have passed since last update.

gobgpdでフルルート広告+そこからちぎって広告

Last updated at Posted at 2017-05-28

注意書き

このブログではどっかで見たことがあるグローバルなアドレスやグローバルAS番号を検証に用いておりますが、意図としてわかりやすさを表したいだけであり、検証環境は閉じられたNWで構成され、その値を持つ意味としてNWの検証以外の意味を持たせておりません。

gobgpdとフルルートの出会い

今回はまぁ身近なものでフルルートを広告したり、そこからちぎったり検証環境を作りたいなと思っており、ぴろぴろネットを見てると簡単にできるなーーーと思い構築しました。

gobgpdとは?

go言語で実装されたBGP Daemon。flowspecやMPLSも出来る。
ライバルにquaggaやexaBGPがいる。
https://github.com/osrg/gobgp

フルルートとは?

インターネットのネットワークアドレスのすべて(以下当ブログではフルルートはIPv4のみを示す)。
NWエンジニアであれば、まずは広告する立場にいたい。
2017/05/28現在70万経路近い。
bgp-active.png
(上記画像の引用元:http://bgp.potaroo.net/)
余談だが、Cisco ASR9kはフルルートの受信が一瞬である事は凄いなぁと毎回思う。

当該検証環境登場人物

●Windows10(仮想基盤)
・12GBの自宅サーバ
●GNS3
・そこらへんのGNS3 v2.0.1
●8.8.8.8のPC
・ping疎通用
●192.168.0.2のPC
・ping疎通用
●フルルートのサーバ
・Ubuntu16.04LTSにgobgpdをぶち込んだヤツ
・4GBのメモリ(gobgpdに2GB喰われる)
●ASR9k(IOS XRv)
・フルルートを広告されるヤツ
・4GBのメモリ(2GBだとタヒました)
●ルー太(8.8.8.0/24を受け取るだけのルータ)
・そこらへんのIOS
・メモリが512MiBしかないのでフルルートなんか貰ったらタヒぬ(というかタヒんだ)
・今回は8.8.8.0/24しかもらわないようにroute-mapを書きました

その他設計のお約束

・基本的にグローバルアドレスはBGP、プライベートはstaticで繋いでいる。
・フルルートは受信行為に非常に処理が重くなるので、そこらへんのルータに受信させるとタヒぬ
・そもそもIOS XRvはIOSとCPUの処理の仕方が根本的に違うので、まぁ同じことやるのであればIOS XRvで受信させる事をおススメされたい。
BGPのフルルートだが、毎日何回も更新されて公開されているので、是非最新のをダウンロードされたい。

ae022d9c33311c3dc310c9dfa781b4af.png

れっつら構築

●8.8.8.8のPC
8.8.8.8 255.255.255.0 gateway 8.8.8.10

●192.168.0.2のPC
192.168.0.2 255.255.255.0 gateway 192.168.0.1

フルルートのサーバ

(参考:http://qiita.com/kooshin/items/fe70c68217a0d399cefa
ほぼ丸パクリ参考にさせて頂きました。kooshin様ありがとうございましたm(_ _)m)

アドレス
ip add add 8.8.8.10/24 dev eth0
ip add add 202.249.2.169/24 dev eth1
スタティックルート追加
ip route add 10.0.0.0/24 via 202.249.2.170
ip route add 192.168.0.0/24 via 202.249.2.170
IPv4フォワーディングの許可
echo 1 >/proc/sys/net/ipv4/ip_forward
Go言語を使っていない場合はgolang-1.6をインストール
$ sudo apt update
$ sudo apt install golang-go
GOPATHで外部ライブラリのインストール場所を指定($HOME/go)
$ echo 'export GOPATH=$HOME/go' >> ~/.bashrc
$ echo 'export PATH=$GOPATH/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc
GoBGPのインストール
$ go get github.com/osrg/gobgp/gobgpd
$ go get github.com/osrg/gobgp/gobgp
Bash用の補完スクリプトの読み込み
$ wget https://raw.githubusercontent.com/osrg/gobgp/master/tools/completion/gobgp-completion.bash
$ wget https://raw.githubusercontent.com/osrg/gobgp/master/tools/completion/gobgp-static-completion.bash
$ wget https://raw.githubusercontent.com/osrg/gobgp/master/tools/completion/gobgp-dynamic-completion.bash
$ source gobgp-completion.bash
設定ファイル作成
$cat < gobgpd.conf
[global.config]
as = 9999
router-id = "202.249.2.169"

[[neighbors]]
[neighbors.config]
neighbor-address = "202.249.2.170"
peer-as = 10000
EOF
GoBGPデーモンを起動
$ sudo $HOME/go/bin/gobgpd -f gobgpd.conf

$ wget http://archive.routeviews.org/route-views.wide/bgpdata/2017.05/RIBS/rib.20170527.1600.bz2

$ bzip2 -d rib.20170527.1600.bz2

$ source gobgp-completion.bash

$ gobgp mrt inject global rib.20170527.1600

ASR9k(IOS XRv)

interface GigabitEthernet0/0/0/0
 ipv4 address 202.249.2.170 255.255.255.252
!
interface GigabitEthernet0/0/0/1
 ipv4 address 10.0.0.1 255.255.255.0
!
router bgp 10000
 bgp router-id 202.249.2.170
 address-family ipv4 unicast
!
 neighbor 10.0.0.2
  remote-as 10000
  update-source GigabitEthernet0/0/0/1
  address-family ipv4 unicast
   next-hop-self
!
!
 neighbor 202.249.2.169
  remote-as 9999
  update-source GigabitEthernet0/0/0/0
  address-family ipv4 unicast
★   route-policy ALL in
★   route-policy ALL out
!
route-policy ALL
  pass
end-policy
!
router static
 address-family ipv4 unicast
  192.168.0.0/24 10.0.0.2

ASR9kの制約なのですが、eBGPはroute-policyがないとALL DENYになりますので注意:relaxed:

ルー太(8.8.8.0/24を受け取るだけのヤツ)

interface GigabitEthernet2/0
 ip address 10.0.0.2 255.255.255.0
 negotiation auto
!
interface Ethernet1/0
 ip address 192.168.0.1 255.255.255.0
 duplex full
!
router bgp 10000
 bgp log-neighbor-changes
 neighbor 10.0.0.1 remote-as 10000
 neighbor 10.0.0.1 route-map ONLY in
!
★ip prefix-list ONLY-LIST seq 5 permit 8.8.8.0/24
!
★route-map ONLY permit 10
★ match ip address prefix-list ONLY-LIST
!

route-map ONLYを入れる事で1経路だけ受信させています。
これがないとリソース不足のルー太はぶっ壊れます:scream:

結果

①ASR9kとフルルートのUBUNTUのねいば

ubuntu#sudo $HOME/go/bin/gobgpd -f gobgpd.conf

ubuntu#go bgp neighbor 202.249.2.170
BGP neighbor is 202.249.2.170,  remote AS 10000
  BGP version 4, remote router ID 202.249.2.170
  BGP state = Established, up for 00:32:40

ほぼIOSのshowコマンドですね:laughing:

ASR9k#sho bgp nei
BGP neighbor is 202.249.2.169
 Remote AS 9999, local AS 10000, external link
 Remote router ID 202.249.2.169
  BGP state = Established, up for 01:08:55

ASR9k#show  bgp ipv4 unicast summary
Neighbor        Spk    AS MsgRcvd MsgSent   TblVer  InQ OutQ  Up/Down  St/PfxRcd
202.249.2.169     0  9999  650559     129   636507    0    0 01:03:06     ★650431

ASR9k#sho ip route 8.8.8.8
Routing entry for 8.8.8.0/24
  Known via "bgp 10000", distance 20, metric 0
  Tag 9999, type external
  Installed May 28 11:59:48.111 for 01:11:58
  Routing Descriptor Blocks
    202.249.2.169, from 202.249.2.169, BGP external
      Route metric is 0
  No advertising protos.

show bgp ipv4 unicast summaryの[St/PfxRcd]が650431経路~という事でフルルート受信!:innocent:

②ASR9kとルー太(8.8.8.0/24を受け取るだけのヤツ)のねいば

ASR9k#sho bgp nei
 Remote AS 10000, local AS 10000, internal link
 Remote router ID 192.168.0.1
  BGP state = Established, up for 00:34:15
ルー太#sho bgp nei
BGP neighbor is 10.0.0.1,  remote AS 10000, internal link
  BGP version 4, remote router ID 202.249.2.170
  BGP state = Established, up for 00:32:40

ルー太#sho bgp ipv4 unicast summary
Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.0.1        4        10000  104913      44        2    0    0 00:36:38        ★1

ルー太#sho ip ro
      ★8.0.0.0/24 is subnetted, 1 subnets
★B        8.8.8.0 [200/0] via 10.0.0.1, 00:36:46
      10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        10.0.0.0/24 is directly connected, GigabitEthernet2/0
L        10.0.0.2/32 is directly connected, GigabitEthernet2/0
      192.168.0.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.0.0/24 is directly connected, Ethernet1/0
L        192.168.0.1/32 is directly connected, Ethernet1/0

無事1経路だけもらえてる事が分かります:point_up:

③PCからPING

8.8.8.8のPC> ping 192.168.0.2
84 bytes from 192.168.0.2 icmp_seq=1 ttl=61 time=18.513 ms
84 bytes from 192.168.0.2 icmp_seq=2 ttl=61 time=19.013 ms
84 bytes from 192.168.0.2 icmp_seq=3 ttl=61 time=22.518 ms
84 bytes from 192.168.0.2 icmp_seq=4 ttl=61 time=19.014 ms
84 bytes from 192.168.0.2 icmp_seq=5 ttl=61 time=23.019 ms


192.168.0.2のPC> ping 8.8.8.8
84 bytes from 8.8.8.8 icmp_seq=1 ttl=61 time=18.527 ms
84 bytes from 8.8.8.8 icmp_seq=2 ttl=61 time=19.011 ms
84 bytes from 8.8.8.8 icmp_seq=3 ttl=61 time=11.007 ms
84 bytes from 8.8.8.8 icmp_seq=4 ttl=61 time=17.012 ms
84 bytes from 8.8.8.8 icmp_seq=5 ttl=61 time=11.509 ms

パーペキね:relaxed:

感想

手法としては簡単にできるので、後はリソースとの戦いかもしれません。
しかし、BGPこそ何回も検証を重ねて身に着けるものだと思うので、
是非高スペックの仮想環境はNWエンジニアといえど持っておく事をおススメいたします。

8
5
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
8
5