ツイッターパーツ
t

2014年1月5日日曜日

VPN接続 | Linux OSでVPNサーバーを構築 #2

前回の続き

詳細を書いていきます。ちなみに、全然ネットワークに詳しくないので
あてにならないかもしれないですが、参考までに。

環境:
 OS:ESXi5.1上にCentOS6.x
 ブロードバンドルーター:BBR-4MG(古そうだったので、だめかと思いました。。。)

 クライアントOS:windows7
 クライアントソフト:Open VPN
 イーモバイル:GP03(アドバンスドプラン)



ルーターは何時のものかわかりませんが、昔我が家にインターネットが
普及された頃のモノから変わりがないと思います。。。

結構いいルータじゃないとVPN接続なんてできないと思ってたのですが、
なんとかこれで設定出来ました。とりあえず、BBR-4MGでVPN接続は
できるのでご安心を。

可能であれば、ファームアップとかしていただけると尚よろしいかと。


ESXi5.1での設定は特に必要ないと思います。
vSwitchの設定とかは特に設定を変えた覚えはないです。

構築手順は他のサイトをご参考にしてください。
なぜなら書くのが面倒だから。。。

参考になりそうなコンフィグだけ残していきます。


【鍵の作成】

これは他のサイトで、OpenVPNの構築手順を調べたら出てきますので
がんばってください。簡単です。

【サーバー: /etc/openvpn/server.conf】

#################################################
# Sample OpenVPN 2.0 config file for            #
# multi-client server.                          #
#                                               #
# This file is for the server side              #
# of a many-clients <-> one-server              #
# OpenVPN configuration.                        #
#                                               #
# OpenVPN also supports                         #
# single-machine <-> single-machine             #
# configurations (See the Examples page         #
# on the web site for more info).               #
#                                               #
# This config should work on Windows            #
# or Linux/BSD systems.  Remember on            #
# Windows to quote pathnames and use            #
# double backslashes, e.g.:                     #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
#                                               #
# Comments are preceded with '#' or ';'         #
#################################################
# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d
# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one.  You will need to
# open up this port on your firewall.
port 1194
# TCP or UDP server?
;proto tcp
proto udp
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
...skipping...
;max-clients 100
# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
user nobody
group nobody
# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
#status openvpn-status.log
status /var/log/openvpn-status.log
# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it.  Use one
# or the other (but not both).
;log         openvpn.log
log-append  /var/log/openvpn.log
# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3
# Silence repeating messages.  At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20
management localhost 7505
crl-verify      crl.pem


【クライアント:C:\Program Files (x86)\OpenVPN\config\client.ovpn】


##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server.     #
#                                            #
# This configuration can be used by multiple #
# clients, however each client should have   #
# its own cert and key files.                #
#                                            #
# On Windows, you might want to rename this  #
# file so it has a .ovpn extension           #
##############################################
# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client
# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one.  On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap
# Are we connecting to a TCP or
# UDP server?  Use the same setting as
# on the server.
;proto tcp
proto udp
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote filer 1194
;remote ここは、ブロードバンドルータのIPやホスト名を指定(DDNSを利用してホスト名) 1194
# Choose a random host from the remote
# list for load-balancing.  Otherwise
# try hosts in the order specified.
;remote-random
# Keep trying indefinitely to resolve the
# host name of the OpenVPN server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
# Most clients don't need to bind to
# a specific local port number.
nobind
# Downgrade privileges after initialization (non-Windows only)
user nobody
group nobody
# Try to preserve some state across restarts.
persist-key
persist-tun
# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here.  See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
# Wireless networks often produce a lot
# of duplicate packets.  Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings
# SSL/TLS parms.
# See the server config file for more
# description.  It's best to use
# a separate .crt/.key file pair
# for each client.  A single ca
# file can be used for all clients.
ca ca.crt
cert client2.crt
key client2.key
# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server".  This is an
# important precaution to protect against
# a potential attack discussed here:
http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server".  The build-key-server
# script in the easy-rsa folder will do this.
ns-cert-type server
# If a tls-auth key is used on the server
# then every client must also have the key.
tls-auth ta.key 1
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x
# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo
# Set log file verbosity.
verb 3
# Silence repeating messages
;mute 20

