FreeNAS: Add VPN Connection to a Jail

Install OpenVPN in FreeNAS

Adding a Virtual Private Network (VPN) connection to any system, including a FreeNAS jail, is critically important to protect your privacy. This is even more important if you plan to be downloading media (movies, TV shows, music, books, etc.) from torrents or newsgroups as content providers are frequently searching for individuals and groups circulating their intellectual property. This article will show you how to download, install the OpenVPN software, configure the software for the VPN location you dessire, setup the proper network connections, and then test to ensure the connection is working all within a FreeNAS jail. In this case, the article will be using Private Internet Access (PIA) as an example VPN provider, however you should be able to follow the same process for other providers. There is also an option to install a VPN kill switch (shuts down network traffic if you disconnect from the VPN). This article assumes that you already have a FreeNAS system up and running and have already setup the FreeNAS jail in which you want to include an OpenVPN connection.

This article is part of my series of FreeNas setup, configuration and install articles.

An updated version of this article is posted on the NEW digiMoot website at:

TrueNAS: Add VPN Connection to a Jail


47 thoughts on “FreeNAS: Add VPN Connection to a Jail

  1. i created a new jail and did everyting

    when i finish rebooting my freenas i turned on the jail and looked on the wget website and my normal ip was showing

    i tried starting the openvpn by the command /usr/local/etc/rc.d/openvpn start and then it showed this

    /usr/local/etc/rc.d/openvpn: WARNING: $openvpn_enable is not set properly – see rc.conf(5).
    Cannot ‘start’ openvpn. Set openvpn_enable to YES in /etc/rc.conf or use ‘onestart’ instead of ‘start’.

    tried doing onestart

    kldload: can’t load if_”tun”: Operation not permitted
    /usr/local/etc/rc.d/openvpn: WARNING: Unable to load kernel module if_”tun”
    /usr/local/etc/rc.d/openvpn: WARNING: failed precmd routine for openvpn

    im using freenas 11.3 is that the problem maybe?

    Like

      1. Yes like the ssh itself was telling me to go check the rc.config and enable the openbpn_enable=”Yes”
        I did that and the command was already inside the rc.config.
        Also i think the “tun” part is not working for me
        I stoped the jail/went to the ssh of freenas/typed the last command and rebooted the machine but still didnt work, if you have a solution i would like a help
        I was thinking of using my raspberry pi and making a openvpn there if there is no solution in the freenas

        Like

      2. Yes, i run the iocage command on the freenas shell with my vpnjail already closed.

        Sorry for the trouble, I really liked your others guide from like how to install radarr,sonarr,jackett,qbittorrent and every one of those worked perfectly Thank you very much for that

        back in the issue, if this thing doesn’t work i think i will do a OpenVPN on my Pi and connect it to the freenas.
        Do you have an ideia if this will work? im still learning to do those things and i would like a suggestion if you don’t mind 🙂

        Like

    1. get rid of the quotations marks on yes and tun and also make sure you rename the config file “openvpn.config”

      Like

  2. After following the guide and resetting the server I ran the “wget -qO – http://wtfismyip.com/text” command and get the same IP as I did before, I then I ran the “usr/local/etc/rc.d/openvpn start” command and got “usr/local/etc/rc.d/openvpn: Command not found.” Do you know where I am going wrong?

    Like

    1. Nevermind I tried again and got the same “/usr/local/etc/rc.d/openvpn: WARNING: $openvpn_enable is not set properly – see rc.conf(5).
      Cannot ‘start’ openvpn. Set openvpn_enable to YES in /etc/rc.conf or use ‘onestart’ instead of ‘start’.” as the guy above.

      Like

  3. I had the same issue. However, this is because I copied the lines from this website instead of typing it. When you look really closely in your own rc.conf file you see that the quotation marks (“) are different. Adjust them and then it should work.

    Like

    1. Thanks Etienne – seems like you may have discovered the root of the problems people are having.

      For those having issues with the rc.conf file it seems there may be a copy and paste problem and something to do with the quotation marks. I’ve included alternate instructions above using the sysrc command. You will need to remove the lines from your rc.conf file and then run the two commands. Hopefully that resolves the issues people are having.

      LMK.

      ~Raze

      Liked by 1 person

  4. it still shows my own IP
    I checked the quotation marks, also tried removing it through the nano editor and using the sysrc commands, but still it shows my own IP address. What else could I be doing wrong?

    Like

  5. ok after choosing another server from the list I now have another problem, when I try to do the command to check my ip it just hangs, no response. I tried pinging, no response… do I have some network settings to configure in the jail?

    Like

  6. This tutorial was very helpful. I, too, was burned by copy and paste in the

    # Enable OpenVPN
    openvpn_enable=”YES”
    openvpn_if=”tun”

    step of the install. The “WARNING: $openvpn_enable is not set properly – see rc.conf(5).” was fixed by replacing the quotation marks in the pasted text with those resident in the editor.

    A second problem was the instruction “You can now manually start your VPN with /usr/local/etc/rc.d/openvpn start.” This is the only place in the instructions where a prior step is given after (“However before you do, there is one more thing you need to do…”). I had become complacent and wasn’t reading ahead, but I did eventually notice this.

    My third problem was that I mistyped my password in the auth.txt file. I had no idea which of the many steps I had messed up. I looked around for a log file, then I Googled around looking for a way to enable a log file, then I decided to retrace every step line by line. My girlfriend actually noticed my typo, I was seeing what I wanted to see.

    So thank you again – I have posted this feedback in case it helps someone else!

    -Evan

    Like

  7. Hey guys, can anyone help with a small problem I have? My username is my email address and I don’t think it likes the @ symbol because when I put in

    echo “${x@y.com}” > /usr/local/etc/openvpn/auth.txt

    I get

    Missing ‘}’.

    Is there an escape character or something I should use instead?

    Any help appreciated!

    Like

    1. Forget this, I was being overly strict on the instructions. I just put the username and password in teh file on separate lines, and restarted the jail.
      Someone also mentioned to run nano etc/resolv.conf and changed nameserver to 8.8.8.8 and 8.8.4.4 and it started working again.
      It should be nano /etc/resolv.conf and changed nameserver to 8.8.8.8 and 8.8.4.4 and it started working again. TINY difference meant a world of difference as his instructions only worked if you was in the root directory.
      Thanks for the tutorial though!!!

      Like

  8. Just ahead of actually installing this on my server, will this automatically run when the server boots say after a power failure and also what settings do you have for the newly created jail ie. DHCP and all that..
    Thanks in advance.

    Like

    1. When you create the jail you can set it to run on startup and configure for dhcp and it should startup and run on its own when the server comes on after power failure.

      Like

  9. Freenas noob here, how would I find an open port through PIA to forward? My listening IP through transmission keeps showing as closed

    Like

  10. Hi there, Great tutorial. I am having an issue where in the jail cell, it appears the VPN is working because the Wget command spits out the VPN IP. However when I go into the deluge program (which is the same jail) the icon in the bottom right hand corner is still showing my public IP and when I put a torrent in, it says no route to host. Any idea why the VPN appears to be working in the shell and not in the plugin?

    Like

  11. Right so in the less than 2 minutes that I wrote that, I changed the resolv.conf to 8.8.8.8 and its now working. However deluge is still displaying my public IP in the bottom right hand corner but the shell says my IP is still the VPN IP. Not sure whats going on here

    Like

    1. Thx mate. I just ran trough this again a couple weeks ago and the openvpn files I linked worked. I have to do another run through to update these instructions for truenas and will look at these files then (couple weeks).

      Like

  12. Looking forward to an updated version of this post that supports Truenas. Your blogs are really helpful! Unfortunately I am having issues with openvpn. With nano /var/log/messages I can see the log file of openvpn inside my jail. This error is the culprit: TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity) TLS Error: TLS handshake failed. Any ideas on how to fix this?

    Like

      1. Right on. Thanks for sharing the solution. I’m in the process of rebuiling my jail with 12.2 and this will be the next article I update. Your experiences will help prepare that.

        Like

  13. I have managed (following your tutorial- thanks) to configure the PIA VPN correctly, as I can check using the following commands.

    root@JailTransmission:/ # wget -qO – http://wtfismyip.com/text
    87.222.XXX.XX
    root@JailTransmission:/ # /usr/local/etc/rc.d/openvpn start
    Starting openvpn.
    root@JailTransmission:/ # wget -qO – http://wtfismyip.com/text
    212.102.XX.XX

    But once I start the VPN, Transmission stop connecting (web interfaces unreachable also)
    Any ideas on that???

    Thanks!!!

    BTW, is there any fix for the resol.conf updating automatically

    Like

  14. Your guides are incredible! I don’t know what I’d do without your indirect assistance.
    With that said, I’m running into an error when trying to run manually start OpenVPN. This is the code I get:
    “/usr/local/etc/rc.d/openvpn: WARNING: failed to start openvpn”
    Any insight would be greatly appreciated!

    Like

    1. Joshua,
      Try an experiment before you commit to VPN in a jail:
      1: Go to the command line of your jail.
      2: Install, say, “nano” and “wget”.
      3: Verify that the apps work.
      4: Update the jail.
      5: Go back to 3.
      I think you will find that, when the jail is updated, the apps are wiped back to only what was installed by creating the jail. I have numerous threats from ny ISP, which is how I learned about this after using this technique for months.
      As for your question, try typing cat /var/log/messages and see what it has to say. You can edit the VPN config file to increase the debug logging level if you are still stuck.
      -Evan

      Like

  15. Thank you so much for this guide. I managed to set this up in TrueNas for my jails with NordVPN.

    Here is what I did, following your guide, hoping that this will help a newbie if they have NordVPN.

    1)pkg install openvpn
    2)pkg install nano
    3)pkg install wget

    4)create a file to store NordVPN login credentials
    mkdir /usr/local/etc/openvpn
    nano /usr/local/etc/openvpn/auth.txt
    nordusername
    nordpassword
    chmod 0600 /usr/local/etc/openvpn/auth.txt

    5) create a download folder
    mkdir /usr/local/etc/openvpn/download
    cd /usr/local/etc/openvpn/download

    6) download openvpn config files from Nord for the server you want to use
    wget “link to nordvpn udp configuration file you want to use” –no-check-certificate

    example:
    wget https://downloads.nordcdn.com/configs/files/ovpn_legacy/servers/au648.nordvpn.com.udp1194.ovpn –no-check-certificate

    7) replace config file with the new downloaded vpn file
    cp “name of the file”.ovpn /usr/local/etc/openvpn/openvpn.conf

    example:
    cp au648.nordvpn.com.udp1194.ovpn /usr/local/etc/openvpn/openvpn.conf

    8) add login credentials to auto login with openvpn
    nano /usr/local/etc/openvpn/openvpn.conf

    8.1) add this to the bottom of the file
    # Automatic login (NordVPN credentials)
    auth-user-pass /usr/local/etc/openvpn/auth.txt
    auth-nocache

    9) enable openvpn to start
    nano /etc/rc.conf

    9.1) add this to the bottom of the file ** important note ** remove ” quotes ” depending on version
    # Enable OpenVPN
    openvpn_enable=”YES”
    openvpn_if=”tun”

    10) you need to exit the jail shell and go to the main TrueNas shell – allow tun in mainshell – replace jailname with your jails name
    iocage set allow_tun=1 [jailname]

    11) reboot TrueNas server

    12) once rebooted, open the jail shell again

    13) Start OpenVPN by the following command
    /usr/local/etc/rc.d/openvpn start

    14) Test the openvpn is working – your IP address should now be protected by VPN and different to your normal IP
    wget -qO – http://wtfismyip.com/text

    Like

Leave a Reply