5f062e987feb8d326d9e5cf7b6b50657335faa76
Linux/OpenVPN.md
| ... | ... | @@ -56,20 +56,20 @@ BOOTPROTO=none |
| 56 | 56 | # cd /etc/openvpn/easyrsa3/ |
| 57 | 57 | # ./easyrsa init-pki (OpenVPNインストール後初回のみ実行する) |
| 58 | 58 | # ./easyrsa build-ca (PEM pass phrase, Common Name を入力) |
| 59 | -# cp pki/ca.crt /etc/openvpn/ |
|
| 59 | +# cp pki/ca.crt /etc/openvpn/server/ |
|
| 60 | 60 | ``` |
| 61 | 61 | |
| 62 | 62 | ## サーバー証明書・秘密鍵作成 |
| 63 | 63 | ``` |
| 64 | 64 | # ./easyrsa build-server-full server nopass (CAのパスフレーズを入力) |
| 65 | -# cp pki/issued/server.crt /etc/openvpn/ |
|
| 66 | -# cp pki/private/server.key /etc/openvpn/ |
|
| 65 | +# cp pki/issued/server.crt /etc/openvpn/server/ |
|
| 66 | +# cp pki/private/server.key /etc/openvpn/server/ |
|
| 67 | 67 | ``` |
| 68 | 68 | |
| 69 | 69 | ## Diffie Hellman パラメータ作成 |
| 70 | 70 | ``` |
| 71 | 71 | # ./easyrsa gen-dh |
| 72 | -# cp pki/dh.pem /etc/openvpn/ |
|
| 72 | +# cp pki/dh.pem /etc/openvpn/server/ |
|
| 73 | 73 | ``` |
| 74 | 74 | |
| 75 | 75 | ## 証明書廃止リスト作成 |
| ... | ... | @@ -83,17 +83,17 @@ set_var EASYRSA_CRL_DAYS 3650 |
| 83 | 83 | # ./easyrsa build-client-full dmy nopass (CAのパスフレーズを入力) |
| 84 | 84 | # ./easyrsa revoke dmy (yes応答, CAのパスフレーズを入力) |
| 85 | 85 | # ./easyrsa gen-crl (CAのパスフレーズを入力) |
| 86 | -# cp /etc/openvpn/easyrsa3/pki/crl.pem /etc/openvpn/ |
|
| 87 | -# chmod o+r /etc/openvpn/crl.pem |
|
| 86 | +# cp /etc/openvpn/easyrsa3/pki/crl.pem /etc/openvpn/server/ |
|
| 87 | +# chmod o+r /etc/openvpn/server/crl.pem |
|
| 88 | 88 | ``` |
| 89 | 89 | |
| 90 | 90 | ## OpenVPN設定 |
| 91 | 91 | ``` |
| 92 | 92 | # openvpn --genkey --secret /etc/openvpn/ta.key |
| 93 | -# cp /usr/share/doc/openvpn/sample/sample-config-files/server.conf /etc/openvpn/ |
|
| 93 | +# cp /usr/share/doc/openvpn/sample/sample-config-files/server.conf /etc/openvpn/server/ |
|
| 94 | 94 | ``` |
| 95 | 95 | |
| 96 | -- /etc/openvpn/server.conf |
|
| 96 | +- /etc/openvpn/server/server.conf |
|
| 97 | 97 | ``` |
| 98 | 98 | port 1194 |
| 99 | 99 | |
| ... | ... | @@ -130,52 +130,6 @@ log-append /var/log/openvpn.log |
| 130 | 130 | crl-verify crl.pem |
| 131 | 131 | ``` |
| 132 | 132 | |
| 133 | -- /etc/openvpn/openvpn-startup |
|
| 134 | -```bash |
|
| 135 | -#!/bin/bash |
|
| 136 | - |
|
| 137 | -# VPNインタフェースiptablesルール削除スクリプト実行※必須 |
|
| 138 | -/etc/openvpn/openvpn-shutdown |
|
| 139 | - |
|
| 140 | -# VPNサーバーからの送信を許可※必須 |
|
| 141 | -iptables -I OUTPUT -o tun+ -j ACCEPT |
|
| 142 | -iptables -I FORWARD -o tun+ -j ACCEPT |
|
| 143 | - |
|
| 144 | -# VPNクライアントからVPNサーバーへのアクセスを許可する場合 |
|
| 145 | -iptables -I INPUT -i tun+ -j ACCEPT |
|
| 146 | - |
|
| 147 | -# VPNクライアントからLANへのアクセスを許可する場合 |
|
| 148 | -# (例としてVPNクライアントから192.168.1.0/24へのアクセスを許可する場合) |
|
| 149 | -# ※192.168.1.0/24側のファイアウォール等でVPNクライアント(10.8.0.0/24)からのアクセスを許可すること |
|
| 150 | -iptables -I FORWARD -i tun+ -d 192.168.1.0/24 -j ACCEPT |
|
| 151 | -``` |
|
| 152 | - |
|
| 153 | -- /etc/openvpn/openvpn-shutdown |
|
| 154 | -```bash |
|
| 155 | -#!/bin/bash |
|
| 156 | - |
|
| 157 | -# VPNインタフェース(tun+)用iptablesルール削除関数 |
|
| 158 | -delete() { |
|
| 159 | - rule_number=`iptables -L $target --line-numbers -n -v|grep tun.|awk '{print $1}'|sort -r` |
|
| 160 | - for num in $rule_number |
|
| 161 | - do |
|
| 162 | - iptables -D $target $num |
|
| 163 | - done |
|
| 164 | -} |
|
| 165 | - |
|
| 166 | -# VPNインタフェース(tun+)用iptables受信ルール削除 |
|
| 167 | -target='INPUT' |
|
| 168 | -delete |
|
| 169 | - |
|
| 170 | -# VPNインタフェース(tun+)用iptables転送ルール削除 |
|
| 171 | -target='FORWARD' |
|
| 172 | -delete |
|
| 173 | - |
|
| 174 | -# VPNインタフェース(tun+)用iptables送信ルール削除 |
|
| 175 | -target='OUTPUT' |
|
| 176 | -delete |
|
| 177 | -``` |
|
| 178 | - |
|
| 179 | 133 | - /etc/logrotate.d/openvpn |
| 180 | 134 | ``` |
| 181 | 135 | /var/log/openvpn.log { |
| ... | ... | @@ -195,16 +149,16 @@ delete |
| 195 | 149 | ``` |
| 196 | 150 | |
| 197 | 151 | ## サービス起動 |
| 198 | -- CentOS 7 |
|
| 199 | - ``` |
|
| 200 | - # systemctl enable openvpn@server |
|
| 201 | - # systemctl start openvpn@server |
|
| 202 | - ``` |
|
| 203 | 152 | - CentOS 8 |
| 204 | 153 | ``` |
| 205 | 154 | # systemctl enable openvpn-server@server |
| 206 | 155 | # systemctl start openvpn-server@server |
| 207 | 156 | ``` |
| 157 | +- CentOS 7 |
|
| 158 | + ``` |
|
| 159 | + # systemctl enable openvpn@server |
|
| 160 | + # systemctl start openvpn@server |
|
| 161 | + ``` |
|
| 208 | 162 | |
| 209 | 163 | # クライアント用設定 |
| 210 | 164 | |
| ... | ... | @@ -216,8 +170,8 @@ delete |
| 216 | 170 | |
| 217 | 171 | ## クライアント設定ファイル |
| 218 | 172 | - ファイルをクライアントマシンに転送。 |
| 219 | - - /etc/openvpn/ca.crt |
|
| 220 | - - /etc/openvpn/ta.key |
|
| 173 | + - /etc/openvpn/server/ca.crt |
|
| 174 | + - /etc/openvpn/server/ta.key |
|
| 221 | 175 | - /etc/openvpn/easyrsa3/pki/issued/client1.crt |
| 222 | 176 | - /etc/openvpn/easyrsa3/pki/private/client1.key |
| 223 | 177 | - /usr/share/doc/openvpn/sample/sample-config-files/client.conf |