ssh tunneling

主要使用了ssh隧道技术:

经常隧道会自动断开的原因:隧道可能因为某些原因断开,例如:机器重启,长时间没有数据通信而被路由器切断等等。

OpenSSH基于安全的理由,如果用户连线到SSH Server后闲置一段时间,SSH Server会在超过特定时间后自动终止SSH连线。

保持长连接,我们需要了解这几个参数:

TCPKeepAlive yes/no for ssh and sshd

ClientAliveCountMax for sshd

ClientAliveInterval for sshd

ServerAliveCountMax for ssh

ServerAliveInterval for ssh

To enable the keep alive system-wide (root access required), edit /etc/ssh/ssh_config; to set the settings for just your user, edit ~/.ssh/config (create the file if it doesn’t exist). Insert the following:

Host *

ServerAliveInterval 300

ServerAliveCountMax 2

You can also make your OpenSSH server keep alive all connections with clients by adding the following to /etc/ssh/sshd_config:

ClientAliveInterval 300

ClientAliveCountMax 2

connection idle timeout setting

ServerAliveCountMax

Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session. It is important to note that the use of server alive messages is very different from TCPKeepAlive (below). The server alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The server alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive.

The default value is 3. If, for example, ServerAliveInterval (see below) is set to 15 and ServerAliveCountMax is left at the default, if the server becomes unresponsive, ssh will disconnect after approximately 45 seconds. This option applies to protocol version 2 only; in protocol version 1 there is no mechanism to request a response from the server to the server alive messages, so disconnection is the responsibility of the TCP stack.

ServerAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server, or 300 if the BatchMode option is set. This option applies to protocol version 2 only. ProtocolKeepAlives and SetupTimeOut are Debian-specific compatibility aliases for this option.

下面是几个参数的解释:

TCPKeepAlive
             Specifies whether the system should send TCP keepalive messages
             to the other side.  If they are sent, death of the connection or
             crash of one of the machines will be properly noticed.  However,
             this means that connections will die if the route is down tem-
             porarily, and some people find it annoying.  On the other hand,
             if TCP keepalives are not sent, sessions may hang indefinitely on
             the server, leaving “ghost” users and consuming server resources.

             The default is “yes” (to send TCP keepalive messages), and the
             server will notice if the network goes down or the client host
             crashes.  This avoids infinitely hanging sessions.

             To disable TCP keepalive messages, the value should be set to
             “no”.
 ClientAliveCountMax
             Sets the number of client alive messages (see below) which may be
             sent without sshd(8) receiving any messages back from the client.
             If this threshold is reached while client alive messages are
             being sent, sshd will disconnect the client, terminating the ses-
             sion.  It is important to note that the use of client alive mes-
             sages is very different from TCPKeepAlive (below).  The client
             alive messages are sent through the encrypted channel and there-
             fore will not be spoofable.  The TCP keepalive option enabled by
             TCPKeepAlive is spoofable.  The client alive mechanism is valu-
             able when the client or server depend on knowing when a connec-
             tion has become inactive.

             The default value is 3.  If ClientAliveInterval (see below) is
             set to 15, and ClientAliveCountMax is left at the default, unre-
             sponsive SSH clients will be disconnected after approximately 45
             seconds.  This option applies to protocol version 2 only.
 ClientAliveInterval
             Sets a timeout interval in seconds after which if no data has
             been received from the client, sshd(8) will send a message
             through the encrypted channel to request a response from the
             client.  The default is 0, indicating that these messages will
             not be sent to the client.  This option applies to protocol ver-
             sion 2 only.
 ServerAliveInterval
             Sets a timeout interval in seconds after which if no data has
             been received from the server, ssh(1) will send a message through
             the encrypted channel to request a response from the server.  The
             default is 0, indicating that these messages will not be sent to
             the server.  This option applies to protocol version 2 only.
 ServerAliveCountMax
             Sets the number of server alive messages (see below) which may be
             sent without ssh(1) receiving any messages back from the server.
             If this threshold is reached while server alive messages are
             being sent, ssh will disconnect from the server, terminating the
             session.  It is important to note that the use of server alive
             messages is very different from TCPKeepAlive (below).  The server
             alive messages are sent through the encrypted channel and there-
             fore will not be spoofable.  The TCP keepalive option enabled by
             TCPKeepAlive is spoofable.  The server alive mechanism is valu-
             able when the client or server depend on knowing when a connec-
             tion has become inactive.

             The default value is 3.  If, for example, ServerAliveInterval
             (see below) is set to 15 and ServerAliveCountMax is left at the
             default, if the server becomes unresponsive, ssh will disconnect
             after approximately 45 seconds.  This option applies to protocol
             version 2 only.

