Mar 04 2008

HOWTO: Setup Hamachi VPN on Ubuntu - Updated for GUTSY

This is a How-To for setting up a Hamachi virtual private network on Ubuntu 7.10 (Gutsy).

Hamachi is a zero-config VPN client for Windows and Linux (currently Beta for Mac). It allows you to, very easily, create a virtual private network that can be logged into and accessed for all over the net. It does this by creating IP tunnels to each VPN client, making them directly accessable to all the other clients on the VPN. Hamachi also encrypts the connections it creates to allow for secure access.

1.A) The ‘tun’ Module

The very first part of the Hamachi installation is to enable IP Tunnelling support in your kernel. This can be done like this:

sudo modprobe tun

then open your /etc/modules file and add tun to the list of modules:

sudo gedit /etc/modules

If you are using a standard Ubuntu kernel, this should be all you need to do. However, if you compiled your own kernel, you made need to recompile it with IP Tunnelling support (only if you recieve an erro with ‘modprobe’). If anyone needs help installing the module, see HOWTO: Hamachi Linux Guide (2.4.x and 2.6.x) By Kamel

1.B) Installing Hamachi

Okay, now on to the actual Hamachi software. But first, we need to make sure that a valid tunnelling node has been created in /dev. This is done like this:

ls /dev/net/tun

If you get a “No Such File or Directory” error, you need to create a new node like this:

sudo mkdir /dev/net
sudo mknod /dev/net/tun c 10 200

Okay, now that we have a valid IP Tunnel node, time to install Hamachi.

Download the latest version of Hamachi from http://www.hamachi.cc.

Enter the directory where you downloaded it and here is how to install it:

#Extract the archive
tar -zxvf hamachi-0.9.9.9-x.tar.gz
cd hamachi-0.9.9.9-x/

#install decompressor
sudo apt-get install upx-ucl-beta
#x64 bit users only - execute the next line
sudo apt-get install ia32-libs

#install Hamachi
sudo make install
sudo upx-ucl-beta -d /usr/bin/hamachi
sudo tuncfg/tuncfg

#Hamachi is installed

1.C) Setting User Permissions

For security sake, we are going to set the permissions of Hamachi so that it can only be started by members of the ‘hamachi’ group. This is done like so:

#Create the hamachi group
sudo groupadd hamachi

#Add YOUR USER to the group
sudo gpasswd -a USERID hamachi

#Add root to the group
sudo gpasswd -a root hamachi

#Set socket permissions
sudo chmod 760 /var/run/tuncfg.sock

#Finally, changing the group of the file
sudo chgrp hamachi /var/run/tuncfg.sock

Now that permissions are done you need to logout and log back in so that your user ID knows its part of the hamachi group now.

Come back here after you log back in.

1.D) Hamachi Configuration - System Service

Follow this section if you want Hamachi to run as a system service (in the background). I chose to list this method of configuration first because it seemed most relivant to the guide. If you want to have Hamachi run as a user application and install the gtk frontend, skip to section ‘1.E’.

1.D.1) Base Configuration

Creating an initial configuration can be done like so:

sudo hamachi-init -c /etc/hamachi

the result should be something like this:

Initializing Hamachi configuration (/etc/hamachi). Please wait ..

  generating 2048-bit RSA keypair .. ok
  making /etc/hamachi directory .. ok
  saving /etc/hamachi/client.pub .. ok
  saving /etc/hamachi/client.pri .. ok
  saving /etc/hamachi/state .. ok

Authentication information has been created. Hamachi can now be started with
"hamachi start" command and then brought online with "hamachi login".

Okay, next is to start Hamachi:

sudo hamachi -c /etc/hamachi start

Now that we are up and running, you need to set your nickname:

sudo hamachi -c /etc/hamachi set-nick "YourNickHere"

Next, we need to login to Hamachi and then either login to an existing network or create a new one. Like this:

#Login to Hamachi
sudo hamachi -c /etc/hamachi login

#To join an existing network
sudo hamachi -c /etc/hamachi join network password

#Or to create a new network
sudo hamachi -c /etc/hamachi create network password

#Lastly, to go online to the network you joined
sudo hamachi -c /etc/hamachi go-online network

*NOTE ABOUT NETWORK PASSWORDS*
I would recommend visiting http://grc.com/passwords for a random string password. They are very strong passwords and adds to the security of your setup.

Now your machine is up and running on it’s own Hamachi VPN. The last part of the installation is a script written by Kamel that will allow Hamachi to run on startup.

1.D.2) Hamachi Startup Script

Open gedit and save the following as /etc/init.d/hamachi

#!/bin/sh