【ブロードバンドルーター:アドレス変換】


【ブロードバンドルーター:静的ルート】


なんか
イーモバイル経由でコンフィグ触ると接続がきれる。。。
自宅のネット環境から、グローバルIP経由で触りに行くときれない。

どこの設定いじればいいのかなー
通信料が多くて落ちるのか切り分けてみたいと思います。。。
あとは、ほかのホストにアクセスできないんだよなあ
これはこれでスタティックルートせっていしないとなんかなあ



追記:上記の切り分け

①グローバルIPを直接指定して接続
 openvpnのコンフィグファイルを編集しようとして、この異変に気づけたので
 これを再度編集してみたが問題ない。

②ローカルIPで指定して接続
 vpn接続したので、ローカルIPでの接続をしてみた。ここまでは問題ないが
 この先ファイルの編集ができない。編集可能なファイルがわかれば
 さっと切り分けができるが。。

③ファイルの容量が小さいものを編集
 /etc/hostsを編集してみたが、ファイルを開いた瞬間接続がきれた。
 わずか4行でだめだったので、④はやるまでもなくだめ。

④ファイルの容量が大きいものを編集



異常なわけですが、原因不明。
面倒くさい…


a.③よりさらに小さいファイルを編集
b.NW帯域を調べる
c.あとなんだろ、おもいついたけど忘れた

とりあえず、フォワーディングはできているので、接続語にプロトコルでブロックされている
わけではなさそう。ログの確認ができなかったから、特定の操作っていうことでもない

vpnのコンフィグになんかあるのかなー
しらべてみたけどようわからん


sambaサーバに接続してみたけど、やっぱおちた
プロトコルではない。

通信料の多さがが問題っぽい

ちなみに、sambaに接続したら、その後復帰しなくなった笑

クライアント側で、接続をきってインターフェースの再起動して
vpnクライアントから再接続しないとだめでした。

windowsだと次のコマンドで、接続をきってください。
実際は切れてるんだけど、コネクションがなんかのこるんかな??


net use /d 192.168.xxx.xxx

net use

net useコマンドで、セッションが残ってないか、確認する
なんかつらつらと書いてるけど、、、
ぜんぜんまとめる気なし。





追記: わかった!!

サーバーと、クライアント側の設定ファイルにしたの内容を記述すればok!
tun-mtu 1280


以上です!
なんかすごい詳しい人たちがいっぱいいるんだなーと思った。

vpn使ってるんで、ヘッダサイズが通常と違うんで、1500のmtu値のままだと
だめっぽい。

なので、値をちっさくしてあげたら問題なくいけた。
ちなみに、

tun-mtu 1400
 1400にすると、通信速度めっちゃ速くなった。10倍くらい
ただ、なぜかファイルの編集には耐えられなかった。

tun-mtu 1280
で、こっちでやったら通信速度に変化はなかったけど、
問題なくファイルの編集ができるようになった。

まあ、ローカルでいじるんとちゃうんで、速度は問題じゃなくて
つながらないと何の意味もないので、1280のmtu値にしました。

ほかにもフラグメントの設定とかもあったんですが、
サービスが起動しなくなってしまったので、とりあえずMTU値だけ
変更しました。

さらに、windowsOSへのリモートデスクトップができていなかった問題も
実は解消されまして、これにてずっと構築したかった環境ができあがり
ました!

とりあえず、あとはsambaサーバーにつなげられたらいい休日が
すごせそうです。

mtuの設定とかは各ファイルの最後尾にでも追記してあげればよろしいです。


では!!!!!



0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。