Raspberry_Pi4_ _openvpn - yokohama/oreshic-record GitHub Wiki
Date: 2023-07-19 16:35:43
vpnã®äžãããã©ãŠã¶ã§ããŒã ããŒãžãèŠãããšãããšãhttpsãèµ€ããªã£ããä¿¡é ŒãããŠããªããšèšãããããšããããiptablesã®natãåå ã調æ»äžããã®ä»ã¯åé¡ãªãã
ç©çæ§æã¯ä»¥äžã®ãããªæãã

äžèšã®ç©çæ§æãå€ããã«openvpnã䜿çšããŠã以äžã®ãããªè«çãããã¯ãŒã¯ïŒä»®æ³LANïŒã远å ã§æ§æããŠvpnclientã®ããŒãPCãLANãããã¯ãŒã¯ã«ã¢ã¯ã»ã¹å¯èœã«ããŸãã

ä»å䜿çšããVPNã®æ¥ç¶æ¹æ³ã¯ãopneVPNã䜿çšããŸããä»ã«ã¯ãL2TPãšãããã®ããããŸããopenVPNã¯ãµãŒããŒãšã¯ã©ã€ã¢ã³ããäºãã«èšŒææžã䜿çšããèªèšŒãå¯èœãšãªããŸããèšŒææžãå¿ èŠãšãªãã®ã§èšŒææžã®èªèšŒå±(CA)ãå¿ èŠãšãªããä»åCAã¯opnevpnãéçºããŠããããeasy-rsaãã䜿çšããŸãã
| é ç® | OpenVPN | L2TP |
|---|---|---|
| ãµããªãŒ | ã»ãã¥ã¢ãªãªã¢ãŒãã¢ã¯ã»ã¹ãæäŸããVPNãããã³ã« | ã¬ã€ã€ãŒ2ãã³ããªã³ã°ãããã³ã« |
| å©çšã·ãŒã³ | ã€ã³ã¿ãŒãããçµç±ã§ã®å®å šãªãªã¢ãŒãã¢ã¯ã»ã¹ | ãã¡ã€ã«å ±æããªã¢ãŒãã¢ã¯ã»ã¹ãVPNã¢ã¯ã»ã¹ |
| èªèšŒæ¹æ³ | ãŠãŒã¶ãŒåãšãã¹ã¯ãŒããèšŒææžãå ±æéµ | ãŠãŒã¶ãŒåãšãã¹ã¯ãŒããããªã·ã§ã¢ãŒãã㌠|
| ã»ãã¥ãªãã£åŒ·åºŠ | é«ã | æšæº |
| OSI 7éå±€ã®ã¬ã€ã€ãŒ | ã¬ã€ã€ãŒ3ïŒãããã¯ãŒã¯å±€ïŒ | ã¬ã€ã€ãŒ2ïŒããŒã¿ãªã³ã¯å±€ïŒ |
| ããäžç·ã«å©çšããããããã³ã« | TLS (Transport Layer Security) | IPsec (Internet Protocol Security) |
VPNãµãŒããŒãšã¯ã©ã€ã¢ã³ããšã§ä»¥äžã®ãã¡ã€ã«ãé åããŠãVPNæ¥ç¶ã®èªèšŒãèšŒææžããŒã¹ã§ãããªãã
| åå | ãã¡ã€ã«å | 説æ |
|---|---|---|
| CAèšŒææž | ca.crt | æ¥ç¶ããŠããã¯ã©ã€ã¢ã³ãã®èšŒææžã®æ£åœæ§ã蚌æããŠãããèªèšŒæ©é¢ãšããŠäœ¿çšããããµãŒããŒãšã¯ã©ã€ã¢ã³ãã§åããã®ã䜿çšããã |
| ãµãŒããŒèšŒææž | server.crt | ã¯ã©ã€ã¢ã³ãããµãŒããŒã確èªããããã«äœ¿çšããŸããäžã«ã¯ãµãŒããŒå ¬ééµãå«ãŸããŸãã |
| ãµãŒããŒç§å¯éµ | server.key | ãµãŒããŒãµã€ãã®ã¿ã§äœ¿çšããç§å¯éµã§ããã¯ã©ã€ã¢ã³ãããµãŒããŒå ¬ééµã§æå·ããããŒã¿ã®è€åã«äœ¿çšããŸãã |
| TSLèªèšŒå ±ééµ | ta.key | ã¯ã©ã€ã¢ã³ããšãµãŒããŒã§å ±éã®éµãæã¡ãŸããTLSãã³ãã·ã§ã€ã¯ã«HMAC眲åã远å ããŠã»ãã¥ãªãã£ã匷åããŸãã |
| DHèªèšŒç§å¯éµ | dh.pem | ãµãŒããŒå ±ééµãšã¯ã©ã€ã¢ã³ãå ±ééµã®ããåããããéã«ãDiffie-Hellmanæ¹åŒã䜿çšããŸãã |
| ãµãŒããŒèšå®ãã¡ã€ã« | server.conf | openvpnãµãŒããŒã®èšå®ãã¡ã€ã«ã§ãã |
| åå | ãã¡ã€ã«å | 説æ |
|---|---|---|
| CAèšŒææž | ca.crt | æ¥ç¶ããã¿ãŒããŒã®èšŒææžã®æ£åœæ§ã蚌æããŠãããèªèšŒæ©é¢ãšããŠäœ¿çšããããµãŒããŒãšã¯ã©ã€ã¢ã³ãã§åããã®ã䜿çšããã å®éã¯ãã¡ã€ã«ã§ã¯ãªããclient.ovpnãã¡ã€ã«ã®äžã«èšè¿°ã |
| ã¯ã©ã€ã¢ã³ãèšŒææž | client.crt | ãµãŒããŒãã¯ã©ã€ã¢ã³ãã確èªããããã«äœ¿çšããŸããäžã«ã¯ã¯ã©ã€ã¢ã³ãå
¬ééµãå«ãŸããŸãã å®éã¯ãã¡ã€ã«ã§ã¯ãªããclient.ovpnãã¡ã€ã«ã®äžã«èšè¿°ã |
| ã¯ã©ã€ã¢ã³ãç§å¯éµ | client.key | ã¯ã©ã€ã¢ã³ããµã€ãã®ã¿ã§äœ¿çšããç§å¯éµã§ãããµãŒããŒãã¯ã©ã€ã¢ã³ãå
¬ééµã§æå·ããããŒã¿ã®è€åã«äœ¿çšããŸãã å®éã¯ãã¡ã€ã«ã§ã¯ãªããclient.ovpnãã¡ã€ã«ã®äžã«èšè¿°ã |
| TSLèªèšŒå ±ééµ | ta.key | ã¯ã©ã€ã¢ã³ããšãµãŒããŒã§å
±éã®éµãæã¡ãŸããTLSãã³ãã·ã§ã€ã¯ã«HMAC眲åã远å ããŠã»ãã¥ãªãã£ã匷åããŸãã å®éã¯ãã¡ã€ã«ã§ã¯ãªããclient.ovpnãã¡ã€ã«ã®äžã«èšè¿°ã |
| ã¯ã©ã€ã¢ã³ãèšå®ãã¡ã€ã« | client.ovpn | ã¯ã©ã€ã¢ã³ãã®openvpnã®æ¥ç¶èšå®ãã¡ã€ã«ã |

