OpenVPNサーバの構築

VPNの種類

  • インターネットVPN

  ・使用技術

    IPsec-VPN:セキュリティプロトコルIPsecを使用。

              SSL-VPN   :セキュリティプロトコルSSLを使用。

  ・接続タイプ

    サイト間VPN

      VPN機能を実装したルータ同士を接続する。

      VPNの実装(パケットの暗号化、復号、カプセル化、非カプセル化)

      を全てルータで行う。

      クライアント(PC、サーバetc)には、専用のソフトウェアはいらない。

    リモートアクセスVPN

      VPN機能を実装したルータとVPNクライアントソフトを

      インストールしたPCを接続する。

      クライアント側(PC、サーバetc)には、専用のソフトウェアがいる。

  ・使用技術

    MPLS-VPN:通信事業者のプライベートIP網内で

            経路情報の探索にMPLSを採用したVPNのこと。

 

 

 

OpenVPNサーバの構築

 

 リモートアクセスVPN技術を使用したOpenVPNサーバを構築する。

 

 インストール

[root@centos8-test ~]# dnf install -y openvpn easy-rsa net-tools

 

 サーバ認証局、証明書などを作成

[root@centos8-test ~]# ll /usr/share/easy-rsa
合計 0
lrwxrwxrwx. 1 root root 5 3月 31 22:04 3 -> 3.0.7
lrwxrwxrwx. 1 root root 5 3月 31 22:04 3.0 -> 3.0.7
drwxr-xr-x. 3 root root 66 6月 18 19:47 3.0.7
[root@centos8-test ~]# cd /usr/share/easy-rsa
[root@centos8-test easy-rsa]# ll
合計 0
lrwxrwxrwx. 1 root root 5 3月 31 22:04 3 -> 3.0.7
lrwxrwxrwx. 1 root root 5 3月 31 22:04 3.0 -> 3.0.7
drwxr-xr-x. 3 root root 66 6月 18 19:47 3.0.7
[root@centos8-test easy-rsa]# cd 3

 

 初期化

[root@centos8-test 3]# ./easyrsa init-pki

 

 認証局の作成(青色の部分は自由に決める)

[root@centos8-test 3]# ./easyrsa build-ca
Using SSL: openssl OpenSSL 1.1.1c FIPS 28 May 2019

Enter New CA Key Passphrase:〇〇〇
Re-Enter New CA Key Passphrase:〇〇〇
Generating RSA private key, 2048 bit long modulus (2 primes)
.........................+++++
.............+++++
e is 65537 (0x010001)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:centos8

CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/usr/share/easy-rsa/3/pki/ca.crt

 

 サーバ証明書作成([server1]の部分は任意。証明書のファイル名になる。)

[root@centos8-test 3]# ./easyrsa build-server-full server1 nopass

Using SSL: openssl OpenSSL 1.1.1c FIPS 28 May 2019
Generating a RSA private key
........................+++++
......................+++++
writing new private key to '/usr/share/easy-rsa/3/pki/easy-rsa-2014.7aTQ0X/tmp.VZ9Mf8'
-----
Using configuration from /usr/share/easy-rsa/3/pki/easy-rsa-2014.7aTQ0X/tmp.tMJ7RF

認証局作成時のパス
Enter pass phrase for /usr/share/easy-rsa/3/pki/private/ca.key:〇〇〇
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'server1'
Certificate is to be certified until Sep 21 12:52:13 2022 GMT (825 days)

Write out database with 1 new entries
Data Base Updated

 

 クライアント証明書作成([client1]の部分は任意。証明書のファイル名になる。)

[root@centos8-test 3]# ./easyrsa build-client-full client1 nopass
Using SSL: openssl OpenSSL 1.1.1c FIPS 28 May 2019
Generating a RSA private key
............................................................+++++
......................................................................................+++++
writing new private key to '/usr/share/easy-rsa/3/pki/easy-rsa-2103.GT2DK4/tmp.cdLx4o'
-----
Using configuration from /usr/share/easy-rsa/3/pki/easy-rsa-2103.GT2DK4/tmp.pFk3id

認証局作成時のパス
Enter pass phrase for /usr/share/easy-rsa/3/pki/private/ca.key:〇〇〇
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'client1'
Certificate is to be certified until Sep 21 12:56:19 2022 GMT (825 days)

Write out database with 1 new entries
Data Base Updated

 

 Diffie Hellman(DH)パラメーター生成

[root@centos8-test 3]# ./easyrsa gen-dh
Using SSL: openssl OpenSSL 1.1.1c FIPS 28 May 2019
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
.......+...........................................................................................................................................................................

DH parameters of size 2048 created at /usr/share/easy-rsa/3/pki/dh.pem

 

 TLS-Authキー作成

[root@centos8-test 3]# openvpn --genkey --secret ./pki/ta.key

 

 生成したファイル等をコピー

[root@centos8-test 3]# cp -pR /usr/share/easyrsa/3/pki/{issued,private,ca.crt,dh.pem,ta.key}

/etc/openvpn/server/

 

 

 IPフォワードを有効化

[root@centos8-test 3]# vi /etc/sysctl.d/10-ipv4_forward.conf

追記

net.ipv4.ip_forward = 1

 

[root@centos8-test 3]# sysctl --system

 

 OpenVPNサーバの設定ファイルの編集&起動

1.サンプルの設定ファイルをコピー

[root@centos8-test ~]# cp

/usr/share/doc/openvpn/sample/sample-config-files/server.conf

/etc/openvpn/server/

 

2.サーバ設定ファイルの編集

[root@centos8-test server]# vi server.conf

port 1194

proto udp

dev tun

ca ca.crt
cert issued/server1.crt
key private/server1.key

dh dh.pem

server 10.0.0.0 255.255.255.0 //VPNで使用するNWの指定

push "route 192.168.1.0 255.255.255.0" //自NWの指定

client-to-client //クライアント間通信の設定

tls-auth ta.key 0

comp-lzo

status /var/log/openvpn-status.log

log /var/log/openvpn.log
log-append /var/log/openvpn.log

 

3.OpenVPNの起動

[root@centos8-test server]# systemctl start openvpn-server@server

[root@centos8-test server]# systemctl enable openvpn-server@server

 

4.firewalldの設定

[root@centos8-test server]# firewall-cmd --add-port=1194/udp --permanent

[root@centos8-test server]# firewall-cmd --reload

 

 クライアント側で必要な設定ファイル

・ca.key

・ta.key

・client1.crt

・client1.key