惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cloudbric
Cloudbric
V
Visual Studio Blog
L
LangChain Blog
A
About on SuperTechFans
B
Blog
T
Tenable Blog
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Palo Alto Networks Blog
U
Unit 42
WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
C
Check Point Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence
Application and Cybersecurity Blog
Application and Cybersecurity Blog
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
NISL@THU
NISL@THU
Forbes - Security
Forbes - Security
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
GbyAI
GbyAI
T
Troy Hunt's Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
V2EX - 技术
V2EX - 技术
小众软件
小众软件
Google DeepMind News
Google DeepMind News
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
Netflix TechBlog - Medium
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed

博客园 - centosboy

Thinkpad T490卡顿排查 xinference初探 diff的安装与使用 ubuntu docker运行大模型 vllm部署 zabbix监控mongodb /root/.dbshell无权限解决办法 开机启动后应用limit没有生效 关于运维工作的一点感悟 将CDLINUX装入U盘 hive分区表实践 hashlib模块 rm 防误删脚本 linux 通过inode删除文件 那些年踩过的坑 htpdate代替ntpdate同步时间 Openfire搭建聊天系统 zookeeper运维 centos ping添加丢包记录 Linux tee命令输出显示在屏幕和保存到日志文件中
Autossh打洞
centosboy · 2020-12-15 · via 博客园 - centosboy

autossh介绍:

autossh 是一个用来启动 ssh 并进行监控的程序,可在需要时重启 ssh,如果程序问题或者是网络问题。其灵感和机制来自于 rstunnel (Reliable SSH Tunnel). autossh 1.2 的方法已经改变:autossh 使用 ssh 来构造一个 ssh 重定向循环(本地到远程和远程到本地),然后发送测试数据并获得返回结果。

内网主机主动连接到外网主机,又被称作反向连接(Reverse Connection),这样NAT路由/防火墙就会在内网主机和外网主机之间建立映射即可相互通信了。但这种映射是路由网关自动维持的,不会持续下去,如果连接断开或者网络不稳定都会导致通信失败,这时内网主机需要自动重连机制了。

安装:

yum install autossh

实例:

autossh -M 9090 -fCNR 18081:10.10.3.x:8080 root@x.x.x.x

autossh -M 9091 -fCNR 18082:10.10.3.x:80 root@x.x.x.x

autossh -M 9091 -fCNR 18083:127.0.0.1:80 root@x.x.x.x

这样将在'x.x.x.x'主机上开启一个本地侦听地址:18081,访问本地18081将转发至10.10.3.x:8080

-M 9090参数,负责通过9090端口监视连接状态,连接有问题时就会自动重连。
-M 是服务器echo机制使用的端口。

autossh -M 5678 -CqTfnN -D 192.168.0.2:7070 freeoa@remote-host

参数解释:

-M为autossh参数, -CqTfnN -D 为ssh参数

-M 5678 : 负责通过5678端口监视连接状态,连接有问题时就会自动重连

-C :启动数据压缩传输

-q :安静模式运行,忽略提示和错误

-T :不占用shell

-f :后台运行

-n :配合 -f 参数使用

-N :不执行远程命令,专为端口转发度身打造

-D 192.168.0.2:7070 :指定一个本地机器 “动态的“ 应用程序端口转发,如果不加IP地址,默认只监听127.0.0.1

使用场景:

场景:A是内网服务器192.168.1.10(内部多次nat,无法使用公网IP),B是内网用户转发代理服务器192.168.1.12,C是公网服务器x.x.x.x,D是用户PC

需求:D访问A内网服务器web 8080

方法:
1.B安装autossh

2.B执行autossh -M 9091 -fCNR 18080:192.168.1.10:8080 root@x.x.x.x

3.设置B可以无密码登陆C

4.D上打开putty,设置正向代理,点击Add,save保存

5.D上打开浏览器:http://127.0.0.1:18080 ,访问到内网A服务器web应用

补充:

注意几个参数:

AUTOSSH_MAXLIFETIME:
Sets the maximum number of seconds the process should live for before killing off the ssh child and exiting.
AUTOSSH_POLL:
poll time in seconds; default is 600.
在实际应用中,发现每隔10分钟,会断线重连,这对应用造成很大影响。

使用AUTOSSH_MAXLIFETIME参数设定转发存活时间,在这个时间内不会断,但是时间到后,会kill掉进程,无法重连。

使用AUTOSSH_POLL,可以指定多长时间断线重连,官网原话,实际上没看懂,希望理解的同道指点。

AUTOSSH_POLL - poll time in seconds; default is 600.
Changing this will also change the first
poll time, unless AUTOSSH_FIRST_POLL is
used to set it to something different.
If the poll time is less than twice the
network timeouts (default 15 seconds) the
network timeouts will be adjusted downward
to 1/2 the poll time.
在实际中,使用这个参数,依然无法解决我的问题,authossh实际上是调用ssh,可以再加上 -o TCPKeepAlive=yes -o ServerAliveInterval=30 ,解决频繁断线问题。

一个例子:

autossh -M 9098 -CNR x.x.x.x:443:10.x.x.x:443 root@x.x.x.x -f AUTOSSH_POLL 86400 -o TCPKeepAlive=yes -o ServerAliveInterval=30