sish:一个开源、轻量且类似于Servo/Ngrok的内网穿透工具

 说明:sish是一个SSH服务器,仅用于远程端口转发,可以快速将本地端口暴露在外网,作者声称其为Servo/Ngrok替代方案,仅使用SSH的HTTP(S)、WS(S)、TCP隧道连接到他们的localhost服务器,该工具和Servo差不多一样,不同就是Servo官方提供了免费的SSH客户端,而sish作者提供的客户端貌似因为滥用关闭了,所以就需要我们自己搭建了,这里就水下Docker和手动安装。

Docker安装

1、安装Docker
  1. #CentOS 6
  2. rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  3. yum update -y
  4. yum -y install docker-io
  5. service docker start
  6. chkconfig docker on
  7.  
  8. #CentOS 7、Debian、Ubuntu
  9. curl -sSL https://get.docker.com/ | sh
  10. systemctl start docker
  11. systemctl enable docker
2、拉取镜像
这里由于直接使用ip的话,只能用于转发TCP,HTTP(S)等就需要配置下域名了,所以以下全部默认使用域名。
先解析一个主/泛域名到服务器ip,比如解析moerats.com、*.moerats.com到服务器ip。
然后再参考下面的参数详解,再自行修改部分参数后,使用命令:
  1. #配置http域名
  2. docker run -d --name sish
  3. --restart=always
  4. -v ~/sish/keys:/keys
  5. -v ~/sish/pubkeys:/pubkeys
  6. --net=host antoniomika/sish
  7. -sish.addr=:3333
  8. -sish.http=:80
  9. -sish.keysdir=/pubkeys
  10. -sish.pkloc=/keys/ssh_key
  11. -sish.forcerandomsubdomain=false
  12. -sish.domain moerats.com
  13. -sish.bindrandom=false
  14. -sish.redirectrootlocation https://www.baidu.com
  15.  
  16. #配置https域名,这里需要提供泛域名证书
  17. docker run -d --name sish
  18. --restart=always
  19. -v ~/sish/ssl:/ssl
  20. -v ~/sish/keys:/keys
  21. -v ~/sish/pubkeys:/pubkeys
  22. --net=host antoniomika/sish
  23. -sish.addr=:3333
  24. -sish.https=:443
  25. -sish.http=:80
  26. -sish.httpsenabled=true
  27. -sish.httpspems=/ssl
  28. -sish.keysdir=/pubkeys
  29. -sish.pkloc=/keys/ssh_key
  30. -sish.forcerandomsubdomain=false
  31. -sish.domain moerats.com
  32. -sish.bindrandom=false
  33. -sish.redirectrootlocation https://www.baidu.com
部分参数如下:
  1. -sish.addr=:3333 #ssh监听地址
  2. -sish.forcerandomsubdomain=false #是否强制随机子域,这个建议关掉
  3. -sish.bindrandom=false #是否随机绑定端口,这个建议关掉
  4. -sish.domain moerats.com #使用的域名
  5. -sish.redirectrootlocation https://www.baidu.com #主域名(-sish.domain参数)强制跳转到该地址
  6. -sish.httpspems=/ssl #泛域名SSL证书路径,存放路径~/sish/ssl,证书命名格式fullchain.pemprivkey.pem