openvpnãéçºãããeasy-rsaããšããPKIåºç€ã䜿çšããŠãåçš®èšŒææžã®çºè¡ãšç®¡çãè¡ãªããŸããeasy-rsaã§çºè¡ãããã¯ã©ã€ã¢ã³ããšãµãŒããŒã§äœ¿çšããåçš®ã®èšŒææžãã¡ã€ã«çããæçµçã«ã¯openvpnãµãŒããŒã§äœ¿çšã§ããããã«ãopenvpnã®é©åãªãã©ã«ãã«æ ŒçŽããŸãã
$ sudo apt install easy-rsa
# äœãå
¥ã£ããæ¢ããŠã¿ã
$ find / -name 'easy-*' 2>/dev/null
/var/lib/dpkg/info/easy-rsa.list
/var/lib/dpkg/info/easy-rsa.md5sums
/etc/openvpn.back/easy-rsa
/etc/openvpn/easy-rsa
/usr/share/doc/easy-rsa
/usr/share/easy-rsa
# /usr/share/easy-rsaã®äžèº«ãèŠãŠã¿ã
$ sudo tree /usr/share/easy-rsa
/usr/share/easy-rsa
âââ easyrsa
âââ openssl-easyrsa.cnf
âââ vars.example
âââ x509-types
âââ ca
âââ client
âââ code-signing
âââ COMMON
âââ email
âââ kdc
âââ server
âââ serverClient
# make-cadirãäžç·ã«ã€ã³ã¹ããŒã«ãããŠãã
$ which make-cadir
/usr/bin/make-cadir
easy-rsaã®ã€ã³ã¹ããŒã«æã«ããmake-cadirããåæã«ã€ã³ã¹ããŒã«ãããŸããããã¯openvpnåŽã§èšŒææžçã管çããéã®å¿ èŠãªãã¡ã€ã«ã管çïŒçæããããã«äœ¿çšãããã£ã¬ã¯ããªãäœæããŠããã䟿å©ããŒã«ã§ããåŸã»ã©äœ¿çšããŸãã
èšŒææžã®ç®¡ççšã«ãŠãŒã¶ãŒãäœæããŸãã以éã®äœæ¥ã¯å šãŠãã®ãŠãŒã¶ãŒã§ãããªããŸããrootã§ã®çŽæ¥ã®äœæ¥ã¯ãããŸãããã
$ sudo adduser ca-admin
/etc/sudoers.dã®äžã®ãã¡ã€ã«ãç·šéããŠããca-adminãã远å ããŠããã
$ sudo apt install openvpn
# åæã®ç¶æ
ãèŠãŠã¿ã
$ sudo tree /etc/openvpn/
/etc/openvpn/
âââ client
âââ server
âââ update-resolv-con
ä»åŸã¯ä»¥äžã®ãã£ã¬ã¯ããªã§äœæ¥ãé²ããã®ã§ç§»åããŸãã
$ cd /etc/openvpn
easy-rsaã®ã€ã³ããŒã«æã«ã€ã³ã¹ããŒã«ããããmake-cadirãã䜿çšããŠãopenvpnã®äžã«èšŒææžé¢é£ã®ãã£ã¬ã¯ããªããã¡ã€ã«ãäœæããŸãã
ca-admin$ cd /etc/openvpn
ca-admin$ sudo make-cadir easy-rsa
### ca-adminãäœæ¥ã§ããããã«ãäœæããããeasy-rsaããã£ã¬ã¯ããªã®ãªãŒããŒã倿Žã
ca-admin $ sudo su -
root# chown ca-admin.ca-admin easy-rsa
root# exit
### äœãåºæ¥ãã確èª
ca-admin$ sudo tree .
.
âââ client
âââ easy-rsa
â âââ easyrsa -> /usr/share/easy-rsa/easyrsa
â âââ openssl-easyrsa.cnf
â âââ vars
â âââ x509-types -> /usr/share/easy-rsa/x509-types
âââ server
âââ update-resolv-conf
äžèšã§äœæããããvarsããã¡ã€ã«ãç·šéããŸããæåã¯äœãããããæžããŠããã
# Easy-RSA 3 parameter settings
# NOTE: If you installed Easy-RSA from your distro's package manager, don't edit
# this file in place -- instead, you should copy the entire easy-rsa directory
# to another location so future upgrades don't wipe out your changes.
# HOW TO USE THIS FILE
#
# vars.example contains built-in examples to Easy-RSA settings. You MUST name
# this file 'vars' if you want it to be used as a configuration file. If you do
# not, it WILL NOT be automatically read when you call easyrsa commands.
#
# It is not necessary to use this config file unless you wish to change
# operational defaults. These defaults should be fine for many uses without the
# need to copy and edit the 'vars' file.
#
# All of the editable settings are shown commented and start with the command
# 'set_var' -- this means any set_var command that is uncommented has been
# modified by the user. If you're happy with a default, there is no need to
# define the value to its default.
# NOTES FOR WINDOWS USERS
#
# Paths for Windows *MUST* use forward slashes, or optionally double-escaped
# backslashes (single forward slashes are recommended.) This means your path to
# the openssl binary might look like this:
# "C:/Program Files/OpenSSL-Win32/bin/openssl.exe"
# A little housekeeping: DON'T EDIT THIS SECTION
#
# Easy-RSA 3.x doesn't source into the environment directly.
# Complain if a user tries to do this:
if [ -z "$EASYRSA_CALLER" ]; then
echo "You appear to be sourcing an Easy-RSA 'vars' file." >&2
echo "This is no longer necessary and is disallowed. See the section called" >&2
echo "'How to use this file' near the top comments for more details." >&2
return 1
fi
## (以äžãçç¥ïŒ##
å šéšæ¶ããŠã以äžã®ïŒè¡ã ãã«ç·šéããããã®èšå®ã¯èšŒææžãäœæããéã®æå·ã¢ã«ãŽãªãºã ãšããã·ã¥é¢æ°ãæå®ãããã®ã§ãã
-
set_var EASYRSA_ALGO "ec": èšŒææžã®éµãã¢çæã«äœ¿çšããæå·ã¢ã«ãŽãªãºã ãæå®ããŸãããã®èšå®ã§ã¯ãæ¥åæ²ç·æå·ïŒelliptic curve cryptography, ECCïŒã䜿çšããŠããŸããECCã¯åŸæ¥ã®RSAæå·ãããå¹ççã§ãããåãã»ãã¥ãªãã£ã¬ãã«ãå®çŸããããã«çãéµé·ãå¿ èŠã§ãã
-
set_var EASYRSA_DIGEST "sha512": èšŒææžã®ããã·ã¥é¢æ°ãæå®ããŸãããã®èšå®ã§ã¯ãSHA-512ããã·ã¥é¢æ°ã䜿çšããŠããŸããSHA-512ã¯å®å šæ§ãé«ãããã匷åãªããã·ã¥å€ãçæããŸãã
ca-admin$ cat easy-rsa/vars
set_var EASYRSA_ALGO "ec"
set_var EASYRSA_DIGEST "sha512"
ã³ã³ããã®äœæ¥ã¯ã./easy-rsaã«ç§»åããŸãã
ca-admin$ cd easy-rsa
ã©ããªãã¡ã€ã«ããããã確èªã
ca-admin$ tree .
.
âââ easyrsa -> /usr/share/easy-rsa/easyrsa
âââ openssl-easyrsa.cnf
âââ vars
âââ x509-types -> /usr/share/easy-rsa/x509-types
PKIïŒPublic Key Infrastracturãå ¬éããŒåºç€ïŒã®ãã©ã«ããäœæããã以äžã®ã³ãã³ãã§èªèšŒå±ãåæåããŸããèªèšŒå±ã®èšçœ®æã«ïŒåºŠã ãè¡ãªããŸãã
easyrsaãšããã³ãã³ããã³ããŒãããŠããã®ã§ãã³ã¬ã䜿ããŸãã
ca-admin$ sudo ./easyrsa init-pki
init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /etc/openvpn/easy-rsa/pki
ã©ããªã£ãã確èªããŠã¿ããpkiãšãããã£ã¬ã¯ããªãäœæãããŠããã
ca-admin$ sudo tree .
.
âââ easyrsa -> /usr/share/easy-rsa/easyrsa
âââ openssl-easyrsa.cnf
âââ pki
â âââ openssl-easyrsa.cnf
â âââ private
â âââ reqs
â âââ safessl-easyrsa.cnf
âââ vars
âââ x509-types -> /usr/share/easy-rsa/x509-typeses
èªèšŒå±ãäœæããããååãªãã«ããïŒãã£ãŠïŒåºŠã ãèããããã©ãããã©ã«ãã®ãŸãŸã§ãšã³ã¿ãŒã
ca-admin$ sudo ./easyrsa build-ca nopass
Using SSL: openssl OpenSSL 1.1.1n 15 Mar 2022
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]:
CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/etc/openvpn/easy-rsa/pki/ca.crt
äœãã§ãããèŠãŠã¿ãã
ca-admin$ sudo tree .
.
âââ easyrsa -> /usr/share/easy-rsa/easyrsa
âââ openssl-easyrsa.cnf
âââ pki
â âââ ca.crt
â âââ certs_by_serial
â âââ index.txt
â âââ index.txt.attr
â âââ issued
â âââ openssl-easyrsa.cnf
â âââ private
â â âââ ca.key
â âââ renewed
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ reqs
â âââ revoked
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ safessl-easyrsa.cnf
â âââ serial
âââ vars
âââ x509-types -> /usr/share/easy-rsa/x509-types
ããã§ã¯ã以äžãäœæãããŠããã°OKã§ãã
- pki/ca.crtïŒCAèšŒææžïŒ
- pki/private/ca.keyïŒCAç§å¯éµïŒ
â»ãserverãã®éšåã¯ä»»æãç§å¯éµãšèšŒææžçœ²åèŠæ±ãã¡ã€ã«ã®ååã«äœ¿ãããã
ã蚌æå¯Ÿè±¡ã®ãµãŒããŒã®ååã¯ãªãã«ããïŒãã£ãŠèããŠããããã³ãã³ãã®ãªãã·ã§ã³ã§ããŠãããããã©ã«ãïŒserverïŒã®ãŸãŸã§ãšã³ã¿ãŒã
ca-admin$ sudo ./easyrsa gen-req server nopass
Using SSL: openssl OpenSSL 1.1.1n 15 Mar 2022
Generating a RSA private key
...........................................+++++
..............................................+++++
writing new private key to '/etc/openvpn/easy-rsa/pki/easy-rsa-1693.iCGDZm/tmp.pa6uG0'
-----
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) [server]:
Keypair and certificate request completed. Your files are:
req: /etc/openvpn/easy-rsa/pki/reqs/server.req
key: /etc/openvpn/easy-rsa/pki/private/server.key
ãªã«ãã§ãããèŠãŠã¿ãã
ca-admin$ sudo tree .
.
âââ easyrsa -> /usr/share/easy-rsa/easyrsa
âââ openssl-easyrsa.cnf
âââ pki
â âââ ca.crt
â âââ certs_by_serial
â âââ index.txt
â âââ index.txt.attr
â âââ issued
â âââ openssl-easyrsa.cnf
â âââ private
â â âââ ca.key
â â âââ server.key
â âââ renewed
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ reqs
â â âââ server.req
â âââ revoked
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ safessl-easyrsa.cnf
â âââ serial
âââ vars
âââ x509-types -> /usr/share/easy-rsa/x509-types
ããã§ã¯ä»¥äžã®ãã¡ã€ã«ãäœæãããŠããã°OKã§ãã
- pki/private/server.keyïŒãµãŒããŒç§å¯éµïŒ
- pki/reqs/server.req
ãµãŒãèšŒææžã«çœ²åããéã¯ãåŒæ°ãå ã»ã©äœæããèšŒææžçœ²åèŠæ±ãserver.reqããæå®ããïŒæ¡åŒµåã¯äžèŠïŒãèŠæ±ãåãå ¥ãããã®ç¢ºèªãããŠããã®ã§ããyesããšã¿ã€ãã
ca-admin$ sudo ./easyrsa sign-req server server
Using SSL: openssl OpenSSL 1.1.1n 15 Mar 2022
You are about to sign the following certificate.
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.
Request subject, to be signed as a server certificate for 825 days:
subject=
commonName = server
Type the word 'yes' to continue, or any other input to abort.
Confirm request details: yes
...............................+++++
Using configuration from /etc/openvpn/easy-rsa/pki/easy-rsa-1737.yuvuQ4/tmp.epovku
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'server'
Certificate is to be certified until Oct 17 09:29:28 2025 GMT (825 days)
Write out database with 1 new entries
Data Base Updated
Certificate created at: /etc/openvpn/easy-rsa/pki/issued/server.crt
ãªã«ãã§ããã確èª
# tree .
.
âââ easyrsa -> /usr/share/easy-rsa/easyrsa
âââ openssl-easyrsa.cnf
âââ pki
â âââ ca.crt
â âââ certs_by_serial
â â âââ 9403D6EBE1885C65C36D2DFD8753769E.pem
â âââ index.txt
â âââ index.txt.attr
â âââ index.txt.attr.old
â âââ index.txt.old
â âââ issued
â â âââ server.crt
â âââ openssl-easyrsa.cnf
â âââ private
â â âââ ca.key
â â âââ server.key
â âââ renewed
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ reqs
â â âââ server.req
â âââ revoked
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ safessl-easyrsa.cnf
â âââ serial
â âââ serial.old
âââ vars
âââ x509-types -> /usr/share/easy-rsa/x509-types
ããã§ã¯ä»¥äžã®ãã¡ã€ã«ãäœæãããŠããã°OKã§ãã
- pki/issued/server.crtïŒãµãŒããŒèšŒææžïŒ
Diffie-Hellman éµäº€æã¯ãæå·éµãå®å šã«è»¢éããããã«äœ¿çšãããæ¹æ³ã§ãã
ã³ãã³ãå®è¡ãããšçµæ§ãŸã¡ãŸãããã
# ./easyrsa gen-dh
以äžã®ãã¡ã€ã«ãäœæãããŸãã
- pki/dh.pemãã¡ã€ã«ãäœæãããã
openvpnã§ã¯ãã»ãã¥ãªãã£ãåäžãããããã« TLS-AuthããŒ(ta.key)ãå®è£ ããŠããŸããå šãŠã®TLSãã³ãã·ã§ã€ã¯ã«HMAC眲åã远å ããããã«ãã¯ã©ã€ã¢ã³ããšãµãŒããŒã§äœ¿çšããå ±ééµãäœæããŸãã
# openvpn --genkey secret ta.key
以äžã®ãã¡ã€ã«ãäœæãããŸãã
- ta.key
å¿ èŠãªãã¡ã€ã«ã¯ä»¥äžã®ãã®ã«ãªãã
- ca.crt
- server.crt
- server.key
- dh2048.pem
- ta.key
äžèšã®ãã¡ã€ã«ãã/etc/openvpn/server/ããã£ã¬ã¯ããªã®é äžã«ã³ããŒããŸãã
ca-admin$ sudo cp pki/ca.crt ../server/
ca-admin$ sudo cp pki/issued/server.crt ../server/
ca-admin$ sudo cp pki/private/server.key ../server/
ca-admin$ sudo cp pki/dh.pem ../server/
ca-admin$ sudo cp ta.key ../server/
ca-admin$ ls ../server/
ca.crt dh.pem server.crt server.key ta.key
ããã©ã«ãã®ãŸãŸã ãšãopenvpnãµãŒãã®æ§æãã¡ã€ã«ã¯ã/etc/openvpnããã©ã«ãã«ã¯ååšããªããããopenvpnããã±ãŒãžã«ä»å±ããŠããæ§æãã¡ã€ã«ã®ãã³ãã¬ãŒããã³ããŒããŠããå¿ èŠããããŸãã
ca-admin$ sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf ../server/
ca-admin$ ls ../server/
ca.crt dh.pem server.conf server.crt server.key ta.key
OpenVPNãµãŒãã®æ§æãã¡ã€ã«ãç·šéããŸãã以äžã®è¡ãç·šéã»è¿œèšããŸãã
78 ca ca.crt #ãã®ãŸãŸ
79 cert server.crt #ãã®ãŸãŸ
80 key server.key #ãã®ãŸãŸ
85 dh dh.pem #dh_2048.pemãdh.pemã«å€æŽ
142 push "route 192.168.1.0 255.255.255.0" #ã³ã¡ã³ãã¢ãŠããèªåã®LANã®ã¢ãã¬ã¹ã«å€æŽã
244 tls-auth ta.key 0 #ãã®ãŸãŸ
æ¥ç¶ããŠããã¯ã©ã€ã¢ã³ããèå¥ã§ããããã«ãååãèããããä»åã¯ãtestããšãããã
ca-admin$ sudo ./easyrsa gen-req client nopass
Using SSL: openssl OpenSSL 1.1.1n 15 Mar 2022
Generating a RSA private key
...+++++
.......................................................+++++
writing new private key to '/etc/openvpn/easy-rsa/pki/easy-rsa-2156.tty8u8/tmp.96r0wc'
-----
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) [client]:test
Keypair and certificate request completed. Your files are:
req: /etc/openvpn/easy-rsa/pki/reqs/client.req
key: /etc/openvpn/easy-rsa/pki/private/client.key
ãªã«ãã§ãããïŒ
ca-admin$ sudo tree .
.
âââ easyrsa -> /usr/share/easy-rsa/easyrsa
âââ openssl-easyrsa.cnf
âââ pki
â âââ ca.crt
â âââ certs_by_serial
â â âââ 9403D6EBE1885C65C36D2DFD8753769E.pem
â âââ dh.pem
â âââ index.txt
â âââ index.txt.attr
â âââ index.txt.attr.old
â âââ index.txt.old
â âââ issued
â â âââ server.crt
â âââ openssl-easyrsa.cnf
â âââ private
â â âââ ca.key
â â âââ client.key
â â âââ server.key
â âââ renewed
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ reqs
â â âââ client.req
â â âââ server.req
â âââ revoked
â â âââ certs_by_serial
â â âââ private_by_serial
â â âââ reqs_by_serial
â âââ safessl-easyrsa.cnf
â âââ serial
â âââ serial.old
âââ ta.key
âââ vars
âââ x509-types -> /usr/share/easy-rsa/x509-types
ããã§ã¯ä»¥äžã®ãã¡ã€ã«ãäœæãããŠããã°OKã§ãã
- pki/private/client.keyïŒã¯ã©ã€ã¢ã³ãç§å¯éµïŒ
- pki/reqs/client.req
ã¯ã©ã€ã¢ã³ãèšŒææžã«çœ²åããéã¯ãåŒæ°ãå ã»ã©äœæããèšŒææžçœ²åèŠæ±ãclient_test.reqããæå®ãããïŒæ¡åŒµåã¯äžèŠïŒãèŠæ±ãåãå ¥ããã確èªããŠããã®ã§ããyesããšå ¥åã
ca-admin$ sudo ./easyrsa sign-req client client
Using SSL: openssl OpenSSL 1.1.1n 15 Mar 2022
You are about to sign the following certificate.
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.
Request subject, to be signed as a client certificate for 825 days:
subject=
commonName = test
Type the word 'yes' to continue, or any other input to abort.
Confirm request details: yes
Using configuration from /etc/openvpn/easy-rsa/pki/easy-rsa-2209.1K7Pp7/tmp.MNAwKK
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'test'
Certificate is to be certified until Oct 17 09:52:56 2025 GMT (825 days)
Write out database with 1 new entries
Data Base Updated
Certificate created at: /etc/openvpn/easy-rsa/pki/issued/client.crt
ããã§ã¯ä»¥äžã®ãã¡ã€ã«ãäœæãããŸãã
- pik/issued/client_test.crtïŒã¯ã©ã€ã¢ã³ãèšŒææžïŒ
ããã©ã«ãã®ãŸãŸã ãšãopenvpnã¯ã©ã€ã¢ã³ãã®æ§æãã¡ã€ã«ã¯ã/etc/openvpnããã©ã«ãã«ã¯ååšããªããããopenvpnããã±ãŒãžã«ä»å±ããŠããæ§æãã¡ã€ã«ã®ãã³ãã¬ãŒããã³ããŒããŠããå¿ èŠãããã
ca-admin$ sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ../client/
以äžã®è¡ãç·šéããŸãã
42 remote xx.xx.xx.xx 1194 # ã«ãŒã¿ãŒWANåŽIPã¢ãã¬ã¹
61 user nobody # ã³ã¡ã³ãã®ã;ããæ¶ã
62 group nogroup # ã³ã¡ã³ãã®ã;ããæ¶ã
88è¡ç®ã®ãca ca.crtïŒCAèšŒææžïŒãã³ã¡ã³ãããŠã以äžã®å
容ãçŽæ¥èšè¿°ã
<ca>
# pki/ca.crtãã¡ã€ã«ã®å
容ããã®ãŸãŸã³ãã
</ca>
89è¡ç®ã®ãcert client.crtïŒã¯ã©ã€ã¢ã³ãèšŒææžïŒãã³ã¡ã³ãããŠã以äžã®å
容ãçŽæ¥èšè¿°
<cert>
# pki/issued/client.certãã¡ã€ã«ã®å
容ããã®ãŸãŸã³ãã
</cert>
90è¡åã®key client.keyïŒã¯ã©ã€ã¢ã³ãç§å¯ããŒïŒãã³ã¡ã³ãããŠã以äžã®å
容ãçŽæ¥èšè¿°ã
<key>
# pki/private/client.keyãã¡ã€ã«ã®å
容ããã®ãŸãŸã³ãã
</key>
以äžãäžçªæåŸãããã«ã远èš
key-direction 1
æŽã«ãäžçªäžã«ãTLSèªèšŒã®å ±éããŒãèšå ¥
<tls-auth>
# ta.keyã®å
容ãã³ãã
</tls-auth>
æåŸã«ã¯ã©ã€ã¢ã³ãã«é åžããããã«ãclient.confã®æ¡åŒµåã倿ŽããŸãã
ca-admin$ sudo mv ../client/client.conf ../client/client.ovpn
systemctlãã€ãã£ãŠèšå®ããããªããŸãã
# OSèµ·åæã«èµ·åãã
ca-admin$ sudo systemctl -f enable [email protected]
# èµ·å
ca-admin$ systemctl start [email protected]
èµ·åã®èšå®ãã¡ã€ã«ã®äžèº«ã確èªãããå Žåã¯ãã/etc/systemd/system/multi-user.target.wants/[email protected]ããåç §ã
port1194ãUDPã§ãªãŒãã³ããŠããã°OKã
ca-admin$ ss -antu | grep 1194
udp UNCONN 0 0 0.0.0.0:1194 0.0.0.0:*