#!/bin/bash

###################################################################################

#date:2016-12-20                                                             ######

#author:victor                                                               ######

#description:                                                                ######

#this shell script is for improving the network performance to www.google.com######

###################################################################################

Ssh_Pid=`ps aux | grep ‘192.168.1.53‘| grep -v ‘grep‘| awk ‘{print $2}‘`

kill $Ssh_Pid

ssh -f -w 0:0 192.168.1.53 true

ifconfig tun0 192.168.100.2 netmask 255.255.255.252

ssh [email protected] "ifconfig tun0 192.168.100.1 netmask 255.255.255.252"

route add -host 192.168.1.53 dev eth0

route del -net 0.0.0.0

route add -net 0.0.0.0 dev tun0

时间: 2024-08-03 15:44:00

ssh tunneling的相关文章

How to do SSH Tunneling (Port Forwarding)

In this post we will see how ssh works?, what is SSH tunneling? what is important of ssh tunnels and how to setup the ssh tunnel.When SSH server is installed in machine then by default its allowed ssh tunneling. SSH Tunneling (Port Forwarding) Tunnel

SSH Tunneling Explained

Recently I wanted to set up a remote desktop sharing session from home pc to my laptop. While going through the set up guide I came across ssh tunneling. Even though there are many articles on the subject still it took me a considerable amount of goo

SSH原理与运用(二):远程操作与端口转发

本问转载自  http://www.ruanyifeng.com/blog/2011/12/ssh_port_forwarding.html SSH原理与运用(二):远程操作与端口转发 作者: 阮一峰 日期: 2011年12月23日 接着前一次的文章,继续介绍SSH的用法. ======================================= 作者:阮一峰 (Image credit: Tony Narlock) 七.远程操作 SSH不仅可以用于远程主机登录,还可以直接在远程主机上执行

VNC+SSH相关应用

1.安装vnc-server  vncviewer2.执行vncserver  输入密码3.执行vncserver -kill :1 杀死1号屏幕4.修改/root/.vnc/xstartup   unset SESSION_MANAGER   exec /etc/X11/xinit/xinitrc  去掉以上两行的注释 或者:/root/.vnc/xstartup,在最后一行会看到twm &,(不能去掉&)如果要运行KDE则将twm改成startkdeGnome则改成gnome-sess

ssh用法及命令

什么是SSH? 简单说,SSH是一种网络协议,用于 计算机之间的加密登录.如果一个用户从本地计算机,使用SSH协议登录另一台远程计算机,我们就可以认为,这种登录是安全的,即使被中途截获,密码也不会 泄露.最早的时候,互联网通信都是明文通信,一旦被截获,内容就暴露无疑.1995年,芬兰学者Tatu Ylonen设计了SSH协议,将登录信息全部加密,成为互联网安全的一个基本解决方案,迅速在全世界获得推广,目前已经成为Linux系统的标准配置.SSH只是一种协议,存在多种实现,既有商业实现,也有开源实

SSH原理与运用

SSH是每一台Linux电脑的标准配置. 随着Linux设备从电脑逐渐扩展到手机.外设和家用电器,SSH的使用范围也越来越广.不仅程序员离不开它,很多普通用户也每天使用. SSH具备多种功能,可以用于很多场合.有些事情,没有它就是办不成.本文是我的学习笔记,总结和解释了SSH的常见用法,希望对大家有用. 虽然本文内容只涉及初级应用,较为简单,但是需要读者具备最基本的"Shell知识"和了解"公钥加密"的概念.如果你对它们不熟悉,我推荐先阅读<UNIX / Li

Linux基本功杂记——[023]——「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> [email

ssh tunnel

https://peppoj.net/2012/10/tunnel-http-traffic-encrypted-using-polipo-and-ssh/ --------------------- Tunnel HTTP traffic encrypted, using Polipo and SSH SSH can be used to do allot of great things. Login remotely, transfer files with scp and run sing

[转帖]SSH原理与运用(二):远程操作与端口转发

SSH原理与运用(二):远程操作与端口转发 http://www.ruanyifeng.com/blog/2011/12/ssh_port_forwarding.html 接着前一次的文章,继续介绍SSH的用法. ======================================= SSH原理与运用(二):远程操作与端口转发 作者:阮一峰 (Image credit: Tony Narlock) 七.远程操作 SSH不仅可以用于远程主机登录,还可以直接在远程主机上执行操作. 上一节的操