其他参数默认即可,也可以自行添加或修改其它参数。
全部参数如下:
  1. Usage of sish:
  2. -sish.addr string
  3. The address to listen for SSH connections (default "localhost:2222")
  4. -sish.auth
  5. Whether or not to require auth on the SSH service
  6. -sish.bannedcountries string
  7. A comma separated list of banned countries
  8. -sish.bannedips string
  9. A comma separated list of banned ips
  10. -sish.bannedsubdomains string
  11. A comma separated list of banned subdomains (default "localhost")
  12. -sish.bindrandom
  13. Bind ports randomly (OS chooses) (default true)
  14. -sish.bindrange string
  15. Ports that are allowed to be bound (default "0,1024-65535")
  16. -sish.cleanupunbound
  17. Whether or not to cleanup unbound (forwarded) SSH connections (default true)
  18. -sish.debug
  19. Whether or not to print debug information
  20. -sish.domain string
  21. The domain for HTTP(S) multiplexing (default "ssi.sh")
  22. -sish.forcerandomsubdomain
  23. Whether or not to force a random subdomain (default true)
  24. -sish.http string
  25. The address to listen for HTTP connections (default "localhost:80")
  26. -sish.httpport int
  27. The port for HTTP connections. This is only for output messages (default 80)
  28. -sish.https string
  29. The address to listen for HTTPS connections (default "localhost:443")
  30. -sish.httpsenabled
  31. Whether or not to listen for HTTPS connections
  32. -sish.httpspems string
  33. The location of pem files for HTTPS (fullchain.pem and privkey.pem) (default "ssl/")
  34. -sish.httpsport int
  35. The port for HTTPS connections. This is only for output messages (default 443)
  36. -sish.keysdir string
  37. Directory for public keys for pubkey auth (default "pubkeys/")
  38. -sish.password string
  39. Password to use for password auth (default "S3Cr3tP4$$W0rD")
  40. -sish.pkloc string
  41. SSH server private key (default "keys/ssh_key")
  42. -sish.pkpass string
  43. Passphrase to use for the server private key (default "S3Cr3tP4$$phrAsE")
  44. -sish.proxyprotoenabled
  45. Whether or not to enable the use of the proxy protocol
  46. -sish.proxyprotoversion string
  47. What version of the proxy protocol to use. Can either be 1, 2, or userdefined. If userdefined, the user needs to add a command to SSH called proxy:version (ie proxy:1) (default "1")
  48. -sish.redirectroot
  49. Whether or not to redirect the root domain (default true)
  50. -sish.redirectrootlocation string
  51. Where to redirect the root domain to (default "https://github.com/antoniomika/sish")
  52. -sish.subdomainlen int
  53. The length of the random subdomain to generate (default 3)
  54. -sish.usegeodb
  55. Whether or not to use the maxmind geodb
  56. -sish.verifyorigin
  57. Whether or not to verify origin on websocket connection (default true)
  58. -sish.verifyssl
  59. Whether or not to verify SSL on proxy connection (default true)
  60. -sish.whitelistedcountries string
  61. A comma separated list of whitelisted countries
  62. -sish.whitelistedips string
  63. A comma separated list of whitelisted ips
看不懂的,可以使用下谷歌翻译。
最后CentOS系统建议关闭防火墙使用,或者打开部分端口也行,关闭命令:
  1. #CentOS 6系统
  2. service iptables stop
  3. chkconfig iptables off
  4.  
  5. #CentOS 7系统
  6. systemctl stop firewalld
  7. systemctl disable firewalld
像阿里云等服务器,还需要去安全组那里开放下端口。

手动安装

Docker虽然方便很多,但也有人会喜欢手动安装,这里作者没直接给出二进制文件,所以就需要我们手动来构建二进制文件了。
1、安装Go
这里由于需要新版的Go环境,所以这里就使用Go二进制包安装环境,下载地址→传送门
然后根据自己的服务器架构下载对应的最新安装包,一般可以直接使用命令:
  1. #32位系统下载
  2. wget -O go.tar.gz https://dl.google.com/go/go1.13.3.linux-386.tar.gz
  3. #64位系统下载
  4. wget -O go.tar.gz https://dl.google.com/go/go1.13.3.linux-amd64.tar.gz
  5.  
  6. #解压压缩包
  7. tar -zxvf go.tar.gz -C /usr/local
  8. #设置环境变量,将以下一起复制进ssh客户端运行
  9. mkdir $HOME/go
  10. echo 'export GOROOT=/usr/local/go
  11. export GOPATH=$HOME/go
  12. export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> /etc/profile
  13. source /etc/profile
  14. #查看go版本,有输出即为安装成功
  15. go version
2、安装sish
  1. #下载源码到主目录
  2. git clone https://github.com/antoniomika/sish
  3. cd sish
  4. #编译二进制文件
  5. go install
这里提示-bash: git: command not found的,可以先使用命令:
  1. #CentOS
  2. yum -y install git
  3.  
  4. #Debian、Ubuntu
  5. apt install git -y
3、运行sish
运行参数这里就不贴了,直接参考上面Docker安装最下面的全部参数就行了。
先解析一个主/泛域名到服务器ip,比如解析moerats.com、*.moerats.com到服务器ip。
这里就贴个大概需要使用的参数,其它的根据需求自行修改,使用命令:
  1. #配置http域名
  2. sish -sish.addr=:3333 -sish.http=:80 -sish.domain moerats.com -sish.forcerandomsubdomain=false -sish.bindrandom=false -sish.redirectrootlocation https://www.moerats.com -sish.keysdir=/sish/pubkeys -sish.pkloc=/sish/keys/ssh_key
  3.  
  4. #配置https域名
  5. sish -sish.addr=:3333 -sish.https=:443 -sish.http=:80 -sish.domain moerats.com -sish.forcerandomsubdomain=false -sish.bindrandom=false -sish.httpsenabled=true -sish.redirectrootlocation https://www.moerats.com -sish.keysdir=/sish/pubkeys -sish.pkloc=/sish/keys/ssh_key -sish.httpspems=/sish/ssl
