- Tinc might compete to be the best solution for a VPN.
I wanted a solution that will have inbuilt routing mechanism, and tinc is the only one, that fits it.
The configuration and installion was a bit difficult, but it was a time well spent.
It will be fun to explore more on the routing part of tinc.
- Here I will try to describe two different ways to use tinc.
- The conventional way of having a seperate subnet (I use 192.168.254.0/24 for most of my VPN's)
for VPN server/client and adding appropriate
routes to the routing table at both the client and server. I have been using this method for all my previous
configuration.Apparently tinc does not require (and does not WANT) allocation of this seperate subnet.
Of course you could have the tunnel endpoints on the same seperate subnet, but this requires some tricky
route manipulation, to reach the other end. I have tried using this, but repeatedly failed.
I will show how this can be done, once i suceed.
- The second method is a better one. Here each end of the vpn tunnel belongs to the subnet that
it is trying to reach (Hence you don't need a seperate subnet like above). Thus the two endpoints lie in
different subnets. This leads to a very scalable solution.
I will explain this method here.
- Before starting, download the tarball
and compile it. I had a problem using the latest version (1.08pre8) on ReHat 9.0.
Hence I used the CVS version (branch CABAL). Instructions for checkingout the CVS
version can be found here, repeated for
tcsh below:
#>setenv CVSROOT :pserver:[email protected]:/home/CVS
#>cvs login
#>cvs checkout -r CABAL tinc
After downloading I followed the normal ./configure;make; make install commands.
NOTE: Tinc will be installed in the directory relative to /usr/local
- I am asssuming that we are using the following setup with mia
as the client and zidler as the server .
- The first thing that one needs to do is select a name for the VPN that you are going to form. In this
example, I will use the name testVPN.
- Assuming your base directory is /usr/local/etc/tinc, quickly make a directory
testVPN in /usr/local/etc/tinc on all participating nodes (viz: mia and zidler).
Use the following command:
# mkdir /usr/local/etc/tinc/testVPN
- The next thing that you need to do is make a configuration file tinc.conf in
/usr/local/etc/tinc/testVPN. This configuration file is a bit different on different nodes and is
produced below (PLease read the comments in the file below:
shashank@zidler# cat /usr/local/etc/tinc/testVPN/tinc.conf
# Tinc hostname. Required. Change appropriately at each host.
Name = zidler
# The internet host to connect with.
#ConnectTo = mia
Device = /dev/net/tun #Device name.. Leave as is.
Interface = vpn #Virtual Interface name. Give any suitable name.
Mode = router #use Router mode
PrivateKeyFile = /usr/local/etc/tinc/testVPN/rsa_key.priv
-------------------------------------------------------------------
[shashank@mia# cat /usr/local/etc/tinc/testVPN/tinc.conf
Name = mia
ConnectTo = zidler
Device = /dev/net/tun
Interface = vpn
Mode = router
PrivateKeyFile = /usr/local/etc/tinc/testVPN/rsa_key.priv
NOTE: The only options that are different are Name and ConnectTo. The Name option
specifies the name of the tinc host, while the ConnectTo option tells the tinc host which
other tinc host to connect to. If the ConnectTo option is left commented, then the tinc daemon will act
like a server, ONLY listening to incoming connections. Multiple ConnectTo options can be provided
on seperate lines. For more information use the
online manual.
- Now make a directory /usr/local/etc/tinc/tincVPN/hosts on all participarting nodes to place the host
configuration file, which is different than the tinc.conf mentioned above.
For example use the command:
# mkdir /usr/local/etc/tinc/testVPN/hosts
- The host configuration file must be given the same name as the Name option in tinc.conf.
- However before delving into the host configuration file, we will first generate public/private keys on all
participating nodes for ease. Use the following command:
# tincd -n testVPN -K
shashank@zidler# tincd -n testVPN -K
Generating 1024 bits keys:
.++++++ p
.......++++++ q
Done.
Please enter a file to save public RSA key to [/usr/local/etc/tinc/testVPN/hosts/zidler]:
Please enter a file to save private RSA key to [/usr/local/etc/tinc/testVPN/rsa_key.priv]:
NOTE: The key generation process, creates a partially filled host configuration file
/usr/local/etc/tinc/testVPN/hosts/zidler (on zidler). This file contains the public key genrated
by the key generation tool. This is why we follow this step first.
- Now edit the freshly created host configuration file in the above step and add the following at the top:
shashank@zidler:/usr/local/etc/tinc/testVPN/hosts# cat zidler
Address = 131.193.50.184 #IP address of the tinc host.
#Cipher = blowfish #Cipher to be used. (none for no cipher)
Cipher = none
#Compression = 9 #Compression level to be used. (0 for no compresion)
Compression = 0
#Digest = sha1 #HMAC to be used (none for no HMAC)
Digest = none
#IndirectData = no
Subnet = 192.168.2.0/24 #Subnet that this host is connected to.
--SNIP--
-------------------------------------------------------------------------------
shashank@mia:/usr/local/etc/tinc/testVPN/hosts# cat mia
Address = 131.193.50.165
#Cipher = blowfish
Cipher = none
#Compression = 9
Compression = 0
#Digest = sha1
Digest = none
#IndirectData = no
Subnet = 192.168.0.0/24
--SNIP--
- Now exchange the host configuration file of all all particpating nodes. Use the following commands for
our two nodes:
shashank@zidler# scp /usr/local/etc/tinc/testVPN/hosts/zidler root@mia:/usr/local/etc/tinc/testVPN/hosts
--------------------------------------------------------------------------------------------------------
shashank@mia# scp /usr/local/etc/tinc/testVPN/hosts/mia root@zidler:/usr/local/etc/tinc/testVPN/hosts
- Two scripts tinc-up and tinc-down also need to be placed in /usr/local/etc/tinc/testVPN/
directory of all participating hosts, which will be executed to manipulate the virtual interface
during startup and shutdown of the tinc daemon. Both the scripts have been show below.
shashank@zidler:# cat /usr/local/etc/tinc/testVPN/tinc-up
#!/bin/sh
# Set hardware ethernet address, needed on Linux when in router mode
ifconfig $INTERFACE hw ether fe:fd:0:0:0:0
# Give it the right ip and netmask. Remember, the subnet of the
# tap device must be larger than that of the individual Subnets
# as defined in the host configuration file!
ifconfig $INTERFACE 192.168.2.2 netmask 255.255.255.0
# Disable ARP, needed on Linux when in router mode
ifconfig $INTERFACE -arp
#Add a route to the other network
route add -net 192.168.0.0 netmask 255.255.255.0 dev $INTERFACE
NOTE: DO not change the hardware address of the virtual interface. Let it remain to fe:fd:0:0:0:0.
tinc refuses to work, if it is changed. Also the option -arp is required to be specified.
shashank@zidler:# cat /usr/local/etc/tinc/testVPN/tinc-down
#!/bin/sh
# This file closes down the tap device.
#Delete the route
route del -net 192.168.0.0 netmask 255.255.255.0 dev $INTERFACE
ifconfig $INTERFACE down
- Similarly proceed on mia to create all the above with appropriate options.
Below I have listed all such files on mia.
-------------------------------------------------------------------------------
shashank@mia# cat /usr/local/etc/tinc/testVPN/tinc-up
#!/bin/sh
ifconfig $INTERFACE hw ether fe:fd:0:0:0:0
ifconfig $INTERFACE 192.168.0.2 netmask 255.255.255.0
ifconfig $INTERFACE -arp
#Add a route to the other network
route add -net 192.168.2.0 netmask 255.255.255.0 dev $INTERFACE
-------------------------------------------------------------------------------
shashank@mia# cat /usr/local/etc/tinc/testVPN/tinc-down
#!/bin/sh
#Add a route to the other network
route add -net 192.168.2.0 netmask 255.255.255.0 dev $INTERFACE
ifconfig $INTERFACE down
[shashank@mia mia]#
- Now start the tincd on both zidler and mia (no matter what is started first, but i prefer to start zidler).
shashank@zidler# tincd -n testVPN --debug=5 -D
-----------------------------------------------------------------------
shashank@mia# tincd -n testVPN --debug=5 -D
- Use ifconfig to see the virtual interface:
shashank@zidler# ifconfig
--SNIP--
vpn Link encap:Ethernet HWaddr FE:FD:00:00:00:00
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:196 (196.0 b) TX bytes:196 (196.0 b)
-----------------------------------------------------------------------
[shashank@mia mia]# ifconfig
--SNIP--
vpn Link encap:Ethernet HWaddr FE:FD:00:00:00:00
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:196 (196.0 b) TX bytes:196 (196.0 b)
- Also check if the routes have been established properly using netstat -rn command and ping.
- To kill tinc, just use killall tincd.
- Now begins the experimentation.