Tinc VPN

时间:2022-05-04 14:48:22

服务端配置

安装

$ apt-get install tinc

配置

$ mkdir -p /etc/tinc/dock/hosts
$ cd /etc/tinc/dock

配置 tinc.conf

$ vim /etc/tinc/dock/tinc.conf
Name=dockserver
Interface=dock
Mode=switch
TCPOnly=yes
Port=12345
PrivateKeyFile=/etc/tinc/dock/rsa_key.priv

配置 tinc-up

$ vim /etc/tinc/dock/tinc-up
#!/bin/sh
ifconfig $INTERFACE 192.168.0.1 netmask 255.255.255.0

配置 tinc-down

$ vim /etc/tinc/dock/tinc-down
#!/bin/sh
ifconfig $INTERFACE down

Service 配置 dockserver,其中 Address 为服务端的实际 IP 地址

$ vim /etc/tinc/dock/hosts/dockserver
Compression=9
Subnet=192.168.0.1/32
Address=x.x.x.x
Port=54321

修改权限

$ chmod 755 /etc/tinc/dock/{tinc-down,tinc-up}

服务端生成 key

$ cd /etc/tinc/
$ tincd -n dock -K
Generating 2048 bits keys:
...............................................+++ p
............................................................+++ q
Done.
Please enter a file to save private RSA key to [/etc/tinc/vpn/rsa_key.priv]:
Please enter a file to save public RSA key to [/etc/tinc/vpn/hosts/vpnserver]:

客户端配置

安装

$ apt-get install tinc

配置

$ mkdir -p /etc/tinc/dock/hosts$ cd /etc/tinc/dock

创建 tinc.conf 配置文件

$ vim /etc/tinc/dock/tinc.conf
Name=client01
ConnectTo=dockserver
Interfce=dock
Mode=switch
TCPOnly=yes
PrivateKeyFile=/etc/tinc/dock/rsa_key.priv

创建 tinc-down

$ vim /etc/tinc/dock/tinc-down
#!/bin/sh
ifconfig $INTERFACE down

创建 tinc-up

$ vim /etc/tinc/dock/tinc-up
#!/bin/sh
ifconfig $INTERFACE 192.168.0.2 netmask 255.255.255.0

创建 clinent01 配置文件

$ vim /etc/tinc/dock/hosts/client01
Compression=9
Subnet=192.168.0.2/32

修改权限

$ chmod 755 /etc/tinc/dock/{tinc-down,tinc-up}

把服务端的 dockserver 拷贝到客户端

$ scp root@x.x.x.x:/etc/tinc/dock/hosts/dockserver /etc/tinc/dock/hosts/dockserver

客户端生成 key

$ tincd -n dock -K
Generating 2048 bits keys:
................................................+++ p
......+++ q
Done.
Please enter a file to save private RSA key to [/etc/tinc/vpn/rsa_key.priv]:
Please enter a file to save public RSA key to [/etc/tinc/vpn/hosts/vpnclient01]:

把客户端生成的配置文件拷贝到服务端

$ scp /etc/tinc/dock/hosts/client01 root@x.x.x.x:/etc/tinc/dock/hosts/client01

启动和关闭

$ tincd -n dock        #启动tinc vpn
$ tincd -n dock -k     #关闭tinc vpn

启动完成后查看 ifconfig 后会有 dock 的网卡参数

$ ifconfig
dock         Link encap:Ethernet  HWaddr c2:f1:b3:6d:7a:f2          
             inet addr:192.168.0.1 
             Bcast:192.168.0.255 
             Mask:255.255.255.0          
             UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          
             RX packets:5 errors:0 dropped:0 overruns:0 frame:0          
             TX packets:4 errors:0 dropped:0 overruns:0 carrier:0          
             collisions:0 txqueuelen:1000          
             RX bytes:950 (950.0 B)   TX bytes:280 (280.0 B)

客户端为 192.168.0.2 ,如果不互通可以把 tincd 启动在前台查看日志

$ tincd -n dock -D -d 5