LoginSignup
0
0

containerlabを使おうとしたら門前払いされたがめげずにネットワークを構築した話

Last updated at Posted at 2023-12-20

この記事は、 大阪工業大学 Advent Calendar 2023の20日目の記事です。
containerlabをインストールしてさあ触るぞとなった段階でいくつもの壁に当たったので忘れないうちに書いていく。
時間が足りたのでついでに簡単なネットワークの構築も行う
本記事はcontainerlabを実行しネットワークを構築するために行ったことたちを並べるだけの記事である

トラブルシューティング編

以下はcontainerlabを使うまでの苦悩である

containerlabのinstall

containerlabの環境自体はこれを見ながらしようとしていた
そのためinstallのコマンドも以下を使用している

sudo bash -c "$(curl -sL https://get.containerlab.dev)"

ymlを作ってdeployしたところエラーが起こりdockerダメそうとなったのでいっそのこと始めから試すかと以下の操作を行った。

wsl2のupdate

よくよく見てみたらデスクトップpcにはwslがインストールされていなかったらしい(Microsoft Store情報)
ただ、terminalでwsl --installを行うとすでにインストールされているとなっていたので原因は不明
デスクトップpcの環境構築をしたのが遠い昔の話であるため一切覚えていない
普段使っているノートpcは夏ごろに一度フルリカバリされて修理から戻ってきていたのでwslはインストールされていた

windows11でwsl2をインストールする方法及びuddateする方法は以下の通り

wsl --install
wsl --update

dockerのinstall

次にdockerもダメそうだったのでdockerもインストールしなおした
公式が出しているコマンドは以下の通り

curl https://get.docker.com/ | sudo sh

systemctl

ついでにwsl2を起動したときにdockerなどを同時に起動しておくことにした
対象のwsl2ディストリビューションに入り、wsl.confに以下の内容を記載する

[boot]
systemd=true

最後にwsl2をshutdownさせてもう一度起動させれば設定が反映される

ネットワーク構築編

以下は実際にcontainerlabでネットワークを構築する話である

トポロジ図

今回構築するネットワーク構成図は以下のとおりである
image.png
今回はとてもシンプルなospfでのルーティングを行う

containerlabの実行

containerlabを実行するためにはyamlファイルを書かなければならない
今回のネットワークを構築するために書いたymlは以下のとおりである
もし手元でやってみる場合bindのあたりは変える必要があると思う
また、このymlの名前をhoge.clab.ymlにしておかないとcontainerlab deployで実行ができなかった

name: advent

topology:
  nodes:
    router1:
      kind: linux
      image: frrouting/frr:v7.5.1
      binds:
        - router1:/etc/frr
    router2:
      kind: linux
      image: frrouting/frr:v7.5.1
      binds:
        - router2:/etc/frr
    router3:
      kind: linux
      image: frrouting/frr:v7.5.1
      binds:
        - router3:/etc/frr
  links:
    - endpoints:
        - router1:eth1
        - router2:eth1
    - endpoints:
        - router1:eth2
        - router3:eth1
    - endpoints:
        - router2:eth2
        - router3:eth2

これの他に今回はfrrを使用するため以下も必要

zebra=yes
bgpd=no
ospfd=yes
ospf6d=no
ripd=no
ripngd=no
isisd=no
pimd=no
ldpd=yes
nhrpd=no
eigrpd=no
babeld=no
sharpd=no
staticd=no
pbrd=no
bfdd=no
fabricd=no

vtysh_enable=yes
zebra_options=" -s 90000000 --daemon -A 127.0.0.1"
bgpd_options="   --daemon -A 127.0.0.1"
ospfd_options="  --daemon -A 127.0.0.1"
ospf6d_options=" --daemon -A ::1"
ripd_options="   --daemon -A 127.0.0.1"
ripngd_options=" --daemon -A ::1"
isisd_options="  --daemon -A 127.0.0.1"
pimd_options="  --daemon -A 127.0.0.1"
ldpd_options="  --daemon -A 127.0.0.1"
nhrpd_options="  --daemon -A 127.0.0.1"
eigrpd_options="  --daemon -A 127.0.0.1"
babeld_options="  --daemon -A 127.0.0.1"
sharpd_options="  --daemon -A 127.0.0.1"
staticd_options="  --daemon -A 127.0.0.1"
pbrd_options="  --daemon -A 127.0.0.1"
bfdd_options="  --daemon -A 127.0.0.1"
fabricd_options="  --daemon -A 127.0.0.1"

これを各routerのディレクトリにdaemonsとして入れる

これらが書けたら以下のコマンドで起動させる

sudo containerlab deploy

起動時にたくさんのINFOとymlに書いたnodeが起動していたら成功
止めるコマンドは以下の通り

sudo containerlab destroy

補足

hoge.ymlでファイルを保存した場合、以下のコマンドなら実行が可能であった

sudo clab deploy --topo hoge.yml

この場合のcontainerlabの止め方は

sudo clab destroy --topo hoge.yml

である

router1

ipアドレスの設定

router1# conf t
router1(config)# interface eth1
router1(config-if)# ip address 192.168.10.1/24
router1(config-if)# exit
router1(config)# interface eth2
router1(config-if)# ip address 192.168.30.1/24
router1(config-if)# exit

ospfの設定

router1(config)# router ospf
router1(config-router)# router-info area 0.0.0.0
router1(config-router)# network 192.168.10.0/24 area 0.0.0.0
router1(config-router)# network 192.168.30.0/24 area 0.0.0.0

router2

ipアドレスの設定

router2# conf t
router2(config)# interface eth1
router2(config-if)# ip address 192.168.10.2/24
router2(config-if)# exit
router2(config)# interface eth2
router2(config-if)# ip address 192.168.20.2/24
router2(config-if)# exit

ospfの設定

router2(config)# router ospf
router2(config-router)# router-info area 0.0.0.0
router2(config-router)# network 192.168.10.0/24 area 0.0.0.0
router2(config-router)# network 192.168.20.0/24 area 0.0.0.0

router3

ipアドレスの設定

router3# configure terminal
router3(config)# interface eth1
router3(config-if)# ip address 192.168.30.3/24
router3(config-if)# exit
router3(config)# interface eth2
router3(config-if)# ip address 192.168.20.3/24
router3(config-if)# exit

ospfの設定

router3(config)# router ospf
router3(config-router)# router-info area 0.0.0.0
router3(config-router)# network 192.168.30.0/24 area 0.0.0.0
router3(config-router)# network 192.168.20.0/24 area 0.0.0.0

疎通確認

今回はrouter1に入ってルーターからは見えていない192.168.20.2にpingが飛ぶのかを確認する

こんな感じ
image.png

終わりに

ネットワークって何ぞや、でも実機触る機会無いよっていう人は色々な記事を見ながらcontainerlabでもGNS3でもいいので一つの小さなネットワークを触って作ってみたらいいと思う
とても楽しいことに気づくはずだから
あと vrnetlab - VR Network Labを使えば他のOSも使えるようになるらしいのだがまだ試せていないので時間があるときにやってみたい

参考文献

Containerlabを使用した商用環境と同等な検証環境の作成とユースケースについて
Use Containerlab to emulate open-source routers
Basic Commands

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