Ubuntu 12.04 で OpenVPN Server

Ubuntu サーバで OpenVPN なんていうものを以前ご紹介したのですが、家のサーバを Ubuntu 12.04 にUpgradeしたら openvpn server が立ち上がらなくなった。


Ubuntu 12.04 からは openvpn-2.2 系が入っており、実行するスクリプトのセキュリティレベルを設定するようになっている。 「 script-security 2 」というものを追記する必要がある。


up "/etc/openvpn/scripts/up.sh "
down "/etc/openvpn/scripts/down.sh "
script-security 2

man openvpn によると、このようなことらしい。


      --script-security level [method]
This directive offers policy-level control over OpenVPN's usage
of external programs and scripts. Lower level values are more
restrictive, higher values are more permissive. Settings for
level:
0 -- Strictly no calling of external programs.
1 -- (Default) Only call built-in executables such as ifconfig,
ip, route, or netsh.
2 -- Allow calling of built-in executables and user-defined
scripts.
3 -- Allow passwords to be passed to scripts via environmental
variables (potentially unsafe).
The method parameter indicates how OpenVPN should call external
commands and scripts. Settings for method:
execve -- (default) Use execve() function on Unix family OSes
and CreateProcess() on Windows.
system -- Use system() function (deprecated and less safe since
the external program command line is subject to shell expan‐
sion).
The --script-security option was introduced in OpenVPN 2.1_rc9.
For configuration file compatibility with previous OpenVPN ver‐
sions, use: --script-security 3 system

ってことで、久しぶりに openvpn の設定をオサライ。


Install


sudo apt-get install openvpn bridge-utils

Ethernet と openvpn のTAPをブリッジするので、bridge-utils も一緒にインストール。


Netowrk interface


今回もOpenVPNサーバはホームゲートウェイなどのNATルータの内側に設置されていると仮定。 NATルータでは、TCPやUDPの1194番ポートをOpenVPNサーバに転送するように設定しておきます。


OpenVPNサーバではNATの内側ネットワークにEthernetでつないで、OpenVPNのインターフェースにTAPを使うようにしています。 Layer2的にはEthernetとTAPが接続された状態にしたいので、これらをBrigdeするようにします。 まずは /etc/network/interfaces に下記のような設定を行います。


auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 192.168.x.x
netmask 255.255.255.0
gateway 192.168.x.y
bridge_ports eth0

この設定により、起動時に eth0 は br0 にブリッジされます。


server 側のスクリプト


ちょいと鍵の生成については、前回の例  を参考に、、省略します。 (;・∀・)


/etc/openvpn/server-udp.conf にこんな内容を


port 1194
proto udp
dev tap0
ca keys/ca.crt
cert keys/vm00.crt
key keys/vm00.key # This file should be kept secret
dh keys/dh1024.pem
ifconfig-pool-persist ipp.txt
server-bridge 192.168.45.17 255.255.255.0 192.168.45.64 192.168.45.127
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb 3
up "/etc/openvpn/scripts/up.sh "
down "/etc/openvpn/scripts/down.sh "
script-security 2
fragment 1280
mssfix

ついでに TCP でも Listen させるために server-tcp.conf というファイルにコピーして、これらの項目を編集



  • proto udp を proto tcp に

  • fragment 1280 という部分を削除

  • dev tap0 という部分を dev tap1 など、別のデバイスに


OpenvVPNサーバ起動時に device tap を bridge に追加する /etc/openvpn/scripts/up.sh


#!/bin/bash
# args : tun/tap-dev tun-mtu link-mtu ifconfig-local-ip ifconfig-remote-ip
dev="$1" ; tun_mtu="$2"; link_mtu="$3"; local_ip="$4"; remote_ip="$5"
case "$dev" in
tap*)
/sbin/ifconfig "$dev" promisc up
/sbin/brctl addif br0 "$dev"
;;
esac
exit

/etc/openvpn/scripts/up.sh


#!/bin/bash
# args : tun/tap-dev tun-mtu link-mtu ifconfig-local-ip ifconfig-remote-ip
dev="$1" ; tun_mtu="$2"; link_mtu="$3"; local_ip="$4"; remote_ip="$5"
case "$dev" in
tap*)
/usr/sbin/brctl delif br0 "$dev"
/sbin/ifconfig $dev down
;;
esac
exit

コメント

このブログの人気の投稿

パスワードを覚えるのも無理があるから、パスワードマネージャ使いましょう。

大型特殊自動車免許を取った時の話。

車両系建設機械運転者(整地) の講習