LoginSignup
0
0

More than 1 year has passed since last update.

vyosでIPsecが切断されたときに再接続する

Posted at

目的

vyosでAzureとIPsec VPNを張っているが、無通信時間が続くと勝手に切断されてしまうことがあるので対策する。

環境

ちょっと古いバージョン。
Version: VyOS 1.3-rolling-202010070117
Release Train: equuleus

設定

vyosに組み込まれてるタスクスケジューラの機能を使う。
タスクで実行するシェルスクリプトはこんな感じ。

/config/scripts/vpncheck.sh
#!/bin/bash
 
STATUS=`/bin/vbash -ic 'show vpn ipsec sa | count'`
 
if [ $STATUS -lt 3 ]; then
logger -p user.warn -t vpncheck "[FAILED] VPN is disconnected. reboot now."
/bin/vbash -ic 'reboot now'
else
logger -p user.info -t vpncheck "[SUCCESS] VPN is connected."
fi

show vpn ipsec saのコマンド結果が接続時は以下のようになるので、
行数が3未満であれば切断されているものとみなし、再起動する。(restart vpnでは無理だった)

Connection                      State    Uptime    Bytes In/Out    Packets In/Out    Remote address    Remote ID    Proposal
------------------------------  -------  --------  --------------  ----------------  ----------------  -----------  ----------------------------------
peer-xx.xxx.xxx.xxx-tunnel-vti  up       4h12m27s  46K/60K         715/511           xx.xxx.xxx.xxx    N/A          AES_CBC_256/HMAC_SHA1_96/MODP_1024
peer-xx.xxx.xxx.xxx-tunnel-vti  up       4h12m27s  6K/9K           83/71             xx.xxx.xxx.xxx    N/A          AES_CBC_256/HMAC_SHA1_96/MODP_1024

vyosに投入するコマンドは以下のとおり。

set system task-scheduler task vpncheck executable path '/config/scripts/vpncheck.sh'
set system task-scheduler task vpncheck interval '30m'

これで30分ごとにVPN接続状況をチェックして、切断されていたら再起動~再接続できるようになった。

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