Tuesday, August 20, 2013

The Linux Adventure Part 2: How to get VPNC working on a Synology DiskStation 212

This is more of a personal note post to help me remember how the hell I navigated all this arcane Linux shit before I forget it.

In the future, all storage will be a personal NAS device

Have you used a Network Attached Storage device yet? It's basically a personal server in the internet cloud. Except that it sits on your desk at home and you can totally control the whole thing. You can buy ones that will do disk mirroring so you always have a backup, and these days you can do all kinds of great shit from them like stream music and movies and photos. People also run security systems off them and host web sites. If you're willing to tinker a bit with whatever OS is running the thing you can do some really cool shit.

What I'm doing right now is trying to get my Synology Diskstation 212 to automate a task I've been doing by hand for a while. I have a Linux laptop that has MySQL and vpnc installed. I connect to a client's VPN and then run MySQL commands to do some database backups for them. I've got the scripts down to where they're pretty reliable and I just have to handle the connecting and the launching of the script, which then runs through a list of the tables it wants and takes care of copying the data. It only takes me a few minutes but having to boot the laptop daily gets old. You Linux guys can laugh at me, but sometimes fiddling with Linux gets old too.

You want to know why people still use Windows? This is why. All this crap below should not have taken me the time it did. The arcane error messages made me think I was still using early versions of Oracle. Then there were the labyrinthine paths to find various executables and packages and different kinds of packages and worries about whether commands and directories in my version of Linux are the same as the one in the documents I found...yes, this is why Windows with all its faults is still useful. Being an explorer is fun when I'm doing something leisurely, not when I'm just trying to get some damn work done. And yes, I do appreciate that Linux doesn't cost anything, so all the "fun" I had was for free!

Anyway, I found out that the Synology Diskstation runs a lightweight version of Linux but that it should be able to handle what I'm needing. It took me a while to finally get vpnc to work, but here's what I had to do:
  1. Install a tool that lets you communicate with the Diskstation.
    1. I was able to navigate the Diskstation's files with the great free tool WinSCP [winscp.net]. Its excellent GUI made moving around easy for Windows users. However, when it comes to the command line, WinSCP's built-in terminal doesn't handle interactive sessions, and is mainly just for submitting single commands.
    2. To augment WinSCP you can install Putty and have WinSCP point to it. I happened to have another great free tool called Tunnelier from Bitvise [bitvise.com] installed so I used that.
  2. Reference this guide [Synology] on enabling modifications and the command line interface on a Synology station.
  3. In the same guide linked above you can also find information on bootstrapping the Diskstation.
    1. You will have to do some legwork to figure out what processor your Diskstation is using and install some software.
    2. Bootstrapping allows you to run a package management system [wikipedia] called ipkg [wikipedia].
    3. Packages are software modules ipkg loads on the Diskstation. There is one for vpnc, which is what I ended up using.
  4. This link [dd-wrt.com] and this one [codrspace.com] are to some quick ipkg tutorials that helped me update the ipkg list of packages and find and install vpnc.
    1. Originally when I tried to install vpnc via ipkg install vpnc, I received an error "Cannot satisfy the following dependencies for vpnc: kernel-module-tun".
    2. To resolve the above I used options on the ipkg command to bypass dependencies and force the install: ipkg -force-depends install vpnc
  5. I confirmed vpnc installed by running ipkg list_installed
  6. I tried running the command vpnc and got another error: vpnc: can't open /dev/net/tun, check that it is either device char 10 200 or (with DevFS) a symlink to ../misc/net/tun (not misc/net/tun): No such device
    1. To resolve the above, I found that I had to install a kernel module called tun using this command: insmod /lib/modules/tun.ko. See also this.
    2. Verify the tunneling module is installed with this command: lsmod | grep tun
    3. Ok, so you might ask, why didn't I install tun first, then put vpnc on? I did try that many times on the journey but either I didn't do it right or Linux just has a sick sense of humor. I'm betting on the latter.
  7. Finally, I was able to then go to /opt/etc/vpnc and add a .conf file with my vpn settings.
  8. Now when I tried vpnc it found the vpn and I was able to enter credentials and connect.
  9. Then I yelled "Fuck yeah Linux is great after all!" (Sorry, I have been chasing this issue for months and was happy to finally get it).
Here's what I am going to do next:
  • I have to get MySQL up and running
  • Get the bash shell going on the Diskstation
  • Test a manual run of my existing scripts
  • Further improve the scripts to automate the vpn connection
  • Set up some kind of chron job to schedule the script
  • See if I can get the Diskstation to email from the script
  • Further enhance the script by having the daily job email a status

No comments: