brew install tinc
mkdir -p /usr/local/etc/tinc/example
Name = macos
Device = utun0 # use an unused number
ConnectTo = linux
#!/bin/sh
ifconfig $INTERFACE 192.168.0.2 192.168.0.1 mtu 1500 netmask 255.255.255.255
#!/bin/sh
ifconfig $INTERFACE down
#!/bin/sh
[ "$NAME" = "$NODE" ] && exit 0
/usr/local/opt/iproute2mac/bin/ip route add $SUBNET dev $INTERFACE
#!/bin/sh
[ "$NAME" = "$NODE" ] && exit 0
/usr/local/opt/iproute2mac/bin/ip route del $SUBNET dev $INTERFACE
chmod 755 tinc-up
chmod 755 tinc-down
chmod 755 subnet-up
chmod 755 subnet-down
Port = 655
Subnet = 192.168.0.1/24
tincd -n example -K
生成密钥。$ mkdir -p /etc/tinc/example/hosts
$ cat /etc/tinc/example/tinc.conf
Name = linux
$ cat /etc/tinc/example/tinc-up
$!/bin/sh
ip link set $INTERFACE up
ip addr add 192.168.0.1/24 dev $INTERFACE
$ cat /etc/tinc/example/tinc-down
$!/bin/sh
ip addr del 192.168.0.1/24 dev $INTERFACE
ip link set $INTERFACE down
$ cat /etc/tinc/example/hosts/linux
Address = linux_ip
Port = 655
Subnet = 192.168.0.1/24
$ tincd -n example -K
tinc -n example -D -d3
即可看到连接的建立,通过 ping 即可验证网络建立成功。$ cat tinc.conf
Name = example
Device = /dev/tun
Mode = switch
ConnectTo = remote
ScriptsInterpreter = /system/bin/sh
$ cat tinc-up
#!/bin/sh
ip link set $INTERFACE up
ip addr add local_ip/24 dev $INTERFACE
$ cat tinc-down
#!/bin/sh
ip addr del local_ip/24 dev $INTERFACE
ip link set $INTERFACE down
$ cat subnet-up
$!/bin/bash
[ "$NAME" = "$NODE" ] && exit 0
ip route add $SUBNET dev $INTERFACE metric $WEIGHT table local
$ cat subnet-down
#!/bin/bash
[ "$NAME" = "$NODE" ] && exit 0
ip route del $SUBNET dev $INTERFACE table local
Step by step guide to setup tinc VPN
Tinc is a peer to peer VPN software to create a mesh network. (https://www.tinc-vpn.org)
In this gudie, I will show you how to setup an Azure VPS act as a server named tiger and a local client named howard.
Server installation
sudo apt install tinc
sudo vi /etc/sysctl.conf
uncommend:
net.ipv4.ip_forward=1
sudo sysctl -p
cd /etc/tinc
sudo mkdir -p tiger/hosts
cd tiger
sudo vi tinc.conf
Write below content.
Name = tiger
AddressFamily = ipv4
Interface = tun0
sudo vi tinc-up
Write below content.
#!/bin/sh
ip link set $INTERFACE up
ip addr add 192.168.60.1/24 dev $INTERFACE
iptables -A POSTROUTING -t nat -s 192.168.60.0/24 -j MASQUERADE -o eth0
sudo chmod +x tinc-up
sudo vi tinc-down
Write below content.
#!/bin/sh
ip link set $INTERFACE down
iptables -D POSTROUTING -t nat -s 192.168.60.0/24 -j MASQUERADE -o eth0
sudo chmod +x tinc-down
cd hosts
sudo vi tiger
Write below content. Replace <server-public-ip>
with the server's public IP address.
Address =
<server-public-ip>
Port = 443
Subnet = 0.0.0.0/0
sudo tincd -n tiger -K4096
sudo vi /etc/tinc/nets.boot
Append a new line.
tiger
sudo systemctl enable tinc@tiger
sudo systemctl start tinc@tiger
Client installation
sudo apt install tinc
cd /etc/tinc
sudo mkdir -p howard/hosts
cd howard
sudo vi tinc.conf
Write below content.
Name = howard
AddressFamily = ipv4
Interface = tun0
ConnectTo = tiger
sudo vi tinc-up
Write below content. Replace <server-public-ip>
with the server's public IP address.
#!/bin/sh
ip link set $INTERFACE up
ip addr add 192.168.60.2/24 dev $INTERFACE
ip route add 192.168.60.254/24 dev $INTERFACEVPN_GATEWAY=192.168.60.1
REMOTEADDRESS=<server-public-ip>
ORIGINAL_GATEWAY=`ip route show | grep ^default | cut -d ' ' -f 2-5`ip route add $REMOTEADDRESS $ORIGINAL_GATEWAY
ip route add $VPN_GATEWAY dev $INTERFACE
ip route add 0.0.0.0/1 via $VPN_GATEWAY dev $INTERFACE
ip route add 128.0.0.0/1 via $VPN_GATEWAY dev $INTERFACE
sudo chmod +x tinc-up
sudo vi tinc-down
Write below content. Replace <server-public-ip>
with the server's public IP address.
#!/bin/sh
ip link set $INTERFACE downVPN_GATEWAY=192.168.60.1
ORIGINAL_GATEWAY=`ip route show | grep ^default | cut -d ' ' -f 2-5`
REMOTEADDRESS=<server-public-ip>
ip route del $REMOTEADDRESS $ORIGINAL_GATEWAY
ip route del $VPN_GATEWAY dev $INTERFACE
ip route del 0.0.0.0/1 dev $INTERFACE
ip route del 128.0.0.0/1 dev $INTERFACE
sudo chmod +x tinc-down
cd hosts
sudo vi howard
Write below content.
Subnet = 192.168.60.2/32
sudo tincd -n howard -K4096
Exchange host files.
Copy the file
tiger
from the folder/etc/tinc/tiger/hosts
on the server to the folder/etc/tinc/howard/hosts
on the client.
Copy the filehoward
from the folder/etc/tinc/howard/hosts
on the client to the folder/etc/tinc/tiger/hosts
on the server.
- Launch tinc on demand with command
sudo tincd -n howard -D
Use command line
sudo pkill tincd
to stop.
- Customize DNS
You may want to specify an external DNS server to resolve some blocked domain names in some countries.
sudo vi /etc/systemd/resolved.conf
Set below settings.
[Resolve]
DNS=8.8.8.8 8.8.4.4
Domains=~.sudo systemctl restart systemd-resolved
from https://github.com/tianhu/bigpipe
----------------------------------------------
No comments:
Post a Comment