LoginSignup
0
0

【2023年8月版】VyOSで作る障害時自動切替機能付のマルチホーム環境の簡易ルーター【VRRP】

Last updated at Posted at 2023-08-20

はじめに

障害時に自動切替機能付のマルチホーム環境で、冗長化されたLinuxでルーター構築する勉強したいな。。。

そうだ、ChatGPT先生に教えてもらいながら構築しよう

※ 単にマルチホーム環境のルーター構築については以下を参照

【2023年8月版】VyOSで作るマルチホーム環境の簡易ルーター【VRRP】

環境

  • VyOS13
    インストールは以下の記事を参考に
    【2023年8月版】VyOSインストールiso作成から、ESXi7/8へのインストール
  • VyOSのルーターは2台
    • vyosgw01
      • デフォルトゲートウェイ 192.168.0.1
      • eth0
        • インターネット側インターフェイス
        • 192.168.0.100/24
      • eth1
        • 内側インターフェイス
        • 10.10.10.253/24
    • vyosgw02
      • デフォルトゲートウェイ 192.168.100.1
      • eth0
        • インターネット側インターフェイス
        • 192.168.100.100/24
      • eth1
        • 内側インターフェイス
        • 10.10.10.252/24
  • 冗長化のための仮想IPは 10.10.10.254

構築

vyosgw01

  • チェック用スクリプトを作成する
/config/scripts/vrrp-check.sh
#!/bin/bash
ping -c3 8.8.8.8 > /dev/null 2>&1
if [ $? -ne 0 ]; then
    exit 1
fi
exit 0
vim /config/scripts/vrrp-check.sh
chmod +x /config/scripts/vrrp-check.sh 
  • 設定を流し込む
conf
set system host-name vyosgw01
set interfaces ethernet eth0 address 192.168.0.100/24
set interfaces ethernet eth1 address 10.10.10.253/24
set high-availability vrrp group vyosgw vrid 10
set high-availability vrrp group vyosgw interface eth1
set high-availability vrrp group vyosgw virtual-address 10.10.10.254/24
set high-availability vrrp group vyosgw priority 200
set high-availability vrrp group vyosgw advertise-interval 1
#set high-availability vrrp group vyosgw no-preempt
set high-availability vrrp group vyosgw health-check script /config/scripts/vrrp-check.sh
set high-availability vrrp group vyosgw health-check interval 30
set high-availability vrrp group vyosgw health-check failure-count 2
set protocols static route 0.0.0.0/0 next-hop 192.168.0.1
set system name-server '8.8.8.8'
set system ipv6 disable
set system time-zone 'Asia/Tokyo'
set service ssh
set nat source rule 10 outbound-interface 'eth0'
set nat source rule 10 source address '0.0.0.0/0'
set nat source rule 10 translation address masquerade
commit
save

vyosgw02

  • 設定を流し込む
conf
set system host-name vyosgw02
set interfaces ethernet eth0 address 192.168.100.100/24
set interfaces ethernet eth1 address 10.10.10.252/24
set high-availability vrrp group vyosgw vrid 10
set high-availability vrrp group vyosgw interface eth1
set high-availability vrrp group vyosgw virtual-address 10.10.10.254/24
set high-availability vrrp group vyosgw priority 100
set high-availability vrrp group vyosgw advertise-interval 1
#set high-availability vrrp group vyosgw no-preempt
set protocols static route 0.0.0.0/0 next-hop 192.168.100.1
set system name-server '8.8.8.8'
set system ipv6 disable
set system time-zone 'Asia/Tokyo'
set service ssh
set nat source rule 10 outbound-interface 'eth0'
set nat source rule 10 source address '0.0.0.0/0'
set nat source rule 10 translation address masquerade
commit
save

確認

設定

vyosgw01

$ show vrrp
Name    Interface      VRID  State      Priority  Last Transition
------  -----------  ------  -------  ----------  -----------------
vyosgw  eth1             10  MASTER          200  29s
$ show int
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             192.168.0.100/24                  u/u  
eth1             10.10.10.253/24                   u/u  
                 10.10.10.254/24                       
lo               127.0.0.1/8                       u/u  

vyosgw02

$ show vrrp
Name    Interface      VRID  State      Priority  Last Transition
------  -----------  ------  -------  ----------  -----------------
vyosgw  eth1             10  BACKUP          100  20s
$ show int
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             192.168.100.100/24                u/u  
eth1             10.10.10.252/24                   u/u  
lo               127.0.0.1/8                       u/u  

動作

vyosgw02 から vyosgw01 への接続が失われたり、 vyosgw01 のインターネット(8.8.8.8)へのヘルスチェックが失敗すると、自動的に vyosgw02 へ切り替わることを確認する。

さいごに

かんたんでしたね

参考資料

VyOS1.3 公式ドキュメント - High availability

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