pkg update<\/code><\/pre>\nInstall OpenVPN and Easy-RSA packages<\/p>\n
pkg install openvpn easy-rsa<\/code><\/pre>\nCreate a directory to store the server configuration files, the CA, server keys and certificate files.<\/p>\n
mkdir -p \/usr\/local\/etc\/openvpn\/easy-rsa<\/code><\/pre>\nmkdir \/usr\/local\/etc\/openvpn\/server<\/code><\/pre>\nCopy the sample OpenVPN and Easy-RSA sample configuration files to the respective configuration directories created above.<\/p>\n
cp \/usr\/local\/share\/examples\/openvpn\/sample-config-files\/server.conf \/usr\/local\/etc\/openvpn\/server\/<\/code><\/pre>\ncp -r \/usr\/local\/share\/easy-rsa\/* \/usr\/local\/etc\/openvpn\/easy-rsa\/<\/code><\/pre>\nGenerate the Local CA, Keys and Certificate files with EasyRSA<\/h3>\n
The certificate variables are set in the \/usr\/local\/etc\/openvpn\/easy-rsa\/vars<\/code> file. In order to ease the generation of the certificate, edit this file, uncomment and adjust the certificate values as follows;<\/p>\nvim \/usr\/local\/etc\/openvpn\/easy-rsa\/vars<\/code><\/pre>\nset_var EASYRSA_REQ_COUNTRY\t\"KE\"\r\nset_var EASYRSA_REQ_PROVINCE\t\"Nairobi\"\r\nset_var EASYRSA_REQ_CITY\t\"Nairobi\"\r\nset_var EASYRSA_REQ_ORG\t\t\"Kifarunix\"\r\nset_var EASYRSA_REQ_EMAIL\t\"admin@kifarunix.com\"\r\nset_var EASYRSA_REQ_OU\t\t\"Infrastructure\"\r\nset_var EASYRSA_KEY_SIZE\t2048\r\nset_var EASYRSA_CA_EXPIRE\t3650\r\nset_var EASYRSA_CERT_EXPIRE\t3650<\/code><\/pre>\nEasy-RSA ships with certificate generation script called easyrsa.real<\/code>. To generare the certificate files, navigate to \/usr\/local\/etc\/openvpn\/easy-rsa\/<\/code> directory and proceed as follows;<\/p>\nInitialize the PKI<\/p>\n
cd \/usr\/local\/etc\/openvpn\/easy-rsa<\/code><\/pre>\nsh .\/easyrsa.real init-pki\r\nNote: using Easy-RSA configuration from: .\/vars\r\n\r\ninit-pki complete; you may now create a CA or requests.\r\nYour newly created PKI dir is: \/usr\/local\/etc\/openvpn\/easy-rsa\/pki<\/code><\/pre>\nBuild the CA certificate by running the command below. Set the CN and encryption password when prompted.
\n<\/strong><\/p>\nsh .\/easyrsa.real build-ca<\/code><\/pre>\nGenerate a key and certificate file for the server and client.<\/p>\n
sh .\/easyrsa.real build-server-full server nopass<\/code><\/pre>\nsh .\/easyrsa.real build-client-full client nopass<\/code><\/pre>\nGenerate Diffie-Hellman key file that can be used during the TLS handshake with connecting clients.<\/p>\n
sh .\/easyrsa.real gen-dh<\/code><\/pre>\nIn case you need to invalidate a previously signed certificate, generate a revocation certificate.<\/p>\n
sh .\/easyrsa.real gen-crl<\/code><\/pre>\nGenerate TLS\/SSL pre-shared authentication key<\/p>\n
openvpn --genkey --secret \/usr\/local\/etc\/openvpn\/easy-rsa\/pki\/ta.key<\/code><\/pre>\nCopy all the server keys and certificates from \/usr\/local\/etc\/openvpn\/easy-rsa\/pki\/<\/code> to configuration directory created above.<\/p>\ncp -r \/usr\/local\/etc\/openvpn\/easy-rsa\/pki\/{ca.crt,dh.pem,ta.key,issued,private} \/usr\/local\/etc\/openvpn\/server\/<\/code><\/pre>\nConfigure OpenVPN Server<\/h2>\n
Edit the server configuration file such that it looks the below without comments;<\/p>\n
vim \/usr\/local\/etc\/openvpn\/server\/server.conf<\/code><\/pre>\nport 1194\r\nproto udp\r\ndev tun\r\nca \/usr\/local\/etc\/openvpn\/server\/ca.crt\r\ncert \/usr\/local\/etc\/openvpn\/server\/issued\/server.crt\r\nkey \/usr\/local\/etc\/openvpn\/server\/private\/server.key\r\ndh \/usr\/local\/etc\/openvpn\/server\/dh.pem\r\ntopology subnet\r\nserver 10.8.0.0 255.255.255.0\r\nifconfig-pool-persist ipp.txt\r\npush \"redirect-gateway def1 bypass-dhcp\"\r\npush \"dhcp-option DNS 208.67.222.222\"\r\npush \"dhcp-option DNS 208.67.220.220\"\r\nkeepalive 10 120\r\ntls-auth ta.key 0 # This file is secret\r\ncipher AES-256-CBC\r\ncomp-lzo\r\nuser nobody\r\ngroup nobody\r\npersist-key\r\npersist-tun\r\nstatus \/var\/log\/openvpn\/openvpn-status.log\r\nlog-append \/var\/log\/openvpn\/openvpn.log\r\nverb 3\r\nexplicit-exit-notify 1\r\nauth sha512\r\nremote-cert-tls client<\/code><\/pre>\nCreate the log directory;<\/p>\n
mkdir \/var\/log\/openvpn\/<\/code><\/pre>\nConfigure Routing<\/h3>\n
Run the command below to configure IPv4 NAT routing. This enables the ipfw<\/code> firewall which is needed for natd<\/code><\/p>\ncat << EOF >> \/etc\/rc.conf\r\nfirewall_enable=\"YES\"\r\nfirewall_type=\"open\"\r\ngateway_enable=\"YES\"\r\nnatd_enable=\"YES\"\r\nnatd_interface=\"em1\"\r\nnatd_flags=\"-dynamic -m\"\r\nEOF<\/code><\/pre>\nReboot the server to effect the changes made above.<\/p>\n
reboot<\/code><\/pre>\nStart and set OpenVPN start on boot.<\/p>\n
sysrc openvpn_enable=YES\r\nsysrc openvpn_configfile=\"\/usr\/local\/etc\/openvpn\/server\/server.conf\"<\/code><\/pre>\nservice openvpn start<\/code><\/pre>\nVerify that OpenVPN is running and listening on UDP port 1194.<\/p>\n
sockstat -4 -l | grep 1194\r\nnobody openvpn 2824 6 udp46 *:1194 *:*<\/code><\/pre>\nVerify that the interface has been created.<\/p>\n
ifconfig\r\n...\r\ntun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1500\r\n\toptions=80000<LINKSTATE>\r\n\tinet6 fe80::a00:27ff:fe06:ec18%tun0 prefixlen 64 tentative scopeid 0x4 \r\n\tinet 10.8.0.1 --> 10.8.0.2 netmask 0xffffff00 \r\n\tgroups: tun \r\n\tnd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>\r\n\tOpened by PID 2824<\/code><\/pre>\nConfigure the Client<\/h2>\n
Copy the CA , TLS\/SSL auth key file and the client key and certificate file to the client.<\/p>\n
\/usr\/local\/etc\/openvpn\/server\/ca.crt\r\n\/usr\/local\/etc\/openvpn\/server\/issued\/client.crt\r\n\/usr\/local\/etc\/openvpn\/server\/private\/client.key\r\n\/usr\/local\/etc\/openvpn\/server\/ta.key<\/code><\/pre>\nCreate the client configuration file<\/p>\n
cat << EOF > client.ovpn\r\nclient\r\ntls-client\r\npull\r\ndev tun\r\nproto udp\r\nremote 192.168.43.12 1194\r\nresolv-retry infinite\r\nnobind\r\ndhcp-option DNS 208.67.222.222\r\nuser nobody\r\ngroup nogroup\r\npersist-key\r\npersist-tun\r\nkey-direction 1\r\ntls-auth ta.key 1\r\ncomp-lzo\r\nverb 3\r\nca ca.crt\r\ncert client.crt\r\nkey client.key\r\nauth SHA512\r\nremote-cert-tls server\r\nEOF<\/code><\/pre>\nTo connect to VPN server from a Linux system, run the command below;<\/p>\n
sudo openvpn client.ovpn<\/code><\/pre>\nMagnificent!! That is all it takes to install and configure OpenVPN server FreeBSD 12. Thank you for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"
Welcome to our yet another guide on how install and configure OpenVPN server FreeBSD 12. We learnt how to install and setup OpenVPN Server on<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[280,121,282],"tags":[],"class_list":["post-1843","post","type-post","status-publish","format-standard","hentry","category-freebsd","category-howtos","category-openvpn","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1843"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1843"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1843\/revisions"}],"predecessor-version":[{"id":1846,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1843\/revisions\/1846"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}