本次实验做的工作如下图:
中间一台CentOS6通过SSH转发两边两台CentOS7的telnet通信。
-
首先,在右侧CentOS7上安装telnet服务
[root@Shining ~]# yum install -y telnet telnet-server
-
启动telnet服务
[root@Shining ~]# systemctl start telnet.socket
[root@Shining ~]# systemctl status telnet.socket
● telnet.socket – Telnet Server Activation Socket
Loaded: loaded (/usr/lib/systemd/system/telnet.socket; disabled; vendor preset: disabled)
Active: active (listening) since Sun 2016-12-04 10:57:10 CST; 20min ago
Docs: man:telnetd(8)
Listen: [::]:23 (Stream)
Accepted: 2; Connected: 1Dec 04 10:57:10 Shining.ACG systemd[1]: Listening on Telnet Server Activation S…t.
Dec 04 10:57:10 Shining.ACG systemd[1]: Starting Telnet Server Activation Socket.
Dec 04 11:17:18 Shining.ACG systemd[1]: Listening on Telnet Server Activation S…t.
Hint: Some lines were ellipsized, use -l to show in full. -
关闭防火墙:
[root@Shining ~]# iptables -F
-
在左侧CentOS7上也安装telnet
[root@Shining ~]# yum install -y telnet telnet-server
-
开启ssh转发:
[root@Shining ~]# ssh -L 9527:172.16.252.100:23 -fN 172.16.252.157
格式为:ssh -L 本地端口:telnet服务器ip:telnet服务器端口 -fN 转发主机ip
其中-f指后台运行,-N指不打开新的shell
-
连接远程telnet服务器:
[root@Shining ~]# telnet 127.0.0.1 9527
-
实现ssh转发telnet
左侧CentOS7:
[root@Shining ~]# ss -tn State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 52 172.16.253.159:22 172.16.254.183:7220 ESTAB 0 0 172.16.254.39:47615 172.16.252.157:22
中间CentOS6:
[root@localhost /etc/yum.repos.d]# ss -tn State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 172.16.252.157:41111 172.16.252.100:23 ESTAB 0 0 172.16.252.157:22 172.16.254.39:47615 ESTAB 0 64 172.16.252.157:22 172.16.254.183:7221
右侧CentOS7:
[root@Shining ~]# ss -tn State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 52 172.16.252.100:22 172.16.254.183:7515 ESTAB 0 0 ::ffff:172.16.252.100:23 ::ffff:172.16.252.157:41111
+
原创文章,作者:wangshuai,如若转载,请注明出处:http://www.178linux.com/62402