|
| 1 | +# Setup guide |
| 2 | + |
| 3 | +This is simple setup guide to help you get started. It uses the simplest configuration which works nearly out of the box. |
| 4 | + |
| 5 | +## Steps |
| 6 | + |
| 7 | +1. Init configuration directory with initial config files: |
| 8 | + |
| 9 | + ``` bash |
| 10 | + # Starts temporary container, soo you will be able to generate intial config files and opens bash shell in container |
| 11 | + docker run -it --rm --cap-add NET_ADMIN -v </path/to/config>:/config slocomptech/openvpn:latest bash |
| 12 | + ``` |
| 13 | + |
| 14 | +2. At this point you will have bash shell which runs in container. Now run following commands to **setup your PKI**: |
| 15 | + |
| 16 | + ``` bash |
| 17 | + ovpn_init [nopass] # Inits PKI |
| 18 | + #CA settings are located in /config/ssl/vars |
| 19 | + #Did you modified the file or are you planing to enter values interactively ? |
| 20 | + #[y/N]: y |
| 21 | + # |
| 22 | + #init-pki complete; you may now create a CA or requests. |
| 23 | + #Generating DH parameters, 2048 bit long safe prime, generator 2 |
| 24 | + #This is going to take a long time |
| 25 | + #................................. |
| 26 | + #DH parameters of size 2048 created at /config/pki/dh.pem |
| 27 | + # |
| 28 | + #Now it will build CA files for issuing new certifiactes |
| 29 | + #Please protect ca.key with secure password (used for signing new certs) |
| 30 | + #ca.key is needed only for signing new certificates, not for OpenVPN to work |
| 31 | + |
| 32 | + #Using SSL: openssl OpenSSL 1.1.1a 20 Nov 2018 |
| 33 | + #Enter New CA Key Passphrase: <ENTER SECRET PKI PASSWORD> |
| 34 | + #Re-Enter New CA Key Passphrase: <ENTER SECRET PKI PASSWORD> |
| 35 | + #Generating RSA private key, 2048 bit long modulus (2 primes) |
| 36 | + #...............................+++++ |
| 37 | + #You are about to be asked to enter information that will be incorporated |
| 38 | + #into your certificate request. |
| 39 | + #What you are about to enter is what is called a Distinguished Name or a DN. |
| 40 | + #There are quite a few fields but you can leave some blank |
| 41 | + #For some fields there will be a default value, |
| 42 | + #If you enter '.', the field will be left blank. |
| 43 | + #----- |
| 44 | + #Common Name (eg: your user, host, or server name) [Easy-RSA CA]: <COMMON NAME OF YOUR CA> |
| 45 | + # |
| 46 | + #CA creation complete and you may now import and sign cert requests. |
| 47 | + # |
| 48 | + #Generating a RSA private key |
| 49 | + #..............+++++ |
| 50 | + #writing new private key to '/config/pki/private/server.key.osYA8Mim31' |
| 51 | + #----- |
| 52 | + #Enter pass phrase for /config/pki/private/ca.key: <ENTER SECRET PKI PASSWORD> |
| 53 | + #Check that the request matches the signature |
| 54 | + #Signature ok |
| 55 | + #The Subject's Distinguished Name is as follows |
| 56 | + #commonName :ASN.1 12:'server' |
| 57 | + #Certificate is to be certified until Mar 4 21:36:34 2022 GMT (1080 days) |
| 58 | + # |
| 59 | + #Write out database with 1 new entries |
| 60 | + #Data Base Updated |
| 61 | + # |
| 62 | + #You are about to sign the following certificate. |
| 63 | + #Please check over the details shown below for accuracy. Note that this request |
| 64 | + #has not been cryptographically verified. Please be sure it came from a trusted |
| 65 | + #source or that you have verified the request checksum with the sender. |
| 66 | + # |
| 67 | + #Request subject, to be signed as a server certificate for 1080 days: |
| 68 | + # |
| 69 | + #subject= |
| 70 | + # commonName = server |
| 71 | + # |
| 72 | + #Type the word 'yes' to continue, or any other input to abort. |
| 73 | + # Confirm request details: <YES> |
| 74 | + #Enter pass phrase for /config/pki/private/ca.key: <ENTER SECRET PKI PASSWORD> |
| 75 | + #Check that the request matches the signature |
| 76 | + #Signature ok |
| 77 | + #The Subject's Distinguished Name is as follows |
| 78 | + #commonName :ASN.1 12:'server' |
| 79 | + #The matching entry has the following details |
| 80 | + #Type :Valid |
| 81 | + #Expires on :220304213634Z |
| 82 | + #Serial Number :DA40AFDB4E9D5C1D596BA698A2EBC1BE |
| 83 | + #File name :unknown |
| 84 | + #Subject Name :/CN=server |
| 85 | + # |
| 86 | + #Enter pass phrase for /config/pki/private/ca.key: <ENTER SECRET PKI PASSWORD> |
| 87 | + # |
| 88 | + #An updated CRL has been created. |
| 89 | + #CRL file: /config/pki/crl.pem |
| 90 | + ``` |
| 91 | + |
| 92 | + **Note:** You can generate PKI without password, just use `nopass` option. |
| 93 | + |
| 94 | +3. Setup OpenVPN config based on example `basic_nat` with configuration wizard: |
| 95 | + |
| 96 | + ``` bash |
| 97 | + ovpn_enconf basic_nat |
| 98 | + #Protocol udp, tcp, udp6, tcp6 [udp]: |
| 99 | + #VPN network [10.0.0.0]: |
| 100 | + #Port [1194]: |
| 101 | + #Public IP or domain of server: <PUBLIC IP> |
| 102 | + #DNS1 [8.8.8.8]: |
| 103 | + #DNS2 [8.8.4.4]: |
| 104 | + ``` |
| 105 | + |
| 106 | + **Note:** If you are using this container for production use your Public IP (if you don't know it, check with `whatsmyip` website and make sure it is **static**, for testing purposes at home, you can use local IP). |
| 107 | + |
| 108 | +4. Enable **port forwarding** on your router so OpenVPN server will be accessible from the internet. |
| 109 | +5. Add clients to your server |
| 110 | + |
| 111 | + ``` bash |
| 112 | + # Generates client certificates |
| 113 | + ovpn_client add <name> [nopass] |
| 114 | + |
| 115 | + # Generates client config file and prints it to screen (redirect to file) |
| 116 | + ovpn_client ovpn <name> > <config file>.ovpn |
| 117 | + |
| 118 | + # OR BETTER SOLLUTION: Run outside container |
| 119 | + docker exec -it <container name> ovpn_client ovpn <name> > <config file>.ovpn |
| 120 | + ``` |
| 121 | + |
| 122 | +**Note:** Client config files MUST be transported to your devices via **SECURE** methon such as USB (email is considered **INSECURE**). |
| 123 | + |
| 124 | +5. Exit container with `exit`, then it will destroy itself. |
| 125 | +6. Now you can create config file outside container, mentioned above. |
| 126 | +7. If you need to access bash shell again (to add another client after server was started) just use `docker exec -it <container name> bash`. |
| 127 | +8. Start container using normal command: |
| 128 | + |
| 129 | + ``` bash |
| 130 | + docker run \ |
| 131 | + --name=ovpn \ |
| 132 | + --cap-add NET_ADMIN \ |
| 133 | + -e PUID=1000 \ |
| 134 | + -e GUID=1000 \ |
| 135 | + -p 1194:1194/udp \ |
| 136 | + -v </path/o/config>:/config \ |
| 137 | + --restart=unless-stopped \ |
| 138 | + --network host \ |
| 139 | + slocomptech/openvpn:latest |
| 140 | + ``` |
| 141 | + |
| 142 | +**Note:** PUID, GUID parameters are optional. |
| 143 | +**Note:** Container in this example will connect to host network, so there is less network overhead (recommended), this also works if container is in default docker network. |
0 commit comments