部分参数详解:
  1. -sish.addr=:3333 #ssh监听地址,这里为3333
  2. -sish.forcerandomsubdomain=false #是否强制随机子域,这个建议关掉
  3. -sish.bindrandom=false #是否随机绑定端口,这个建议关掉
  4. -sish.domain moerats.com #使用的域名
  5. -sish.redirectrootlocation https://www.baidu.com #主域名(-sish.domain参数)强制跳转到该地址
  6. -sish.httpspems=/sish/ssl #泛域名SSL证书存放路径,证书命名格式fullchain.pem和privkey.pem
  7. -sish.keysdir=/sish/pubkeys #pubkey auth的公共密钥存放文件夹
  8. -sish.pkloc=/sish/keys/ssh_key #SSH服务器私钥

这里/sish/ssl、/sish/pubkeys、/sish/keys目录需要自己提前创建下,使用命令:mkdir -p /sish/ssl /sish/pubkeys /sish/keys
4、开机自启
如果你使用手动命令没问题了,先使用Ctrl+C断开命令。
再新建systemd配置文件,适用CentOS 7、Debian 8+、Ubuntu 16+。
  1. #修改成你手动运行命令的全部参数
  2. command="-sish.addr=:3333 -sish.http=:80 -sish.domain moerats.com -sish.forcerandomsubdomain=false -sish.bindrandom=false -sish.redirectrootlocation https://www.moerats.com -sish.keysdir=/sish/pubkeys -sish.pkloc=/sish/keys"
  3. #将以下代码一起复制到SSH运行
  4. cat > /etc/systemd/system/sish.service <<EOF
  5. [Unit]
  6. Description=sish
  7. After=network.target
  8.  
  9. [Service]
  10. Type=simple
  11. ExecStart=$(command -v sish) ${command}
  12. Restart=on-failure
  13.  
  14. [Install]
  15. WantedBy=multi-user.target
  16. EOF
启动并设置开机自启:
  1. systemctl start sish
  2. systemctl enable sish
最后CentOS系统建议关闭防火墙使用,或者打开部分端口也行,关闭命令:
  1. #CentOS 6系统
  2. service iptables stop
  3. chkconfig iptables off
  4.  
  5. #CentOS 7系统
  6. systemctl stop firewalld
  7. systemctl disable firewalld

像阿里云等服务器,还需要去安全组那里开放下端口。

使用

使用要求:可以使用SSH,并且能连接到互联网,Linux、Windows等系统都行。
以下所使用的的moerats.com为上面配置好的客户端域名地址,自行修改成自己的即可。
1、转发HTTP(S)
将本地3000端口穿透到公网中,使用命令:
  1. #要转发其它端口的自行替换
  2. ssh -p 3333 -R 80:localhost:3000 moerats.com
第一次如果有提示,选择yes即可,之后会为你随机生成一个moerats.com的二级域名,然后就可以使用浏览器间接访问本地的localhost:3000了。
如果要指定二级域名,可以使用命令:
  1. #这里默认为no1.moerats.com,自行替换即可
  2. ssh -p 3333 -R no1:80:localhost:3000 moerats.com
此时你就可以在外网使用no1.moerats.com访问你本地的localhost:3000了。
2、转发TCP
将本地6789端口穿透到公网的9876端口中,使用命令:
  1. #可以自行设置公网端口,这里默认6789,如果你要转发SSH端口,那就改成你的SSH端口
  2. ssh -p 3333 -R 9876:localhost:6789 moerats.com
这里只说了下简单用法,客户端我们还可以设置国家/地区、IP白名单等,使用参考→传送门
最后没有泛域名证书的,可以查看该教程自己申请→传送门,或者等博主发码子→传送门。 

运维教程

【原创】.htaccess伪静态规则文件的另类用法+Apache环境

2019-12-22 8:20:23

运维教程

教你解决宝塔面板加载慢的问题[宝塔面板运维教程]

2020-1-16 9:29:27

本站所发布的一切源码、模板、应用等文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。如有侵权。本站内容适用于DMCA政策。若您的权利被侵害,请与我们联系处理,站长 QQ: 84087680 或 点击右侧 私信:盾给网 反馈,我们将尽快处理。
⚠️
本站所发布的一切源码、模板、应用等文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。如有侵权。本站内容适用于DMCA政策
若您的权利被侵害,请与我们联系处理,站长 QQ: 84087680 或 点击右侧 私信:盾给网 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
私信列表
搜索