ãã®å³ã®ãšãããvpnãµãŒããŒã¯ã192.168.1.0/24ãã®ãããã¯ãŒã¯ãšãã10.8.0.0/30ãã®ãããã¯ãŒã¯ã«æå±ããŠãããã¯ã©ã€ã¢ã³ãããLANã«æ¥ç¶ããã«ã¯ãvpnãµãŒããŒã§IP転éã®èšå®ãããå¿ èŠãããã
ã/etc/sysctd.confããç·šéã以äžã®ïŒè¡ã远å ããããã¯æ¢ã«ååšããå Žåã¯å€ãã1ãã«ä¿®æ£ã
net.ipv4.ip_forward=1
èšå®ãåæ ãããã
ca-admin$ sudo sysctl -p
natãèšå®ããã10.8.0.0/24ã®ãããã¯ãŒã¯ããæ¥ããã±ããã§ãeth0ïŒ192.168.1.0/24ïŒã«åºãŠãããã±ãããMASQUERADEã
ca-admin$ sudo iptables -t nat -A POSTROUTING -o eth0 -s 10.8.0.0/24 -j MASQUERADE
確èªã
ca-admin$ sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 60084 packets, 15M bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 8300 packets, 1574K bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 5 packets, 616 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 19 packets, 2758 bytes)
pkts bytes target prot opt in out source destination
884 125K MASQUERADE all -- * eth0 10.8.0.0/24 0.0.0.0/0
ãã±ãã転éãèš±å¯ã
ca-admin$ sudo iptables -A FORWARD -i tun0 -o eth0 -j ACCEPT
ca-admin$ sudo iptables -A FORWARD -i eth0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
確èªã
ca-admin$ iptables -L -n -v
Chain INPUT (policy ACCEPT 172K packets, 38M bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 112 packets, 22353 bytes)
pkts bytes target prot opt in out source destination
28943 3272K ACCEPT all -- tun0 eth0 0.0.0.0/0 0.0.0.0/0
111K 143M ACCEPT all -- eth0 tun0 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT 142K packets, 152M bytes)
pkts bytes target prot opt in out source destination
äœæããiptablesã®ã«ãŒã«ãä¿åããå¿ èŠãæããŸããiptables-persistentã䜿ããšã³ãã³ãã§æå®ããã«ãŒã«ãã/etc/iptables/rules.v4ã«ä¿åããŠããµãŒããŒåèµ·åæã«ãåãèšå®ãåæ ãããããšãã§ããŸãã
ca-admin$ apt install iptabels-persistent
ã€ã³ã¹ããŒã«äžã«ããæ¢ã«iptablesã®ã«ãŒã«ããããŸããä¿åããŸããïŒããšèããŠããã®ã§ãyesãéžæãããšãä¿åãããã
ä¿åããã«ãŒã«ãã¡ã€ã«ããµãŒããŒèµ·åæã«åæ ãããèšå®ãããŸããaptã§ã€ã³ã¹ããŒã«ãããã±ãŒãžã¯ãiptables-persistentãã ãã©ãsystemctlããåŒã³åºãã®ã¯ãnetfilter-persistentããªã®ã§ããããããã§ãã
# èµ·åæã«æå¹å
ca-admin$ systemctl enable netfilter-persistent.service
# ä»ã¹ã°åæ
ca-admin$ systemctl start netfilter-persistent.service

openvpnã®ããŒãïŒ1194ïŒã¯ãLANã®äžã§éããŠãããããã«ãŒã¿ãŒã®WANåŽã«ãåãããŒããéæŸããŠãWANåŽã®1194ãžã®UDPã¢ã¯ã»ã¹ã¯ãLANå ã®ã192.168.1.96ãã®ãudp: 1194ãã«è»¢éããèšå®ããããªããŸãã
å çšäœæããããclient.ovpnããã¡ã€ã«ãã¯ã©ã€ã¢ã³ãã«é åžããŠãã¯ã©ã€ã¢ã³ãã§openvpnã䜿çšããŠæ¥ç¶ã§ããã°å®äºã§ãã