LoginSignup
9
12

More than 5 years have passed since last update.

SoftEherVPNでTAPデバイスとのブリッジが失敗する場合

Posted at

SoftetherVPNをCentOS7に導入し、br0をTAPデバイスでローカルブリッジ接続する
設定をしていたが、再起動するとbr0とTAPデバイスの間の接続が切れてしまい、
うまくいかない。原因を調べてみた。

まずtapデバイスとbr0がつながっているかを確認するには、
/sbin/brctl show br0
でOKなのだが、


bridge name     bridge id               STP enabled     interfaces
br0             8000.00ac9794c389       no              enp2s0

上記の状態だと、interfacesにtapデバイスが表示されていない=tapデバイスが
br0にブリッジされていない状態。

Softetherのサービスはsystemctlで既に登録済みだが、確認すると、正常に
起動していない様子。

systemctl status softether.service

上記コマンドで、Activeと表示がでていなければ何らかのタイミングで失敗している。

で、見てみると、/etc/systemd/system/softether.service の中のbr0をTAPデバイスに接続しているところが正常に動いていない様子。
どうしても治らないので、起動時のスクリプトを作成して、設定しなおしてみた。

作成した起動スクリプト

vpnserver-tap-enable.sh
#!/bin/sh
TAP_DEVICE=tap_tap-br0
BR_STATUS=`/sbin/brctl show br0 | grep ${TAP_DEVICE} | wc -l`
LOOP_CNT=0

while [ $BR_STATUS = 0 ]
do
        sleep 1
        /sbin/brctl addif br0 ${TAP_DEVICE}
        if [ $? -ne 0 ]; then
                break
        fi
        LOOP_CNT=$(( LOOP_CNT + 1 ))
        if [ ${LOOP_CNT} = 10 ]; then
                break
        fi
done

exit 0

やっている内容としては、
起動時に指定したTAPデバイスが登録されているかを確認し、登録がなければ、brctlのaddifで登録する処理を実行。brctlコマンドが失敗するか、10回やってだめだったらあきらめる。

上記を、/etc/systemd/system/softether.serviceのExcecStartPostに設定

/etc/systemd/system/softether.service
[Unit]
Description=SoftEther VPN Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
ExecStartPost=/root/bin/vpnserver-tap-enable.sh

[Install]
WantedBy=multi-user.target

で、再起動したらちゃんとTAPデバイスが登録されるようになった。

[root@vpn]# /sbin/brctl show br0
bridge name     bridge id               STP enabled     interfaces
br0             8000.00ac9794c389       no              enp2s0
                                                        tap_tap-br0

serviceのstatusもいい感じ♪

[root@vpn]# systemctl status softether.service
● softether.service - SoftEther VPN Server
   Loaded: loaded (/etc/systemd/system/softether.service; enabled; vendor preset: disabled)
   Active: active (running) since 火 2017-06-06 11:15:16 JST; 26s ago
  Process: 1506 ExecStartPost=/root/bin/vpnserver-tap-enable.sh (code=exited, status=0/SUCCESS)
  Process: 1454 ExecStart=/usr/local/vpnserver/vpnserver start (code=exited, status=0/SUCCESS)
 Main PID: 1492 (vpnserver)
   CGroup: /system.slice/softether.service
           笏?─1492 /usr/local/vpnserver/vpnserver execsvc
           └─1498 /usr/local/vpnserver/vpnserver execsvc

 6月 06 11:15:14 vpn-gw01 systemd[1]: Starting SoftEther VPN Server...
 6月 06 11:15:14 vpn-gw01 vpnserver[1454]: The SoftEther VPN Server service has been started.
 6月 06 11:15:16 vpn-gw01 vpnserver-tap-enable.sh[1506]: device tap_tap-br0 is already a member of a b...0.
 6月 06 11:15:16 vpn-gw01 systemd[1]: Started SoftEther VPN Server.
Hint: Some lines were ellipsized, use -l to show in full.

ということで、起動スクリプトそのまま使うときは注意する。

あ、systemctl enable softether.service で自動起動の設定を有効にしておくことも忘れずに。

9
12
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
9
12