VyOS OpenVPNの設定(ver 1.1.8)

・公式情報
https://wiki.vyos.net/wiki/OpenVPN

・rootパスワードの設定

set system login user root authentication plaintext-password "rootのパスワード"

・証明書作成

$ su -

# cp -rv /usr/share/doc/openvpn/examples/easy-rsa/2.0/ /config/easy-rsa2-my
# cd /config/easy-rsa2-my
# vi vars
※有効期限関連の設定は長めの期間に変更しておくこと
※DHの暗号長は2048以上にする

# source vars
# ./clean-all

# ./build-ca
# ./build-dh
# ./build-key-server server
# ./build-key client01

# mkdir /config/auth/ovpn
# cp keys/ca.crt /config/auth/ovpn/
# cp keys/dh2048.pem /config/auth/ovpn/
# cp keys/server.key /config/auth/ovpn/
# cp keys/server.crt /config/auth/ovpn/
# cp keys/client* /config/auth/ovpn/

・ネットワーク構成

(インターネット) - [eth1] - VyOS - [eth0] - (内部セグメント)
                                 - [vtun0] - (仮想セグメント)

OpenVPNサーバ設定

set interfaces openvpn vtun0 mode server
set interfaces openvpn vtun0 openvpn-option "--proto tcp"
set interfaces openvpn vtun0 openvpn-option "--port 5501"
set interfaces openvpn vtun0 server subnet 192.168.100.0/24

set interfaces openvpn vtun0 openvpn-option "--client-to-client"
set interfaces openvpn vtun0 openvpn-option "--comp-lzo yes"
set interfaces openvpn vtun0 openvpn-option '--mssfix 1280'

set interfaces openvpn vtun0 tls ca-cert-file '/config/auth/ovpn/ca.crt'
set interfaces openvpn vtun0 tls cert-file '/config/auth/ovpn/server.crt'
set interfaces openvpn vtun0 tls dh-file '/config/auth/ovpn/dh2048.pem'
set interfaces openvpn vtun0 tls key-file '/config/auth/ovpn/server.key'

※セキュリティを向上させる場合には下記も設定
set interfaces openvpn vtun0 encryption 'aes256'
set interfaces openvpn vtun0 hash 'sha512'

※クライアント側設定には下記を設定
cipher AES-256-CBC
auth sha512

ファイアウォール設定(外部→VyOS)

※外部からVyOSへのOpenVPNアクセスを許可する
※「in」ではなく「local」に適用すること

set firewall name OUT_LOCAL rule 20 action 'accept'
set firewall name OUT_LOCAL rule 20 destination port '5501'
set firewall name OUT_LOCAL rule 20 state new 'enable'

set interfaces ethernet eth1 firewall local name OUT_IN

・状態確認/再起動

show openvpn server status
ps -ef | grep openvpn

show configuration commands | grep openvpn
monitor openvpn &
grep openvpn /var/log/messages

reset openvpn interface vtun0

・DstNATとSrcNATで仮想セグメントから物理セグメントにアクセスできるようにする

set nat destination rule 100 inbound-interface 'vtun0'
set nat destination rule 100 destination address '192.168.100.100'
set nat destination rule 100 translation address '192.168.0.100'
set nat destination rule 101 inbound-interface 'vtun0'
set nat destination rule 101 destination address '192.168.100.101'
set nat destination rule 101 translation address '192.168.0.101'

set nat source rule 100 outbound-interface 'eth0'
set nat source rule 100 source address '192.168.100.0/24'
set nat source rule 100 translation address '192.168.0.98'

※vtun0が受信した 192.168.100.100 宛ての通信は 192.168.0.100 に転送する
※192.168.100.0/24宛ての通信は送信元を 192.168.0.98 に変更して eth0 から送信する