0
1

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 5 years have passed since last update.

DD-WRTにOpenVPNサーバーを立てる

Last updated at Posted at 2016-11-15

はじめに

DD-WRTにOpenVPNサーバーを立てたときのメモ。
昔の記録の転載なので、間違ってるところもあるかも。

DD-WRT自体の導入方法は、Webにわかりやすい解説がゴロゴロ転がっているので、そちらを参照してください。

前提

  • 作業OS : Windows 7 64bit
  • Hardware : Buffalo WZR-HP-AG300H
  • Firmware : DD-WRT v24-sp2 (12/22/14) std

参考

DDNS設定

ieServer.netでdomain.myhome.cxというドメインを取得し、設定が済んでいることを前提とします。設定値についてはDD-WRT設定 基本タブを参照。

証明書の作成

OpenVPNユーティリティのインストール

ダウンロード | OpenVPN.JPからインストーラをダウンロードして、フルインストール

準備

管理者としてコマンドプロンプトを実行する。
easy-rsa\vars.datが生成される。

cd /d %ProgramFiles%\OpenVPN\easy-rsa
init-config

vars.batを修正する。(内容は適当)

set KEY_SIZE=2048
set KEY_COUNTRY=JP
set KEY_PROVINCE=Tokyo
set KEY_CITY=Setagaya
set KEY_ORG=hogehoge
set KEY_EMAIL=hoge@hoge.com
set KEY_CN=hoge
set KEY_NAME=hoge
set KEY_OU=hoge
set PKCS11_MODULE_PATH=hoge
set PKCS11_PIN=1234

以下を実行。

vars
clean-all

認証局証明書と鍵作成

mkdir c:\etc\ssl
copy openssl-1.0.0.cnf c:\etc\ssl\openssl.cnf
build-ca

CommonNameだけhoge-caと入力。あとはそのままEnter。
easy-rsa\keys\に以下のファイルが生成される。

  • ca.crt
  • ca.key

サーバー証明書と鍵作成

build-key-server server

CommonNameだけhoge-svと入力。あとはそのままEnterまたはy。
easy-rsa\keys\に以下のファイルが生成される。

  • server.crt
  • server.key
  • server.csr

セキュリティの強化

build-dh

easy-rsa\keys\に以下のファイルが生成される。

  • dh2018.pem
  • 01.pem

TLS-auth鍵生成

cd %ProgramFiles%\OpenVPN\bin
openvpn --genkey --secret ta.key

OpenVPN\bin\ta.keyが生成される。

クライアントの作成

クライアント用鍵生成

下記はclient1を追加する場合。クライアントごとに任意に変更する。
初めに2回パスワードを入力、CommonNameはclient1と入力。あとはそのままEnterまたはy。

build-key-pass client1

easy-rsa\keys\に以下のファイルが生成される。

  • client1.crt
  • client1.key
  • client1.csr
  • 02.pem

クライアント用設定ファイルの作成

client1.ovpn
emote domain.myhome.cx 443
client
remote-cert-tls server
dev tun0
proto udp
resolv-retry infinite
nobind
persist-key
persist-tun
float
cipher AES-256-CBC
comp-lzo
tls-client
key-direction 1
ca ca.crt # または<ca>ca.crtのBEGIN~ENDまで</ca>
cert client.crt # または<cert>client.crtのBEGIN~ENDまで</cert>
key client.key # または<key>client.keyのBEGIN~ENDまで</key>
tls-auth ta.key # または<tls-auth>ta.keyのBEGIN~ENDまで</tls-auth>

DD-WRTの設定

OpenVPNサーバーの設定

ネットワークタブ > PPTPサーバー/クライアント > OpenVPN Server/Client

項目 設定値 備考
OpenVPN [x] 有効 [ ] 無効
Start Type [x] WAN Up [ ] System WANが起きたら開始
Config as [x] Server [ ] Daemon
Server mode [x] Router(TUN) [ ] Bridge(TAP)
Network 10.16.0.0 VPNセグメントの
ネットワークアドレス
Netmask 255.255.255.0 VPNセグメントの
サブネットマスク
ポート 433 VPNアクセスする際のポート
Tunnel Protocol UDP VPNアクセスする際の
プロトコル
Encryption Chiper AES-256 CBC
Hash Algorithm SHA1
Advanced Options [x] 有効 [ ] 無効
TLS Chiper None
LZO Compression Yes
Redirect default Gateway [ ] 有効 [x] 無効
Allow Client to Client [ ] 有効 [x] 無効
Allow duplicate cn [ ] 有効 [x] 無効
Tunnel MTU setting 1500
Tunnel UDP Fragment (空欄)
Tunnel UDP MSS-Fix [ ] 有効 [x] 無効
Public Server Cert server.crtの中身をコピペ
CA Cert ca.crtの中身をコピペ
Private Server Key server.keyの中身をコピペ
DH PEM dh2048.pemの中身をコピペ
TLS Auth Key ta.keyの中身をコピペ

Additional Config

# packets to 192.168.1.0/24 will be sent to this server
push "route 192.168.1.0 255.255.255.0"

# tell where DNS server is
push "dhcp-option DNS 192.168.1.254"

# send ping constantly
keepalive 10 120

# use tun0 device
dev tun0

Firewall, MASQUARADEの設定

管理タブ > コマンド実行タブ > Firewallスクリプト

# open 443/UDP
iptables -I INPUT 1 -p udp --dport 443 -j ACCEPT

# accept reception/forwarding from VPN
iptables -I INPUT 1 -i tun0 -s 10.16.0.0/24 -j ACCEPT
iptables -I FORWARD 1 -i tun0 -s 10.16.0.0/24 -j ACCEPT

# masquerade
iptables -t nat -I POSTROUTING 1 -o br0 -s 10.16.0.0/24 -j MASQUARADE

DNSMasqの設定

OpenVPNクライアントからの接続時、ローカル同様の名前解決ができるよう、下記2行を追加。

ネットワークタブ > サーバー/サービスタブ > Additional DNSMasq Options

interface=tun0
no-dhcp-interface=tun0

クライアントを追加するとき

クライアント用鍵の生成

easy-rsa\keys\に「証明書の作成」で作成した各種ファイルが存在する状態で、以下を実行。

cd /d %ProgramFiles%\OpenVPN\easy-rsa
build-key-pass client2

クライアント用設定ファイルの作成

上記参照

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?