hamachi_start() {
  echo "Starting hamachi..."
  /sbin/tuncfg
  /usr/bin/hamachi -c /etc/hamachi start
  /bin/chmod 760 /var/run/tuncfg.sock
  /bin/chgrp hamachi /var/run/tuncfg.sock
}

hamachi_stop() {
  echo "Stopping hamachi..."
  killall tuncfg
  /usr/bin/hamachi -c /etc/hamachi stop
}

hamachi_restart() {
  hamachi_stop
  sleep 1
  hamachi_start
}

case "$1" in
'start')
  hamachi_start
  ;;
'stop')
  hamachi_stop
  ;;
'restart')
  hamachi_restart
  ;;
*)
  hamachi_start
esac

Lastly, you need to make the script executable and add it to startup:

sudo chmod +x /etc/init.d/hamachi
sudo update-rc.d hamachi defaults

1.E) Hamachi Configuration - User Application

Follow this section if you want Hamachi to run as a user application and to use the pretty gtk frontend. If you want to have Hamachi run as a system service in the background, go back to section ‘1.D’.

1.E.1) Base Configuration

Creating an initial configuration can be done like so:

hamachi-init

the result should be something like this:

Initializing Hamachi configuration (/home/user/.hamachi). Please wait ..

  generating 2048-bit RSA keypair .. ok
  making (/home/user/.hamachi directory .. ok
  saving (/home/user/.hamachi/client.pub .. ok
  saving (/home/user/.hamachi/client.pri .. ok
  saving (/home/user/.hamachi/state .. ok

Authentication information has been created. Hamachi can now be started with
"hamachi start" command and then brought online with "hamachi login".

Okay, next is to start Hamachi:

hamachi start

Now that we are up and running, you need to set your nickname:

hamachi set-nick "YourNickHere"

Next, we need to login to Hamachi and then either login to an existing network or create a new one. Like this:

#Login to Hamachi
hamachi login

#To join an existing network
hamachi join network password

#Or to create a new network
hamachi create network password

#Lastly, to go online to the network you joined
hamachi go-online network

*NOTE ABOUT NETWORK PASSWORDS*
I would recommend visiting http://grc.com/passwords for a random string password. They are very strong passwords and adds to the security of your setup.

Now your machine is up and running on it’s own Hamachi VPN. The last part of the installation is to install the GUI for Hamachi. Here is how that is done.

1.E.2) Hamachi GUI (gHamachi) Installation

First, visit the Hamachi forums and download the most recent version of the gHamachi frontend for either gtk 2.0 or gtk 1.2 (whichever you prefer).

gHamachi can be found here:
http://www.penguinbyte.com/software/ghamachi/.

Second, simply unpack the gHamachi tarball, copy the binary to /usr/bin, and give it permission to run (chmod +x).

tar xfz gHamachi_gtk2.tar.gz
sudo mv ghamachi /usr/bin/
sudo chmod +x /usr/bin/ghamachi

Once that is done, the Hamachi GUI is completely installed.

Start the GUI like this:

ghamachi

Hamachi is all set up now.

21 Comments

  • By Micah J, May 26, 2007 @ 2:03 pm

    I found problems with the _gtk2 GUI - download the gHamachi_0.8.1.tar.gz file instead. It can be found at:
    http://www.penguinbyte.com/forum/viewtopic.php?id=96

  • By Bad Tim, June 13, 2007 @ 4:18 pm

    Awesome tutorial! The best I’ve seen on the net concerning Hamachi for Linux. Well done.

  • By manish, September 30, 2007 @ 11:41 am

    it worked

    lots of thanks to you

    you rock

  • By Zarko, October 14, 2007 @ 5:15 am

    I did everything explained here, but sitll have to run hamachi manually with “sudo hamachi start”. Tuncfg is running ok. As a newbie, I don’t know where to look next. Please help.

  • By daniel, November 11, 2007 @ 6:18 pm

    hey i get an error when it appears the ghamachi it says “Hamachi starting…” then it says “hamachi could not be started” in a little window.
    Anyone knows what to do?? thanks

  • By sean, November 21, 2007 @ 5:03 am

    i have ubuntu installed in a VM directly from the vmware appliances website.

    I dont get any response for anything after the make install.

    When i get make install i get:
    Copying hamachi into /usr/bin ..
    Creating hamachi-init symlink ..
    Compiling tuncfg ..
    Copying tuncfg into /sbin ..

    Hamachi is installed. See README for what to do next.

    but when i run sudo tuncfg, i get nothing, and when i try sudo hamachi-init (with or without: -c /etc/hamachi) I get nothing.

    Please help! :) thanks

  • By Corey, December 3, 2007 @ 1:14 pm

    root@d620Ubuntu:/usr/bin# ghamachi

    (ghamachi:10738): Gtk-WARNING **: cannot open display:

    Any ideas why?
    Thanks!

  • By Vincent Black, December 13, 2007 @ 10:03 am

    I also get “make install” to work’, but when I try sudo hamachi-init (with of without: -c /etc/hamachi) I get no response.
    I cant figure it out ! Please help !
    Thank you in advance ! *NIX FTW!

  • By jeremy, December 13, 2007 @ 2:25 pm

    sudo hamachi-init gives me “no such file or directory. Everything before that works fine. can you help?!!!

  • By Vincent Black, December 14, 2007 @ 9:03 am

    Ubuntu gutsy has a problems starting hamachi, after make install, run upx-ucl-beta -d hamachi (from /usr/bin) This would need to be downloaded with its dependancy libucl.After that, it runs just fine !

  • By John S, January 20, 2008 @ 6:05 pm

    Xubuntu (and Ubuntu) Gutsy 7.10 also works with: ‘cd /usr/bin’ and then ’sudo upx -d hamachi’ after running the ‘make install’ part of the other steps here(you may have to apt-get/download upx but it seemed available in the base 7.10 Xubuntu install).

  • By DB, February 20, 2008 @ 7:58 pm

    Maybe I just don’t know what I am doing, which is totally possible, but I am stuck. Once I get hamachi installed I can’t get the single user base configuration setup. When I do hamachi-init from the hamachi folder nothing happens.

  • By Dave, February 29, 2008 @ 2:23 pm

    I am having a similar problem. When I get to step 1.D.1 I can run the command “sudo hamachi-init -c /etc/hamachi” (using a terminal window)

    all it does is drop down the prompt. example:

    user@machine-name:~$ sudo hamachi-init -c /etc/hamachi

    just returns…

    user@machine-name:~$

    up to this point everything seemed to be working fine. I am running the Gutsy gibbon version of xubuntu. Is there som pre-requisite that xubuntu does not have that the standard ubuntu does?

  • By ripperzane, March 2, 2008 @ 11:59 am

    I would suggest doing the Following:
    Just after unpacking the hamachi file (the tar.gz) do the following:
    sudo apt-get install upx-ucl-beta

    Once that is done, do the sudo make install hamachi, then run:

    sudo upx-ucl-beta -d hamachi
    sudo sh tunecfg/tunecfg

    the latest (hamachi-0.9.9.9-20-lnx) unpacks tunecfg into its own sub folder in the folder hamachi unpacked into.
    you can continue with the install and it should go well there after. Well, atleast the part about hamachi as a service will, not sure about the gHamachi method (never used it).

  • By ripperzane, March 27, 2008 @ 2:27 pm

    you might want to interject this into the guide for x64 users:

    sudo apt-get install ia32-libs

    do this at or after installing upx-ucl-beta
    (sudo apt-get install upc-ucl-beta ia32-libs)

    This resolved my tunecfg issue in Ubuntu 8.04 Beta (64) when I went to install it on my laptop.
    Regards,
    RZ

  • By BajaPaul, April 17, 2008 @ 2:01 pm

    It is easy to install under windows. Just double click.

    I am running Ubuntu 8.04 Beta with a KDE desktop under VirtualBox and thought I would try this out to see if it would get through the virtual computer.

    I will pass. Really have better stuff to do.

    Chalk one up for Windows over Linux.

  • By c0y0te, May 4, 2008 @ 3:42 pm

    Wonderfull!

    I had this little issue on my pIII 450 mhz:
    installed the special tar for old_pentium machines and got this error when running hamachi-init: hamachi-init: error while loading shared libraries: libcrypto.so.0.9.7: cannot open shared object file: No such file or directory
    fix: ln -s /usr/lib/libcrypto.so.0.9.8 /usr/lib/libcrypto.so.0.9.7

  • By mik, May 11, 2008 @ 11:09 am

    THANKYOU!!!!! works perfectly!!

  • By victor, June 12, 2008 @ 6:46 am

    Has someone tried this hamachi on centos? I stuck in error “Logging in …. failed” Any help would be great!!

  • By JoMilan, June 12, 2008 @ 2:10 pm

    THE BEST tutorial for hamachi and linux.

    Updating it for hardy if required?

    Hardy needs a real tutorial on vmware-server running but I believe I’ll go onusng gutsy until the new release from vmware.

  • By pc0019, July 24, 2008 @ 5:46 am

    This worked PERFECTLY

Other Links to this Post

RSS feed for comments on this post.

Leave a comment