一、tun服务器启动步骤
# 服务器端初始化: 配置tun0 IP地址
# 例子:
ip tuntap add tun0 mode tun user root group root
ip link set tun0 up
ip addr add 10.3.3.3/24 dev tun0 # 注: ip addr add {虚拟IP/子网掩码} dev tun0
# 服务器端通过调整IP路由表限制网络包的流向
ip route add to 192.168.1.18 dev ens33 src 192.168.1.16 # ip route add to 192.168.1.18 dev ens33 sr'c 服务器真实IP
ip route delete default
ip route add default via "虚拟IP例如10.3.3.3" dev tun0
# 服务器端口封禁规则
iptables 只允许特定TCP端口(此处选的端口是55555)流量进入和应答
不允许任何其他端口有数据包流出
# 启动simpletun程序
./simpletun -d -u -i tun0 -s -p 55555
二、tun客户端
ip tuntap add tun0 mode tun user root group root
ip link set tun0 up
ip addr add 10.3.3.100/24 dev tun0
sudo ./simpletun -d -u -i tun0 -c 192.168.1.16 -p 55555
# netcat工具模拟: 客户机其他软件向服务器端发送普通数据
nc -4 -u 10.3.3.3 8888
【备忘】 simpletun命令行参数定义如下:
Usage:
./simpletun -i [-s|-c ] [-p ] [-u|-a] [-d]
./simpletun -h
-i : Name of interface to use (mandatory)
-s|-c : run in server mode (-s), or specify server address (-c ) (mandatory)
-p : port to listen on (if run in server mode) or to connect to (in client mode), default 55555
-u|-a: use TUN (-u, default) or TAP (-a)
-d: outputs debug information while running
-h: prints this help text
cat /etc/iproute2/rt_tables
ip route list table local
ip route list table main
ip route add
No comments:
Post a Comment