专题:OpenSSH tunneling
SSH tunneling 相关
参考資料:http://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/
本地端口转发:
- 适用场景:发起端可以连接 SSH_server_host 端的 ssh 服务,但无法与最终目标 goal_host 的程序直接通信,而 SSH_server_host 可以
- 命令格式:ssh [-g] -L <local_port>:<goal_host>:<goal_port> username@<SSH_server_host>
- local_port:最初发起连接的主机端口号
- goal_host:最终目标主机的 IP 或 主机名,可以与 SSH_server_host 为同一台机器(此时 goal_host 通常设置为 localhost 或 127.0.0.1)
- goal_port:最终目标主机的端口号
- SSH_server_host:负責 SSH 转发的中间主机
- -g:此选项允许其它主机远程连接至第一台主机的 local_port 端口上,相当于进一步増加通信节点
远程端口转发:
- 适用场景:发起端无法连接 SSH_server_host 端的 ssh 服务(如:发起端是外网主机,但 SSH_server_host 是 nat 之后的内网主机),但反向连接是允许的,而且 SSH_server_host 可以与最终目标 goal_host 上的程序直接通信
- 命令格式:ssh [-g] -R <remote_port>:<goal_host>:<goal_port> username@<SSH_server_host>
- remote_host:最初发起连接的主机端口号,此处的 remote 是相对 SSH_server_host 而言的,因为这个操作需要在 SSH_server_host 上完成
- goal_host:最终目标主机的 IP 或 主机名,可以是操作此命令的本机
- goal_port:最终目标主机的端口号
- SSH_server_host:此处指 最初发起连接的主机 IP 或 主机名,因为此时的 ssh 连接是由中间主机发出的,最初的主机允当 ssh 服务器的角色
目标主机:
/*C 语言版*/
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h> int
main(void) {
daemon(0, 0);
char *Argv[] = {"ssh", "-2", "-N", "-R", "9527:localhost:22", "fh@fanhui.f3322.net", NULL};
pid_t Pid;
Label:Pid = fork();
if (Pid == ) {
execvp("ssh", Argv);
}
else if(Pid > ) {
waitpid(Pid, NULL, );
goto Label;
}
else {
exit();
}
}
#!/bin/bash
#dynamic domain name: fanhui.f3322.net
#URL: http://www.pubyun.com http://www.3322.net Keep_Alive() {
Ops="ssh -2 -N -f -R 9527:localhost:22 fh@fanhui.f3322.net"
#仅使用第二版 ssh 协议(-2),建立转发遂道但不登陆控制台(-N),强制后台运行从而取消占用控制台(-f)
while :
do
count=$(ps ax | grep -c $Ops)
if [[ $count -lt ]]
then
su fh -c $Ops
fi
sleep 300s
done
} Keep_Alive
云端( SSH 中转站):
#!/bin/bash
GetIp="http://members.3322.org/dyndns/getip"
while :
do
lynx -mime_header -auth=kitex:aibbigql "http://members.3322.net/dyndns/update?system=dyndns&hostname=fanhui.f3322.net" >/dev/null
Ip_0=$(curl $GetIp)
sleep 600s
Ip_1=$(curl $GetIp) while [[ $Ip_1 -eq $Ip_0 ]]
do
sleep 600s
Ip_1=$(curl $GetIp)
done done
专题:OpenSSH tunneling的更多相关文章
- 开源服务专题之------sshd服务安装管理及配置文件理解和安全调优
本专题我将讨论一下开源服务,随着开源社区的日趋丰富,开源软件.开源服务,已经成为人类的一种公共资源,发展势头可谓一日千里,所以不可不知.SSHD服务,在我们的linux服务器上经常用到,很重要,涉及到 ...
- RHEL5.8设置OpenSSH的X11 Forwarding功能
X11的Forwarding功能需要在SSH中进行设置,RedHat Enterprise Linux5.8默认使用的而是OpenSSH,现将设置方法记录如下: OpenSSH配置文件路径: /etc ...
- openssh
http://www.openssh.com/ OpenSSH is a FREE version of the SSH connectivity tools that technical users ...
- 升级openssh基于openssl
OpenSSH is the premier connectivity tool for remote login with the SSH protocol. It encrypts all tra ...
- 在windows中安装OpenSSH,无密码登录,永远不断线
到这里下载最新安装包:https://github.com/PowerShell/Win32-OpenSSH/releases下载下来解压,然后用管理员打开服务器自带的PowerShell,运行下列命 ...
- How to do SSH Tunneling (Port Forwarding)
How to do SSH Tunneling (Port Forwarding) In this post we will see how ssh works?, what is SSH tunne ...
- 2016年中国微信小程序专题研究报告
2016年12月29日,全球领先的移动互联网第三方数据挖掘和分析机构iiMedia Research(艾媒咨询)权威首发<2016年中国微信小程序专题研究报告>. 报告显示,82.6%手机 ...
- [.NET领域驱动设计实战系列]专题二:结合领域驱动设计的面向服务架构来搭建网上书店
一.前言 在前面专题一中,我已经介绍了我写这系列文章的初衷了.由于dax.net中的DDD框架和Byteart Retail案例并没有对其形成过程做一步步分析,而是把整个DDD的实现案例展现给我们,这 ...
- Ubantu【第一篇】:Ubantu中openssh连接
h3 { color: rgb(255, 255, 255); background-color: rgb(30,144,255); padding: 3px; margin: 10px 0px } ...
随机推荐
- Install Apache 2.2.15, MySQL 5.5.34 & PHP 5.5.4 on RHEL/CentOS 6.4/5.9 & Fedora 19-12 [转]
Step 1: Installing Remi Repository ## Install Remi Repository on Fedora , , , , ## rpm -Uvh http://d ...
- 【转】理解JMX之介绍和简单使用
原文链接:https://blog.csdn.net/lmy86263/article/details/71037316 近期在项目上需要添加一些功能,想把一个开源工程整合进来,虽说是整合,但是觉得跟 ...
- LOJ #103. 子串查找 (Hash)
题意 给定两个字符串 \(A\) 和 \(B\),求 \(B\) 在 \(A\) 中的出现次数. 思路 这是一道 \(KMP\) 的模板题. 不过 \(Hash\) 是个好东西,可以用 \(Hash\ ...
- ROW_NUMBER() over(order by ID desc ) as RowNumber 返回类型问题
因为ID是int类型,所以ROW_NUMBER() over(order by ID desc ) as RowNumber 想当然的认为是Int类型 实际ROW_NUMBER() over(orde ...
- IOU计算python实现
def compute_iou(rec1, rec2): """ computing IoU :param rec1: (y0, x0, y1, x1), which r ...
- Django Model里的__str__以及Meta
举个栗子,注释已经比较详细了 name = models.CharField(max_length=30,verbose_name='标签名称') #max_length=30里的30在mysql以前 ...
- PAT(A) 1042. Shuffling Machine (20)
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...
- __name__ 与 __main__解读
在python脚本中我们经常看到如下的代码: # hello.py def hello(): print("hello world!") def test(): hello() i ...
- tooltip(提示框)组件
一.class加载方式 <span id="pos" class="easyui-tooltip" title="这是提示内容"> ...
- Android开发——回调(Callback)
1. 回调函数的定义: 在A类中定义了一个方法,这个方法中用到了一个接口和该接口中的抽象方法,但是抽象方法没有具体的实现,需要B类去实现,B类实现该方法后,它本身不会去调用该方法,而是传递给A类,供A ...