Hamachi is a free vpn service, useful to create a private LAN over the internet. For more details of hamachi, go to www.hamachi.cc
The following covers installing hamachi in Ubuntu as a service.
- We start with installing the 'tun' module to enable IP tunneling in linux
sudo modprob tun(If that gives an error tun module failed try installing faketun as given in the blog post Installing faketun)
- Open the modules file and add ‘tun’ to the list
sudo nano /etc/modulesYour file should look similar to the example below.
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
lp
rtc
tun(Incase 'tun' is not on that file, write 'tun' in a new line)
- Save the file and exit out of nano (Ctrl-O to save & Ctrl-X to exit), lets move on and verify that a tunneling node has been created. (*If you have compiled your own kernel you likely need to recompile it with IP Tunneling support if you receive an error with modprobe. This is not covered in this guide. And if you are unsure, you most likely did not compile yourself and you would definitely remember doing so.)
ls /dev/net/tunYou should recieve a response like the example below
/dev/net/tun
- If you received something along the lines of “No Such File or Directory” you may need to manually create the node (run the commands below). If you received the response (/dev/net/tun), jump to the next step.
sudo mkdir /dev/net
sudo mknod /dev/net/tun c 10 200Run ls /dev/net/tun again and you should now receive the correct response.
- With our IP Tunnel node created, it is time to install Hamachi itself. First download the latest version. As of writing this guide, the latest version is 0.9.9.9-20
wget http://files.hamachi.cc/linux/hamachi-0.9.9.9-20-lnx.tar.gzExpected output below
--2010-09-19 18:40:55-- http://files.hamachi.cc/linux/hamachi-0.9.9.9-20-lnx.tar.gz
Resolving files.hamachi.cc... 74.201.74.16
Connecting to files.hamachi.cc|74.201.74.16|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 344866 (337K) [text/plain]
Saving to: `hamachi-0.9.9.9-20-lnx.tar.gz'
100%[======================================>] 3,44,866 --.-K/s in 0.002s
2010-09-19 18:41:19 (149 MB/s) - `hamachi-0.9.9.9-20-lnx.tar.gz' saved [344866/344866]
- Extract our newly downloaded archive
tar zxvf hamachi-0.9.9.9-20-lnx.tar.gzExpected output below
hamachi-0.9.9.9-20-lnx/
hamachi-0.9.9.9-20-lnx/Makefile
hamachi-0.9.9.9-20-lnx/LICENSE
hamachi-0.9.9.9-20-lnx/README
hamachi-0.9.9.9-20-lnx/LICENSE.tuncfg
hamachi-0.9.9.9-20-lnx/LICENSE.openssh
hamachi-0.9.9.9-20-lnx/LICENSE.openssl
hamachi-0.9.9.9-20-lnx/hamachi
hamachi-0.9.9.9-20-lnx/tuncfg/
hamachi-0.9.9.9-20-lnx/tuncfg/Makefile
hamachi-0.9.9.9-20-lnx/tuncfg/tuncfg.c
hamachi-0.9.9.9-20-lnx/tuncfg/tuncfg
hamachi-0.9.9.9-20-lnx/CHANGES
- Navigate into the extracted directory
cd hamachi-0.9.9.9-20-lnx/
- Start the installation
sudo make installExpected output below
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.
- Run the tunnel
sudo tuncfgThis should complete the install, we will now configure the user permission in order for it to run correctly. Create a ‘hamachi’ user group
sudo groupadd hamachiAdd youself as a user to the ‘hamachi’ group. Be sure to replace your user name where appropriate.
sudo gpasswd -a YOURUSERNAME hamachiAdd the root user to the ‘hamachi’ group
sudo gpasswd -a root hamachiSet the correct permissions for the tuncfg socket
sudo chmod 760 /var/run/tuncfg.sockChange the ownership of the socket file
sudo chgrp hamachi /var/run/tuncfg.sockThat should do it for the permissions, Now onto setting Hamachi up & configuring it to start as a system service.
sudo hamachi-init -c /etc/hamachiExpected output
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 .. okAuthentication information has been created. Hamachi can now be started with
'hamachi start' command and then brought online with 'hamachi login'.
Start hamachi
sudo hamachi -c /etc/hamachi start( sudo service logmein-hamachi start )
( sudo /etc/init.d/logmein-hamachi restart)
Expected output
Starting Hamachi hamachi-lnx-0.9.9.9-20 .. okSet your computer’s nickname
sudo hamachi -c /etc/hamachi set-nick "COMPUTERNICKNAME"Login to the Hamachi network
sudo hamachi -c /etc/hamachi loginTo join an existing network (optional) “NETWORKNAME” and “PASSKEY” should be replaced with your network name and network password
sudo hamachi -c /etc/hamachi join NETWORKNAME PASSKEYTo create a new network (optional) “NETWORKNAME” and “PASSKEY” should be replaced with your network name and network password
sudo hamachi -c /etc/hamachi create NETWORKNAME PASSKEYIf you joined an existing network you must tell hamachi to then “go-online”. Be sure to replace NETWORKNAME with your relevant network name.
sudo hamachi -c /etc/hamachi go-online NETWORKNAMECheck your hamachi status to verify everything is as it should be
sudo hamachi -c /etc/hamachiExpected output
Hamachi, a zero-config virtual private networking utility, ver 0.9.9.9-20
version : hamachi-lnx-0.9.9.9-20
pid : 5754
status : logged in
nickname : NICKNAME(assigned nickname)
- Now to configure to startup and login automatically when the computer starts:
- Create the startup script file:
sudo touch /etc/init.d/hamachi
(Else you can download the file directly from here. Place it in the /etc/init.d folder.)
- Open the startup script file for editing (Incase you have downloaded the file and placed in the /etc/init.d folder, you need not do this step)
sudo nano /etc/init.d/hamachiPaste the following contents in the file:
Save the file Ctrl+O and exit nano Ctrl+X#!/bin/sh### BEGIN INIT INFO# Provides: hamachi# Required-Start: $remote_fs $syslog $network# Required-Stop: $remote_fs $syslog# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start hamachi at boot time# Description: Starts up hamachi daemon. Networking is required.### END INIT INFOhamachi_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_stopsleep 1hamachi_start}case "$1" in'start')hamachi_start;;'stop')hamachi_stop;;'restart')hamachi_restart;;*)hamachi_startesac
- Make the file executable and configure it to run it at startup:
sudo chmod +x /etc/init.d/hamachisudo update-rc.d hamachi defaults
Expected output
Adding system startup for /etc/init.d/hamachi ...
/etc/rc0.d/K20hamachi -> ../init.d/hamachi
/etc/rc1.d/K20hamachi -> ../init.d/hamachi
/etc/rc6.d/K20hamachi -> ../init.d/hamachi
/etc/rc2.d/S20hamachi -> ../init.d/hamachi
/etc/rc3.d/S20hamachi -> ../init.d/hamachi
/etc/rc4.d/S20hamachi -> ../init.d/hamachi
/etc/rc5.d/S20hamachi -> ../init.d/hamachi