关于Tinc VPN的搭建
关于
Tinc 是一种相对小众的VPN方案。但是支持很多环境的安装,例如ubuntu,centos都可以用自带的包管理工具安装。
下面是对于Ubuntu的示例
准备两台(至少)机器
至少要有一台机器有稳定的公网IP
安装
在两台机器上都安装tincapt update && apt install -y tinc
配置
以下分别命名两台机器为pek,lax
下面我们建一个tinc名为test
网卡tinc0,内网网段设置为172.16.0.0/28
创建test目录
两边都执行mkdir /etc/tinc/test && mkdir /etc/tinc/test/hosts
编辑tinc.conf即tinc的配置文件
vim /etc/tinc/test/tinc.conf
分两部分
pek写入
1 | Interface = tinc0 |
lax写入
1 | Interface = tinc0 |
编辑tinc-up,即当启用test时需要tinc执行的脚本
vim /etc/tinc/test/tinc-up
pek写入
1 |
|
lax写入
1 | #!/bin/sh |
编辑tinc-down,即当关闭test时需要tinc执行的脚本
vim /etc/tinc/test/tinc-down
两边都键入
1 | #!/bin/sh |
给予tinc-up和tinc-down脚本添加执行权限
chmod +x tinc-*
创建tinc之间交互需要的秘钥,
cd /etc/tinc/test && tincd -K4096 -n test
交换lax和pek的秘钥
将lax上的/etc/tinc/test/hosts/lax的内容写入pek的/etc/tinc/test/hosts/lax文件内 并在第一行加入Address=<lax的外网IP>
将pek上的/etc/tinc/test/hosts/pek的内容写入pek的/etc/tinc/test/hosts/pek文件内 并在第一行加入 Address=<pek的外网IP>
简单的来说就是交换两台机器彼此的秘钥,并写入IP地址
将test写入tinc的nets.boot中,并重启tinc
echo 'test' >### /etc/tinc/nets.boot && service tinc restart
之后就可以用ifconfig来查看是否有新加的tinc0网卡,以及IP地址。可以用ping来校验双方是否联通
参考
关于Tinc VPN的搭建