LoginSignup
4
6

More than 3 years have passed since last update.

CentOS 7でOpenConnect VPNサーバを作る

Last updated at Posted at 2019-07-11

はじめに

周知のように、中国のインターネットは規制されています。
規制は昔からあったのですが、かつてはPPTPでも簡単に塀超えできたものです。(遠い目)
年を追って規制が厳しくなり、地域やキャリア/プロバイダによっては、なかなか塀超えできなくなってしまいました。

OpenConnectは、Cisco AnyConnectと互換性のあるVPNソフトウエアのオープンソース実装です。

OpenConnectは、PPTP, L2TPなどの他のVPNプロトコルに比べて規制に強い(あるいはまだ規制が及んでない)ようなので、CentOS 7にOpenConnectをインストールして、塀超え目的のVPNサーバを作ってみます。

今回、サイト証明書は、Let's Encryptで取得しました。

作業

大まかに次のような手順で進めていきます。

  1. EPELを使えるようにする
  2. Let's EncryptでSSL証明書を作る
  3. OpenConnectをインストールする

EPEL

EPELを使えるようにします。

# yum -y install epel-release

Let's Encryptで証明書を得る

certbotをインストールします。

# yum -y install certbot

ポート80を開けておきます。

# firewall-cmd --add-service=http --permanent
# firewall-cmd --reload

certbotコマンドで証明書を作成します。

# certbot certonly --standalone --preferred-challenges http --agree-tos --email foo@example.com -d vpn.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for vpn.example.com
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/vpn.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/vpn.example.com/privkey.pem
   Your cert will expire on 2019-10-07. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

うまくいかないときは、ポート80を使っているWebサーバ(Apacheなど)を止めて試してみてください。

OpenConnectサーバをインストール

OpenConnect Server (ocserv)をインストールします。

# yum -y install ocserv

firewalldを設定します。

# firewall-cmd --add-port=443/tcp --permanent
# firewall-cmd --add-port=443/udp --permanent
# firewall-cmd --permanent --add-masquerade
# firewall-cmd --reload

OpenConnectの設定ファイルを編集します。

  • auth = "pam"をコメントアウト。
  • auth = "plain[passwd=/etc/ocserv/ocpasswd]" を追加。
#auth = "pam"
#auth = "pam[gid-min=1000]"
#auth = "plain[passwd=./sample.passwd,otp=./sample.otp]"
#auth = "certificate"
#auth = "radius[config=/etc/radiusclient/radiusclient.conf,groupconfig=true]"
auth = "plain[passwd=/etc/ocserv/ocpasswd]"
  • server-certserver-keyにLet's Encryptで作ったファイルのパスを入れる
server-cert = /etc/letsencrypt/live/vpn.example.com/fullchain.pem
server-key = /etc/letsencrypt/live/vpn.example.com/privkey.pem
  • default-domainを書き換える
# The default domain to be advertised
default-domain = vpn.example.com
  • ipv4-networkを書き換える
# An alternative way of specifying the network:
ipv4-network = 192.168.1.0/24
  • dnsを設定する
dns = 8.8.8.8
dns = 8.8.4.4

OpenConnectサーバの起動

ocservを有効化して起動します。

# systemctl enable ocserv
# systemctl start ocserv

ユーザー作成

OpenConnectに接続するときに使うユーザーを作成します。

# ocpasswd -c /etc/ocserv/ocpasswd nakamura
Enter password: 
Re-enter password: 

これでインストールは完了です。
クライアントから接続してみましょう。

(クライアント編へ続く。かも)

参考

次の情報を参考にしました。

4
6
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
4
6