SSH端口转发

本地端口转发

实验:
A通过B连接C (C禁止A连接)

A(centos7~红色):172.18.70.40
B(centos6~红色):172.18.70.70
C(centos6~白色):172.18.70.80

C操作
rpm -qa telnet-server  检查是否安装成功
yum install telnet             安装telnet
vim /etc/xinetd.d/telnet    修改配置打开23端口   disable=no
service xinetd restart      重启守护进程
chkconfig --list telnet      查看是否启动telnet        on
service iptables stop    关闭防火墙
iptables -vnL                查询防火墙是否关闭
iptables -A INPUT -s 192.168.25.107 -j REJECT   禁止A机器连接
A操作
telent连接C机器ip 无法连接(禁止A机器ip连接)
ssh -L 9527:172.18.70.80:23 -Nf 172.18.70.70 A连接B连接C机器(9527端口是A设置)
ss -tn 查看是否连接B机器
telnet 127.0.0.1 9527
连接成功登录C机器
killall ssh 删除进程 断开连接
ss -tnl 9527 查看端口取消

远程端口转发(穿过防火墙)

实验:
A主机,B服务器,C主机(B,C主机都在防火墙内部),A通过B穿过防火墙连接C
A(centos7~红色):172.18.70.40
B(centos6~红色):172.18.70.70
C(centos6~白色):172.18.70.80
C操作
[root@centons6 ~]# vim /etc/postfix/main.cf
#inet_interfaces = localhost   绑定127机器上注释掉
inet_interfaces = all            all表示所有ip   去掉注释
[root@centons6 ~]# service postfix restart #centos7 systemctl restart postfix
[root@centons6 ~]# iptables -nvL #查询状态
[root@centons6 ~]# service iptables stop #关闭防火墙
A操作
firewall作为默认防火墙
[root@centos7 ~]#systemctl disable firewalld  禁止firewall开机启动
[root@centos7 ~]#iptables -nvL  查看
[root@centos7 ~]#systemctl stop firewalld   停止firewall
[root@centos7 ~]#iptables -F   清空
[root@centos7 ~]#iptables -nvL
[root@centos7 ~]#telnet 172.18.70.80 25 测试给C机器发信息
C操作
[root@centons6 ~]# iptables -A INPUT -s 172.18.70.40 -j REJECT 禁止A机器连接,不影响B机器访问25端口
A操作
[root@centos7 ~]#vim /etc/selinux/config  修改配置禁止
[root@centos7 ~]#getenforce
Enforcing
[root@centos7 ~]#setenforce 0  临时关闭
B操作
ssh -R 9527:172.18.70.80:25 -fN 172.18.70.40 #ssh是客户端,9527端口在A主机打开
A操作
A 机器172.18.70.40:22相当服务器 B机器172.18.70.70:40140客户端
网络连接已经建
A机器成功通过防火墙连接C
[root@centos7 ~]#telnet 127.0.0.1 9527 发送邮件给C
C操作
查看连接状态 显示ip是B在连接C机器,其实是A连接
[root@centons6 ~]# mail 打开邮件
B跟A连接的SSH协议,B是客户端,A是服务器可以穿过防火墙,现在出去回来都可以,A主动进来是不可以的,除非防火墙单独开策略
OK
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  •   本文将介绍两种应用场景的SSH端口转发,分别是SSH本地转发以及SSH远程转发。 简介   SSH(Secur...
    KingFighting阅读 1,513评论 0 5
  • 实战 SSH 端口转发 通过本文的介绍,读者可以从中了解到如何应用 SSH 端口转发机制来解决日常工作 / 生活中...
    hopevow阅读 1,066评论 0 9
  • 第一部分 概述当你在咖啡馆享受免费 WiFi 的时候,有没有想到可能有人正在窃取你的密码及隐私信息?当你发现实验室...
    fastjrun阅读 1,180评论 0 8
  • 我的应用场景是:在vps(root@159.89.206.20)上面跑了个只能在服务器本地访问的网页:127.0....
    ThomasYoungK阅读 1,233评论 0 0
  • SSH 会自动加密和解密所有 SSH 客户端与服务端之间的网络数据。但是, SSH 还能够将其他 TCP 端口的网...
    姜饼人_9e7b阅读 341评论 0 0