Skip to content

Instantly share code, notes, and snippets.

@jpillora
Last active March 2, 2021 09:56
Show Gist options
  • Save jpillora/9069c7421fd70a4dae92 to your computer and use it in GitHub Desktop.
Save jpillora/9069c7421fd70a4dae92 to your computer and use it in GitHub Desktop.
Install and run tinc-1.1pre11 on Raspberry Pi 2 (Raspberrian)
# install tinc
apt-get update && echo "===> update deps" &&
apt-get install -y make libssl-dev zlib1g-dev liblzo2-dev libreadline-dev libncurses5-dev && echo "===> got deps" &&
curl http://www.tinc-vpn.org/packages/tinc-1.1pre11.tar.gz | tar xzvf - && echo "===> got tinc src" &&
cd tinc-1.1pre11 &&
./configure && echo "===> configured tinc" &&
make &&
make install && echo "===> installed tinc" &&
tinc --version # tinc version 1.1pre11 (built Nov 12 2015 16:25:28, protocol 17.4)
# setup my-network, keys, hosts...
NETWORK="mynet"
CONFIG_DIR="/usr/local/etc/tinc"
NETWORK_DIR="$CONFIG_DIR/$NETWORK"
mkdir -p NETWORK_DIR
mkdir -p /usr/local/var/run/
echo "Name = $NODE_NAME
AddressFamily = ipv4
Interface = tun0
ConnectTo = $OTHER_NODE_NAME" > $CONFIG_DIR/tinc.conf
#set static up (or do some advanced stuff)
echo "ifconfig \$INTERFACE 10.0.0.7 netmask 255.255.255.0" > $NETWORK_DIR/tinc-up
echo "ifconfig \$INTERFACE down" > $NETWORK_DIR/tinc-down
#make these scripts executable
chmod +x $NETWORK_DIR/*
#test with this until it works
tincd -D -n $NETWORK -d3 --logfile=/dev/stdout
#setup startup scripts
#=====================
#if systemd, use tinc systemd.service (RECOMMENDED)
nano /usr/lib/systemd/system/tinc.service
systemctl enable tinc
#=====================
#if upstart/sysvinit, use tinc upstart
nano /etc/init.d/tinc
update-rc.d tinc defaults
echo "$NETWORK --debug=3 --logfile=/var/log/tinc.log" >> $CONFIG_DIR/nets.boot
#=====================
#and then start
service tinc start
[Unit]
Description=tinc
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/local/sbin/tincd -D --config=/usr/local/etc/tinc/mynet --debug=3
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
#! /bin/sh
#
# /etc/init.d/tinc
#
### BEGIN INIT INFO
# Provides: tinc
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Should-Start: $syslog $named
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start tinc daemons
# Description: Create a file $NETSFILE (/etc/tinc/nets.boot),
# and put all the names of the networks in there.
# These names must be valid directory names under
# $TCONF (/etc/tinc). Lines starting with a # will be
# ignored in this file.
### END INIT INFO
#
# Based on Lubomir Bulej's Redhat init script.
DAEMON="/usr/local/sbin/tincd"
NAME="tinc"
DESC="tinc daemons"
TCONF="/usr/local/etc/tinc"
NETSFILE="$TCONF/nets.boot"
NETS=""
test -f $DAEMON || exit 0
[ -r /etc/default/tinc ] && . /etc/default/tinc
# foreach_net "what-to-say" action [arguments...]
foreach_net() {
if [ ! -f $NETSFILE ] ; then
echo "Please create $NETSFILE."
exit 0
fi
echo -n "$1"
shift
egrep '^[ ]*[a-zA-Z0-9_-]+' $NETSFILE | while read net args; do
echo -n "starting '$net' with '$args'"
"$DAEMON" --config="$TCONF/$net" $args
done
echo "."
}
signal_running() {
for i in /var/run/tinc.*pid; do
if [ -f "$i" ]; then
head -1 $i | while read pid; do
kill -$1 $pid
done
fi
done
}
start() {
$DAEMON $EXTRA -n "$@"
}
stop() {
$DAEMON -n $1 -k
}
reload() {
$DAEMON -n $1 -kHUP
}
alarm() {
$DAEMON -n $1 -kALRM
}
restart() {
stop "$@"
sleep 0.5
i=0;
while [ -f /var/run/tinc.$1.pid ] ; do
if [ $i = '10' ] ; then
break
else
echo -n "."
sleep 0.5
i=$(($i+1))
fi
done
start "$@"
}
case "$1" in
start)
foreach_net "Starting $DESC:" start
;;
stop)
foreach_net "Stopping $DESC:" stop
;;
reload|force-reload)
foreach_net "Reloading $DESC configuration:" reload
;;
restart)
foreach_net "Restarting $DESC:" restart
;;
alarm)
signal_running ALRM
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|alarm}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment