梅林安装zerotier实现内网穿透 - 插件 - KoolShare

wizjj /  2018-04-20  /  人气 941

梅林安装zerotier实现内网穿透 - 插件 - KoolShare

无技术活,纯代码,ssh下复制执行就行
先安装zerotier
  1. opkg update
  2. opkg install zerotier
复制代码

运行zerotier

  1. modprobe tun
  2. zerotier-one -d
  3. zerotier-cli info
复制代码
200 info 497845b7e 1.2.4 ONLINE

加入申请到的网络代码

  1. zerotier-cli join 9*************e
复制代码
200 join OK

获取ip值

  1. zerotier-cli listnetworks
复制代码
200 listnetworks <nwid> <name> <mac> <status> <type> <dev> <ZT assigned ips>
200 listnetworks 9*************e laomms aa:bb:cc:dd:ee OK PUBLIC zt0 170.21.0.19/16

ping一下看通不通
PING 170.21.0.19 (170.21.0.19): 56 data bytes
64 bytes from 170.21.0.19: seq=0 ttl=64 time=0.237 ms
--- 170.21.0.19 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.097/0.139/0.237 ms


添加端口映射表:
先用iptables -v -L INPUT -n --line-numbers查询所有iptables情况:

  1. iptables -v -t nat -L -n --line-numbers
复制代码

  1. admin@RT-AC5300-56A0:/tmp/home/root# iptables -v -L INPUT -n --line-numbers
  2. Chain INPUT (policy ACCEPT 4304 packets, 798K bytes)
  3. num pkts bytes target prot opt in out source destination
  4. 1 65 5109 DROP icmp -- ppp0 * 0.0.0.0/0 0.0.0.0/0
  5. 2 0 0 DROP icmp -- ppp0 * 0.0.0.0/0 0.0.0.0/0
  6. 3 15182 2917K INPUT_EasyExplorer all -- * * 0.0.0.0/0 0.0.0.0/0
  7. 4 15182 2917K INPUT_EasyExplorer all -- * * 0.0.0.0/0 0.0.0.0/0
  8. 5 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1688
复制代码
添加一条iptables:
  1. iptables -I INPUT 6 -i zt0 -j ACCEPT
复制代码
注意这里的6是继上面5条之后加一条。再看下,已经加进去了:
  1. admin@RT-AC5300-56A0:/tmp/home/root# iptables -v -L INPUT -n --line-numbers
  2. Chain INPUT (policy ACCEPT 1164 packets, 256K bytes)
  3. num pkts bytes target prot opt in out source destination
  4. 1 79 6117 DROP icmp -- ppp0 * 0.0.0.0/0 0.0.0.0/0
  5. 2 0 0 DROP icmp -- ppp0 * 0.0.0.0/0 0.0.0.0/0
  6. 3 18024 3524K INPUT_EasyExplorer all -- * * 0.0.0.0/0 0.0.0.0/0
  7. 4 18024 3524K INPUT_EasyExplorer all -- * * 0.0.0.0/0 0.0.0.0/0
  8. 5 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1688
  9. 6 10 1431 ACCEPT all -- zt0 * 0.0.0.0/0 0.0.0.0/0
复制代码



重启zerotier:
  1. killall zerotier-one
  2. zerotier-one -d
复制代码
设置开机加载tun驱动并检测脚本是否运行:
  1. echo "modprobe tun" >> /jffs/scripts/nat-start
  2. echo "cru a ZeroTierDaemon "/opt/etc/init.d/S90zerotier-one.sh start"" >> /jffs/scripts/wan-start
复制代码

端口映射,添加/jffs/scripts/nat-start内容,并设置开机启动
iptables -t nat -A PREROUTING -d 170.21.0.19 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1:80
用命令行实现:
  1. echo "iptables -t nat -A PREROUTING -d 170.21.0.19 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1:80" >> /jffs/scripts/nat-start
  2. echo "/opt/etc/init.d/S90zerotier-one.sh" >> /jffs/scripts/nat-start
  3. chmod a+rx /jffs/scripts/*
复制代码

启动脚本放到相应目录

  1. chmod 755 /opt/etc/init.d/S90zerotier-one.sh
复制代码


添加防火墙规则(没有开启防火墙这个无所谓):
  1. echo "logger -t "custom iptables" "Enter" -p user.notice" >> /jffs/scripts/firewall-start
  2. echo "iptables -C INPUT -i zt0 -j ACCEPT" >> /jffs/scripts/firewall-start
  3. echo "if [ $? != 0 ]; then" >> /jffs/scripts/firewall-start
  4. echo "#iptables -I INPUT -i zt0 -j ACCEPT" >> /jffs/scripts/firewall-start
  5. echo "#iptables -I INPUT -i zt0 -p icmp -j ACCEPT" >> /jffs/scripts/firewall-start
  6. echo "iptables -I INPUT 1 -i ppp0 -p icmp -j DROP" >> /jffs/scripts/firewall-start
  7. echo "iptables -t nat -A PREROUTING -d <span style="color: rgb(68, 68, 68); font-family: Tahoma; background-color: rgb(255, 255, 255);">170.21.0.19</span> -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1:80" >> /jffs/scripts/firewall-start
  8. echo "logger -t "custom iptables" "rules added" -p user.notice" >> /jffs/scripts/firewall-start
  9. echo "else" >> /jffs/scripts/firewall-start
  10. echo "logger -t "custom iptables" "rules existed skip" -p user.notice" >> /jffs/scripts/firewall-start
  11. echo "fi" >> /jffs/scripts/firewall-start
复制代码

S90zerotier-one.sh脚本内容:

  1. #! /bin/sh
  2. case "$1" in
  3.   start)
  4.     if ( pidof zerotier-one )
  5.     then echo "ZeroTier-One is already running."
  6.     else
  7.         echo "Starting ZeroTier-One" ;
  8.         /opt/bin/zerotier-one -d ;
  9.         echo "$(date) Started ZeroTier-One" >> /opt/var/log/zerotier-one.log ;
  10.     fi
  11.     ;;
  12.   stop)
  13.     if ( pidof zerotier-one )
  14.     then
  15.         echo "Stopping ZeroTier-One";
  16.         killall zerotier-one
  17.         echo "$(date) Stopped ZeroTier-One" >> /opt/var/log/zerotier-one.log
  18.     else
  19.         echo "ZeroTier-One was not running" ;
  20.     fi
  21.     ;;
  22.   status)
  23.     if ( pidof zerotier-one )
  24.     then echo "ZeroTier-One is running."
  25.     else echo "ZeroTier-One is NOT running"
  26.     fi
  27.     ;;
  28.   *)
  29.     echo "Usage: /etc/init.d/zerotier-one {start|stop|status}"
  30.     exit 1
  31.     ;;
  32. esac
  33. exit 0
复制代码
来源地址: http://koolshare.cn/thread-134930-1-1.html

没写清晰 看不明确 ? 我们评论区见,发表评论等待作者迅速回复 ^_^

评论0
发表评论请 登录