openvpn examples(5) (NAME) openvpn examples - IP (INTRODUCTION) OpenVPN . OPENVPN PEER-FINGERPRINT OpenVPN peer-fingerprint . (PKI) . PKI ( easy-rsa) . . 1. openvpn ( INSTALL ) (apt/yum/pacman/ports) (). 2. (self-signed) : openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -keyout server.key -out server.crt -nodes -sha256 -days 3650 -subj '/CN=server' 3. (fingerprint) SHA256 OpenSSL : openssl x509 -fingerprint -sha256 -in server.crt -noout : SHA256 Fingerprint=00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff 4. (server.conf): # The server certificate we created in step 1 cert server.crt key server.key dh none dev tun # Listen on IPv6+IPv4 simultaneously proto udp6 # The ip address the server will distribute server 10.8.0.0 255.255.255.0 server-ipv6 fd00:6f76:706e::/64 # A tun-mtu of 1400 avoids problems of too big packets after VPN encapsulation tun-mtu 1400 # The fingerprints of your clients. After adding/removing one here restart the # server # Notify clients when you restart the server to reconnect quickly explicit-exit-notify 1 # Ping every 60s, restart if no data received for 5 minutes keepalive 60 300 # Uncomment the line below if you want to have persistent IP addresses # ifconfig-pool-persist /etc/openvpn/server/ipp.txt # Uncomment the line below to push a DNS server to clients # push "dhcp-option DNS 1.1.1.1" 5. . 6. . o systemd server.crt server.key server.conf /etc/openvpn/server systemctl : sudo mv server.conf server.key server.crt /etc/openvpn/server sudo systemctl start openvpn-server@server 1. OpenVPN 2. . alice . . alice . openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -keyout - -nodes -sha256 -days 3650 -subj '/CN=alice' . : -----BEGIN PRIVATE KEY----- [base64 content] -----END PRIVATE KEY----- ----- -----BEGIN CERTIFICATE----- [base 64 content] -----END CERTIFICATE----- 3. . alice.ovpn : # The name of your server to connect to remote yourserver.example.net client # use a random source port instead the fixed 1194 nobind # Uncomment the following line if you want to route # all traffic via the VPN # redirect-gateway def1 ipv6 # To set a DNS server # dhcp-option DNS 192.168.234.1 -----BEGIN PRIVATE KEY----- [Insert here the key created in step 2] -----END PRIVATE KEY----- -----BEGIN CERTIFICATE----- [Insert here the certificate created in step 2] -----END CERTIFICATE----- # This is the fingerprint of the server that we trust. We generated this fingerprint # in step 2 of the server setup peer-fingerprint 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff # The tun-mtu of the client should match the server MTU tun-mtu 1400 dev tun 4. . OpenSSL x509 : openssl x509 -fingerprint -sha256 -noout -in alice.ovpn : SHA256 Fingerprint=ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00:ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00 5. server.conf . : ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00:ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00 99:88:77:66:55:44:33:22:11:00:ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00:88:77:66:55:44:33 6. () peer-fingerprint ( OpenVPN 2.5 OpenVPN Connect 3.3 ) alice.ovpn . peer-fingerprint . server.crt . alice.ovpn : [...] # Beginning of the file skipped # The tun-mtu of the client should match the server MTU tun-mtu 1400 dev tun [contents of the server.crt] . 7. OpenVPN (Import) openvpn alice.ovpn VPN . (EXAMPLES) OpenVPN . OpenVPN INSTALL OpenVPN . (Firewall Setup): OpenVPN . OpenVPN 1194/udp . --ping 15 openvpn OpenVPN ( UDP (stateful) ). . VPN (VPN Address Setup): bob.example.com alice.example.com . VPN bob.example.com alice.example.com IP . (endpoints) . IP VPN . VPN . bob.example.com 10.4.0.1 alice.example.com 10.4.0.2 . VPN . () VPN () () VPN () VPN . bob.example.com ssh VPN alice.example.com ( ssh ) ssh alice.example.com . telnet 10.4.0.2 telnet alice.example.com VPN ssh VPN . ( 10 192.168 ) (bridging) . (feedback loop) . : ( ) tun --dev OpenVPN tunX . (--dev tun1) . bob: openvpn --remote alice.example.com --dev tun1 \ --ifconfig 10.4.0.1 10.4.0.2 --verb 9 alice: openvpn --remote bob.example.com --dev tun1 \ --ifconfig 10.4.0.2 10.4.0.1 --verb 9 . bob: ping 10.4.0.2 alice: ping 10.4.0.1 --verb 9 tcpdump(8) . OpenVPN --verb 9 . : bob : openssl req -x509 -newkey ec:<(openssl ecparam -name secp384r1) -keyout bob.pem -out bob.pem -nodes -sha256 -days 3650 -subj '/CN=bob' openssl x509 -noout -sha256 -fingerprint -in bob.pem alice: openssl req -x509 -newkey ec:<(openssl ecparam -name secp384r1) -keyout alice.pem -out alice.pem -nodes -sha256 -days 3650 -subj '/CN=alice' openssl x509 -noout -sha256 -fingerprint -in alice.pem bob.pem alice.pem ( ascii) . scp(1) ssh(1) . bob: openvpn --ifconfig 10.4.0.1 10.4.0.2 --tls-server --dev tun --dh none \ --cert bob.pem --key bob.pem --cipher AES-256-GCM \ --peer-fingerprint "$fingerprint_of_alices_cert" alice: openvpn --remote bob.example.com --tls-client --dev tun1 \ --ifconfig 10.4.0.2 10.4.0.1 --cipher AES-256-GCM \ --cert alice.pem --key alice.pem \ --peer-fingerprint "$fingerprint_of_bobs_cert" . bob: ping 10.4.0.2 alice: ping 10.4.0.1 : (secp384) --dh none . : PKI TLS bob TLS alice TLS . : TLS (peer-to-peer) UDP OpenVPN . / bob alice ( --cert ). - (Diffie Hellman) ( --dh ). client.crt client.key server.crt server.key ca.crt . .crt / .key ca.crt client.crt server.crt . - dh2048.pem . : OpenVPN . bob: openvpn --remote alice.example.com --dev tun1 \ --ifconfig 10.4.0.1 10.4.0.2 \ --tls-client --ca ca.crt \ --cert client.crt --key client.key \ --reneg-sec 60 --verb 5 alice: openvpn --remote bob.example.com --dev tun1 \ --ifconfig 10.4.0.2 10.4.0.1 \ --tls-server --dh dh1024.pem --ca ca.crt \ --cert server.crt --key server.key \ --reneg-sec 60 --verb 5 . bob: ping 10.4.0.2 alice: ping 10.4.0.1 --reneg-sec 60 . OpenVPN (renegotiate) . --verb 5 . (production) . OpenVPN --reneg-sec 60 . (Routing): . bob alice . . bob 10.0.0.0/24 alice 10.0.1.0/24 . IP (IP forwarding) . : echo 1 > /proc/sys/net/ipv4/ip_forward (persistent) . IP . . tun/tap OpenVPN . bob: route add -net 10.0.1.0 netmask 255.255.255.0 gw 10.4.0.2 alice: route add -net 10.0.0.0 netmask 255.255.255.0 gw 10.4.0.1 10.0.0.0/24 10.0.1.0/24 ( ). () route --up . openvpn examples(5)