如何在Linux中配置SSH端口转发(隧道)

时间:2020-02-23 14:40:31  来源:igfitidea点击:

在本教程指南中,我们将学习

  • SSH端口转发

  • 不同类型的转发

  • 创建SSH隧道和访问HTTP Web服务器的实际示例

  • 使用tcpdump验证SSH隧道

  • 关闭SSH隧道

什么是SSH端口转发

  • SSH端口转发或者隧道允许我们在本地"安全SSH隧道"中将不安全的TCP流量从本地转发到目标服务器。

  • 诸如FTP,POP3,SMTP,HTTP,TELNET等协议都可以在此SSH隧道内转发

  • 这将提供增强的安全功能,例如加密和身份验证,否则可能无法支持。

  • 我们必须"创建新的SSH连接以建立隧道",不能使用任何现有的SSH连接

SSH端口转发的类型?

本地主机和远程主机之间存在三种类型的端口转发机制:

  • 本地端口转发:创建连接到远程服务的本地端口。

  • 远程端口转发:将Internet上远程服务器上的端口转发到本地端口

  • "动态端口转发:" SOCKS客户端通过TCP连接,并通过协议指示它要访问的远程套接字

1:本地端口转发

  • 这允许我们将端口从本地服务器(ssh_client)转发到目标远程服务器(ssh_server)的端口。

  • 基本的语法是ssh -L sourceHost:sourcePort:forwardToHost:onPort connectToHost`

  • 其中" firstHost"的" sourceHost"将是本地主机,我们将在该本地主机上启用端口转发

  • 第二个字段是sourcePort,通过它我们可以连接到remotehost和remotePort。

  • 第三个字段是" forwardToHost",即我们要将请求转发到的服务器。
    我们也可以将localhost放在此字段中(因为它是remoteHost的本地主机)

  • 第四个字段是onPort部分,即请求必须转发到的端口

  • 最后提供我们要在其上创建安全SSH隧道的服务器(connectToHost)

在SSH的手册页中:

-f	Requests ssh to go to background just before command execution. 
-N      Do not execute a remote command.  This is useful for just forwarding ports
-L local_socket:remote_socket
       Specifies that connections to the given TCP port or Unix socket on the local (client) host are to be forwarded to the
       given host and port, or Unix socket, on the remote side.  This works by allocating a socket to listen to either a TCP
       port on the local side, optionally bound to the specified bind_address, or to a Unix socket.  Whenever a connection is
       made to the local port or socket, the connection is forwarded over the secure channel, and a connection is made to
       either host port hostport, or the Unix socket remote_socket, from the remote machine.

1.1:具有两台服务器的本地端口转发

  • 这是最常用的基本端口转发,我们将端口" 5555"上的流量从本地主机(" server1")转发到目标主机" server3"上的端口" 80"。

  • 在这个例子中,我有一个Web服务器在server3的port 80上运行。

  • 我将配置端口" 5555"以将来自本地主机(" server1")的流量转发到"安全SSH隧道"中"端口80"上的" server3"。

1.1.1:为HTTP服务器创建SSH隧道

server1(我们的本地主机)上使用SSH客户端创建通往server3的安全隧道。
-L选项指定本地转发,其中TCP客户端与SSH客户端位于本地计算机上。

[root@server1 ~]# ssh -f -N -L localhost:5555:server3:80 root@server3

提示:

我们也可以使用ssh -f -N -L 5555:localhost:80 root @ server3建立SSH隧道,但这会使初学者感到困惑,因此我们将按规则保留它。
理想情况下,第三个字段" localhost"被认为是在" server3"上调用的,因此我们可以使用其中一个

确保SSH进程仍处于活动状态:

[root@server1 ~]# ps -ef | grep ssh
root      1170     1  0 10:20 ?        00:00:00 /usr/sbin/sshd -D
root      1426  1170  0 10:21 ?        00:00:01 sshd: root@pts/1
root      2242  1170  0 12:31 ?        00:00:00 sshd: root@pts/0
root      2384     1  0 12:53 ?        00:00:00 ssh -f -N -L localhost:5555:server3:80 root@server3
root      2386  1430  0 12:53 pts/1    00:00:00 grep --color=auto ssh

1.1.2:验证SSH隧道

接下来,我们将尝试使用curl连接到server3上的apache服务器,并且curl能够使用server1:5555连接到server3:80

[root@server1 ~]# curl  http://localhost:5555
My test site

可以从在server3上运行的tcpdump收集更多信息。
这表明即使请求的端口为80,curl请求还是使用SSH安全隧道服务的

[root@server3 ~]# tcpdump -i enp0s8 port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
12:53:28.032073 IP server1.53464 > server3.ssh: Flags [P.], seq 29797146:29797230, ack 547702480, win 329, options [nop,no,TS val 8905005 ecr 8902932], length 84
12:53:28.032108 IP server3.ssh > server1.53464: Flags [.], ack 84, win 295, options [nop,nop,TS val 8909252 ecr 8905005], ength 0
12:53:28.032430 IP server3.ssh > server1.53464: Flags [P.], seq 1:45, ack 84, win 295, options [nop,nop,TS val 8909253 ecr8905005], length 44
12:53:28.032854 IP server1.53464 > server3.ssh: Flags [P.], seq 84:200, ack 45, win 329, options [nop,nop,TS val 8905006 er 8909253], length 116
12:53:28.033570 IP server3.ssh > server1.53464: Flags [P.], seq 45:337, ack 200, win 295, options [nop,nop,TS val 8909254 cr 8905006], length 292
12:53:28.044939 IP server1.53464 > server3.ssh: Flags [P.], seq 200:236, ack 337, win 349, options [nop,nop,TS val 8905018ecr 8909254], length 36
12:53:28.045130 IP server3.ssh > server1.53464: Flags [P.], seq 337:409, ack 236, win 295, options [nop,nop,TS val 8909265ecr 8905018], length 72
12:53:28.045599 IP server1.53464 > server3.ssh: Flags [P.], seq 236:272, ack 409, win 349, options [nop,nop,TS val 8905019ecr 8909265], length 36
12:53:28.085911 IP server3.ssh > server1.53464: Flags [.], ack 272, win 295, options [nop,nop,TS val 8909306 ecr 8905019],length 0

1.1.3:关闭本地转发隧道

要关闭安全的SSH隧道,我们必须终止为转发PORT而创建的SSH进程。

[root@server1 ~]# kill -9 2384

1.2:具有三台服务器的本地端口转发

在此示例中,我们将有三台服务器。
这里的server1没有直接访问server3的权限,因此它将使用server1server2连接到server3上的网络服务器。

我们将使用安全的SSH隧道将端口请求从server1:5555转发到server2,这将进一步连接server3:80来获取请求。

1.2.1:创建SSH隧道

使用SSH客户端在本地主机(server1)上创建本地转发端口。
我们也可以在此命令中忽略提及localhost,因为这是默认行为,我其中只是为了解释而写

[root@server1 ~]# ssh -f -N -L localhost:5555:server3:80 root@server2

确保SSH进程处于活动状态,这意味着我们的"隧道已创建"

[root@server1 ~]# ps -ef | grep ssh
root      1170     1  0 10:20 ?        00:00:00 /usr/sbin/sshd -D
root      1426  1170  0 10:21 ?        00:00:01 sshd: root@pts/1
root      2242  1170  0 12:31 ?        00:00:00 sshd: root@pts/0
root      2380     1  0 12:51 ?        00:00:00 ssh -f -N -L localhost:5555:server3:80 root@server2
root      2382  1430  0 12:51 pts/1    00:00:00 grep --color=auto ssh

1.2.2:验证SSH隧道

我们将使用curl通过localhost:5555server1连接到server3:80上的网络服务器。
因此curl工具可以成功获取Web服务器的索引页。

[root@server1 ~]# curl  http://localhost:5555
My test site

我们可以检查server3上的tcpdump捕获,这表明server1和server2之间的安全隧道通信,并且进一步的server2将连接到server3以连接到网络服务器。

[root@server3 tmp]# tcpdump -i enp0s8 port 22 or 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
12:59:04.138042 IP server1.60638 > server2.ssh: Flags [P.], seq 2758738467:2758738551, ack 379740010, win 289, options [nop,nop,TS val 9241111 ecr 5849726], length 84
12:59:04.138269 IP server2.ssh > server1.60638: Flags [.], ack 84, win 273, options [nop,nop,TS val 5891823 ecr 9241111], length 0
12:59:04.144056 IP server2.53650 > server3.http: Flags [S], seq 2208701817, win 29200, options [mss 1460,sackOK,TS val 5891829 ecr 0,nop,wscale 7], length 0
12:59:04.144073 IP server3.http > server2.53650: Flags [S.], seq 2805768777, ack 2208701818, win 28960, options [mss 1460,sackOK,TS val 9245364 ecr 5891829,nop,wscale 7], length 0
12:59:04.148666 IP server2.53650 > server3.http: Flags [.], ack 1, win 229, options [nop,nop,TS val 5891833 ecr 9245364], length 0
12:59:04.148672 IP server2.ssh > server1.60638: Flags [P.], seq 1:45, ack 84, win 273, options [nop,nop,TS val 5891834 ecr 9241111], length 44
12:59:04.148790 IP server1.60638 > server2.ssh: Flags [.], ack 45, win 289, options [nop,nop,TS val 9241122 ecr 5891834], length 0
12:59:04.148917 IP server1.60638 > server2.ssh: Flags [P.], seq 84:200, ack 45, win 289, options [nop,nop,TS val 9241122 ecr 5891834], length 116
12:59:04.149100 IP server2.53650 > server3.http: Flags [P.], seq 1:79, ack 1, win 229, options [nop,nop,TS val 5891834 ecr 9245364], length 78: HTTP: GET/HTTP/1.1
12:59:04.149118 IP server3.http > server2.53650: Flags [.], ack 79, win 227, options [nop,nop,TS val 9245370 ecr 5891834], length 0
12:59:04.149546 IP server3.http > server2.53650: Flags [P.], seq 1:254, ack 79, win 227, options [nop,nop,TS val 9245370 ecr 5891834], length 253: HTTP: HTTP/1.1 200 OK

1.2.3:关闭本地转发隧道

要关闭安全的SSH隧道,请继续并终止我们之前创建的相应SSH进程:

[root@server1 ~]# kill -9  2380

1.3:具有网关端口的本地端口转发

  • 默认情况下,在OpenSSH中,只有运行SSH客户端的主机才能连接到本地转发的端口。

  • 这是因为ssh仅在计算机的环回接口上侦听与转发端口的连接;也就是说,它绑定套接字(localhost,5555),又名(127.0.0.1,5555)而不是(server1,8080)。

  • 因此,在前面的示例中,只有server1可以使用转发功能。

  • 但是,用于OpenSSH的ssh有一个命令行选项-g禁用此限制,允许任何主机连接到本地转发的端口:

  • 客户端配置(ssh_config)关键字GatewayPorts也可以控制此功能。
    默认值为no,而yes与-g相同。

1.3.1:使用网关端口创建SSH隧道

我们还将在现有的SSH命令中使用-g来创建SSH隧道。
另外,如果我们观察到的话,我已经删除了locahost并使用了:5555表示可以匹配所有主机

[root@server1 ~]# ssh -g -f -N -L :5555:server3:80 root@server3

确保相应命令的SSH进程仍处于活动状态:

[root@server1 ~]# ps -ef | grep ssh
root      1170     1  0 10:20 ?        00:00:00 /usr/sbin/sshd -D
root      1426  1170  0 10:21 ?        00:00:01 sshd: root@pts/1
root      2242  1170  0 12:31 ?        00:00:00 sshd: root@pts/0
root      2423     1  0 13:01 ?        00:00:00 ssh -g -f -N -L :5555:server3:80 root@server3
root      2425  1430  0 13:03 pts/1    00:00:00 grep --color=auto ssh

1.3.2:验证本地端口转发

这次我们将使用来自server2的curl命令,以检查它是否可以通过安全隧道中的端口5555连接到server3.

[root@server2 ~]# curl http://server1:5555
My test site

因此,server2能够通过转发端口server1:5555成功连接至server3:80以及网络服务器。

来自server3的tcpdump输出表明,在server1和server3之间使用安全隧道建立了连接以获取HTTP请求。
我们可以扩展" tcpdump"来搜索主机" server2",以从各个主机获取数据包详细信息。
由于隧道仅位于" server1"和" server3"之间,因此其中我们看不到" server2"的相关详细信息。

[root@server3 tmp]# tcpdump -i enp0s8 port 22 or 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
13:01:40.344612 IP server1.53480 > server3.ssh: Flags [P.], seq 2488865116:2488865208, ack 1385274191, win 309, options [nop,nop,TS val 9397318 ecr 9390459], length 92
13:01:40.344639 IP server3.ssh > server1.53480: Flags [.], ack 92, win 295, options [nop,nop,TS val 9401565 ecr 9397318], length 0
13:01:40.346140 IP server3.ssh > server1.53480: Flags [P.], seq 1:45, ack 92, win 295, options [nop,nop,TS val 9401566 ecr 9397318], length 44
13:01:40.346422 IP server1.53480 > server3.ssh: Flags [.], ack 45, win 309, options [nop,nop,TS val 9397320 ecr 9401566], length 0
13:01:40.346507 IP server1.53480 > server3.ssh: Flags [P.], seq 92:208, ack 45, win 309, options [nop,nop,TS val 9397320 ecr 9401566], length 116
13:01:40.347088 IP server3.ssh > server1.53480: Flags [P.], seq 45:337, ack 208, win 295, options [nop,nop,TS val 9401567 ecr 9397320], length 292
13:01:40.347943 IP server1.53480 > server3.ssh: Flags [P.], seq 208:244, ack 337, win 329, options [nop,nop,TS val 9397321 ecr 9401567], length 36
13:01:40.348239 IP server3.ssh > server1.53480: Flags [P.], seq 337:409, ack 244, win 295, options [nop,nop,TS val 9401569 ecr 9397321], length 72
13:01:40.348453 IP server1.53480 > server3.ssh: Flags [P.], seq 244:280, ack 409, win 329, options [nop,nop,TS val 9397322 ecr 9401569], length 36
13:01:40.389600 IP server3.ssh > server1.53480: Flags [.], ack 280, win 295, options [nop,nop,TS val 9401610 ecr 9397322], length 0

1.3.3:关闭SSH隧道

关闭SSH隧道要关闭本地转发端口,我们可以继续执行前面创建的SSH进程,以从" server1"启动隧道。

[root@server1 ~]# kill -9 2423

2:远程端口转发

  • 远程转发的端口就像本地端口一样,但是方向相反。

  • 这次,TCP客户端是远程的,它的服务器是本地的,并且从远程计算机启动了转发的连接。

  • 远程端口转发不太常见,可用于连接到Internet上无法访问的本地端口,以及连接到Internet上可用的服务器上的端口。

  • -R选项指定远程转发。
    它后面是三个值,与以前一样用冒号分隔,但解释略有不同。

从SSH的手册页

-R [bind_address:]port:host:hostport
-R [bind_address:]port:local_socket
-R remote_socket:host:hostport
-R remote_socket:local_socket
             Specifies that connections to the given TCP port or Unix socket on the remote (server) host are to be
             forwarded to the given host and port, or Unix socket, on the local side.  This works by allocating a
             socket to listen to either a TCP port or to a Unix socket on the remote side.  Whenever a connection is
             made to this port or Unix socket, the connection is forwarded over the secure channel, and a connection
             is made to either host port hostport, or local_socket, from the local machine.

执行反向端口转发的语法是ssh -R bindAddress:remotePort:forwardToHost:onPort connectToHost

  • "第一个字段"是本地主机上的绑定地址。
    默认情况下,服务器上的TCP侦听套接字将仅绑定到回送接口

  • 第二个字段是remotePort,它将用于连接到目标端口,即80。

  • 第三个字段用于forwardToHost,即我们希望在转发过程中连接到的服务器的主机名或者IP

  • "第四字段"是" onPort",在forwardToHost上转发应该转发到的" onPort"

  • 最后,"提供要向其创建SSH隧道的服务器详细信息"

2.1:创建用于远程端口转发的SSH隧道

我有一个Web服务器,其Apache在server3上运行的端口80上。
现在在前面的示例中:

使用"本地端口转发",我们将请求从" server1:5555"转发到" server3:80"

现在我们做相反的事情,即

使用"远程端口转发",我们将请求从" server3:80"转发到" server1:5555"

server3上创建SSH隧道

[root@server3 ~]# ssh -f -N -R localhost:5555:server3:80 root@server1

确保使用上述命令的SSH进程仍在运行

[root@server3 ~]# ps -ef | grep ssh
root      5711     1  0 10:22 ?        00:00:01 sshd: root@pts/0
root      9500     1  0 11:10 ?        00:00:00 /usr/sbin/sshd -D
root     11151  9500  0 12:09 ?        00:00:00 sshd: root@notty
root     13638     1  0 15:46 ?        00:00:00 ssh -f -N -R 5555:server3:80 root@server1
root     13642  5799  0 15:46 pts/0    00:00:00 grep --color=auto ssh

2.2:验证SSH隧道设置

验证SSH隧道接下来,我们将使用来自server1的curl通过端口5555连接到server3

[root@server1 ~]# curl  http://localhost:5555
My test site

连接成功

通过在server3上运行tcpdump,我们可以检查从server1到server3的curl请求是否使用了安全的SSH隧道。

[root@server3 ~]# tcpdump -i enp0s8 port 22 or 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
15:48:05.749405 IP server1.ssh > server3.48228: Flags [P.], seq 3747952798:3747952890, ack 3457506699, win 258, options [nop,nop,TS val 19382722 ecr 19296856], length 92
15:48:05.749429 IP server3.48228 > server1.ssh: Flags [.], ack 92, win 291, options [nop,nop,TS val 19386970 ecr 19382722], length 0
15:48:05.750020 IP server3.48228 > server1.ssh: Flags [P.], seq 1:45, ack 92, win 291, options [nop,nop,TS val 19386970 ecr 19382722], length 44
15:48:05.750314 IP server1.ssh > server3.48228: Flags [.], ack 45, win 258, options [nop,nop,TS val 19382723 ecr 19386970], length 0
15:48:05.750506 IP server1.ssh > server3.48228: Flags [P.], seq 92:208, ack 45, win 258, options [nop,nop,TS val 19382724 ecr 19386970], length 116
15:48:05.751491 IP server3.48228 > server1.ssh: Flags [P.], seq 45:337, ack 208, win 291, options [nop,nop,TS val 19386972 ecr 19382724], length 292
15:48:05.752605 IP server1.ssh > server3.48228: Flags [P.], seq 208:244, ack 337, win 281, options [nop,nop,TS val 19382726 ecr 19386972], length 36
15:48:05.752926 IP server3.48228 > server1.ssh: Flags [P.], seq 337:409, ack 244, win 291, options [nop,nop,TS val 19386973 ecr 19382726], length 72
15:48:05.753338 IP server1.ssh > server3.48228: Flags [P.], seq 244:280, ack 409, win 281, options [nop,nop,TS val 19382727 ecr 19386973], length 36
15:48:05.793709 IP server3.48228 > server1.ssh: Flags [.], ack 280, win 291, options [nop,nop,TS val 19387014 ecr 19382727], length 0

2.3:关闭SSH隧道

要关闭SSH隧道,我们必须终止在server3上运行的SSH进程。

[root@server3 ~]# ps -ef | grep 5555
root     13638     1  0 15:46 ?        00:00:00 ssh -f -N -R 5555:server3:80 root@server1

映射到SSH隧道的PID是13638,对于相应的PID,我们将使用带有-9中断信号的kill

[root@server3 ~]# kill -9 13638

3:动态端口转发

  • 假设我们需要一种快速的方法"绕过防火墙设置退出网络"。

  • 我们的server1通常可以访问在server3上运行的HTTP服务器。

  • 但是由于最近的防火墙政策,我们可以访问server3主机来访问Web服务器

  • 为了克服这个问题,我们可以使用"动态端口转发"或者" SOCKS转发"。
    SOCKS是一个小的协议,在RFC-1928中定义。

  • SOCKS客户端通过TCP连接,并通过协议指示它要访问的远程套接字。
    SOCKS服务器建立连接,然后摆脱干扰,透明地来回传递数据。

  • 此后,就好像客户端已直接连接到远程套接字。

从SSH的手册页

-D [bind_address:]port
             Specifies a local “dynamic” application-level port forwarding.  This works by allocating a socket to lis‐
             ten to port on the local side, optionally bound to the specified bind_address.  Whenever a connection is
             made to this port, the connection is forwarded over the secure channel, and the application protocol is
             then used to determine where to connect to from the remote machine.  Currently the SOCKS4 and SOCKS5 pro‐
             tocols are supported, and ssh will act as a SOCKS server.  Only root can forward privileged ports.
             Dynamic port forwardings can also be specified in the configuration file.

使用动态端口转发的语法是:

ssh -f -N -D [bind_address:]port connectToHost
  • 这里在"第一字段"中,无需显式提及" bind_address",只需在"第二字段"中提供要转发的"本地端口"即可。

  • 这是因为"目的地"是动态确定的,并且每个连接都可以不同。

  • 将" connectToHost"替换为要为其创建安全隧道的服务器

3.1:创建SSH隧道

在我们创建SSH隧道之前,让我向我们展示默认情况下允许使用端口80连接到server3上的apache服务器的server1.

[root@server1 ~]# curl http://server3:80
My test site

但是接下来我们引入iptables规则来阻塞server1上的OUTPUT链中的端口80。

[root@server1 ~]# iptables -A OUTPUT -p tcp --dport 80 -j DROP

现在,如果我们尝试从server3访问apache服务器,curl将在试图建立连接时timeout超时。

[root@server1 ~]# curl --connect-timeout 5 http://server3:80
curl: (28) Connection timed out after 5000 milliseconds

因此,我们使用随机端口" 8080"创建了从" server1"到" server3"的动态端口转发SSH隧道。
我们可以选择任何其他端口。

[root@server1 ~]# ssh -f -N -D 8080 root@server3

通过此命令验证SSH进程

[root@server1 ~]# ps -ef | grep ssh
root      1170     1  0 10:20 ?        00:00:00 /usr/sbin/sshd -D
root      1426  1170  0 10:21 ?        00:00:01 sshd: root@pts/1
root      2242  1170  0 12:31 ?        00:00:00 sshd: root@pts/0
root      2611     1  0 16:24 ?        00:00:00 ssh -f -N -D 8080 root@server3
root      2613  1430  0 16:25 pts/1    00:00:00 grep --color=auto ssh

3.2:验证SSH隧道设置

验证SSH隧道设置现在,我们将尝试使用SOCKS代理使用server1:8080从server3:80连接到apache服务器。

[root@server1 ~]# curl --proxy socks5h://localhost:8080  http://server3:80
My test site

使用SOCKS代理成功完成curl连接

在server3上的tcpdump输出显示卷曲连接发生在端口22上的安全SSH隧道内

[root@server3 ~]# tcpdump -i enp0s8 port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
16:27:04.659233 IP server1.53544 > server3.ssh: Flags [P.], seq 2051346850:2051346934, ack 679515067, win 349, options [nop,nop,TS val 21721632 ecr 21664654], length 84
16:27:04.659249 IP server3.ssh > server1.53544: Flags [.], ack 84, win 295, options [nop,nop,TS val 21725880 ecr 21721632], length 0
16:27:04.659651 IP server3.ssh > server1.53544: Flags [P.], seq 1:45, ack 84, win 295, options [nop,nop,TS val 21725880 ecr 21721632], length 44
16:27:04.660067 IP server1.53544 > server3.ssh: Flags [P.], seq 84:192, ack 45, win 349, options [nop,nop,TS val 21721633 ecr 21725880], length 108
16:27:04.660454 IP server3.ssh > server1.53544: Flags [P.], seq 45:337, ack 192, win 295, options [nop,nop,TS val 21725881 ecr 21721633], length 292
16:27:04.661356 IP server1.53544 > server3.ssh: Flags [P.], seq 192:228, ack 337, win 369, options [nop,nop,TS val 21721634 ecr 21725881], length 36
16:27:04.661590 IP server3.ssh > server1.53544: Flags [P.], seq 337:409, ack 228, win 295, options [nop,nop,TS val 21725882 ecr 21721634], length 72
16:27:04.661957 IP server1.53544 > server3.ssh: Flags [P.], seq 228:264, ack 409, win 369, options [nop,nop,TS val 21721635 ecr 21725882], length 36
16:27:04.702875 IP server3.ssh > server1.53544: Flags [.], ack 264, win 295, options [nop,nop,TS val 21725923 ecr 21721635], length 0

我们还可以通过修改"网络设置"下的代理配置,将Mozilla Firefox配置为使用SOCKS代理。

3.3:关闭SSH隧道

要关闭动态端口转发SSH隧道,我们必须终止先前在server1上创建的SSH进程。

[root@server1 ~]# ps -ef | grep ssh
root      2611     1  0 16:24 ?        00:00:00 ssh -f -N -D 8080 root@server3
root      2613  1430  0 16:25 pts/1    00:00:00 grep --color=auto ssh

在这种情况下,请终止进程PID 2611以关闭隧道

[root@server1 ~]# kill -9 2611