1
0

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 1 year has passed since last update.

【2023年9月版】RHEL9.2で作る障害時自動切替機能付の冗長化された簡易ルーター【VRRP】

Last updated at Posted at 2023-08-31

はじめに

障害時に自動切替機能付の冗長化された簡易ルーターをLinuxで構築する勉強したいな。。。

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

環境

  • RHEL9.2
  • RHEL9.2のルーターは2台
    • rhel01
      • デフォルトゲートウェイ 192.168.0.254
      • eth0
        • インターネット側インターフェイス
        • 192.168.0.100/24
      • eth1
        • 内側インターフェイス
        • 10.10.10.253/24
    • rhel02
      • デフォルトゲートウェイ 192.168.0.254
      • eth0
        • インターネット側インターフェイス
        • 192.168.0.101/24
      • eth1
        • 内側インターフェイス
        • 10.10.10.252/24
  • 冗長化のための仮想IPは 10.10.10.254

構築

RHEL01

# NAPT(IPマスカレード)のために firewalld のインストール、サービスとして登録
sudo yum install firewalld -y
sudo systemctl start firewalld
sudo systemctl enable firewalld

# パッケットのフォワードができるようにカーネルパラメータを設定
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

# ルーターとして動作するように firewalld を設定
sudo firewall-cmd --permanent --zone=external --add-masquerade
sudo firewall-cmd --permanent --change-interface=eth0 --zone=external
sudo firewall-cmd --permanent --change-interface=eth1 --zone=trusted
sudo firewall-cmd --reload

# VRRPのために keepalived をインストール
sudo dnf install -y keepalived

# VRRPの冗長化構成を keepalived で設定
sudo tee /etc/keepalived/keepalived.conf <<EOF >/dev/null
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 12345
    }
    virtual_ipaddress {
        10.10.10.254
    }
}
EOF

# vrrp の通信ができるように firewalld を設定
sudo firewall-cmd --permanent --zone=external --add-rich-rule='rule protocol value="vrrp" accept'
sudo firewall-cmd --reload

# keepalived をサービスとして登録
sudo systemctl enable keepalived
sudo systemctl start keepalived

RHEL02

RHEL01とほぼ同じ。
keepalived の vrrp の設定を、BACKUP として設定。

# NAPT(IPマスカレード)のために firewalld のインストール、サービスとして登録
sudo yum install firewalld -y
sudo systemctl start firewalld
sudo systemctl enable firewalld

# パッケットのフォワードができるようにカーネルパラメータを設定
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

# ルーターとして動作するように firewalld を設定
sudo firewall-cmd --permanent --zone=external --add-masquerade
sudo firewall-cmd --permanent --change-interface=eth0 --zone=external
sudo firewall-cmd --permanent --change-interface=eth1 --zone=trusted
sudo firewall-cmd --reload

# VRRPのために keepalived をインストール
sudo dnf install -y keepalived

# VRRPの冗長化構成を keepalived で設定
sudo tee /etc/keepalived/keepalived.conf <<EOF >/dev/null
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 12345
    }
    virtual_ipaddress {
        10.10.10.254
    }
}
EOF

# vrrp の通信ができるように firewalld を設定
sudo firewall-cmd --permanent --zone=external --add-rich-rule='rule protocol value="vrrp" accept'
sudo firewall-cmd --reload

# keepalived をサービスとして登録
sudo systemctl enable keepalived
sudo systemctl start keepalived

さいごに

かんたんでしたね

参考資料

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?