![](https://img.haomeiwen.com/i6909446/34520fc2179608fd.png)
本地端口转发
实验:
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机器连接
![](https://img.haomeiwen.com/i6909446/566ac14f585fe864.png)
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
![](https://img.haomeiwen.com/i6909446/537ddda34ce9e535.png)
连接成功登录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 去掉注释
![](https://img.haomeiwen.com/i6909446/e4f2d801ca27fd0f.png)
[root@centons6 ~]# service postfix restart #centos7 systemctl restart postfix
![](https://img.haomeiwen.com/i6909446/36421611c075fea6.png)
[root@centons6 ~]# iptables -nvL #查询状态
[root@centons6 ~]# service iptables stop #关闭防火墙
![](https://img.haomeiwen.com/i6909446/ba2f8120e22778d8.png)
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
![](https://img.haomeiwen.com/i6909446/ccb98e162b39d8fa.png)
[root@centos7 ~]#telnet 172.18.70.80 25 测试给C机器发信息
![](https://img.haomeiwen.com/i6909446/bf69cab2323b29ba.png)
C操作
[root@centons6 ~]# iptables -A INPUT -s 172.18.70.40 -j REJECT 禁止A机器连接,不影响B机器访问25端口
![](https://img.haomeiwen.com/i6909446/e7bae6ba8b8109fe.png)
A操作
[root@centos7 ~]#vim /etc/selinux/config 修改配置禁止
[root@centos7 ~]#getenforce
Enforcing
[root@centos7 ~]#setenforce 0 临时关闭
![](https://img.haomeiwen.com/i6909446/a57c2d23f217f65c.png)
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客户端
![](https://img.haomeiwen.com/i6909446/e2a4657d81ac1877.png)
网络连接已经建
A机器成功通过防火墙连接C
[root@centos7 ~]#telnet 127.0.0.1 9527 发送邮件给C
![](https://img.haomeiwen.com/i6909446/8ee44287d5f07936.png)
C操作
查看连接状态 显示ip是B在连接C机器,其实是A连接
![](https://img.haomeiwen.com/i6909446/bf82ca8c20cabb97.png)
[root@centons6 ~]# mail 打开邮件
![](https://img.haomeiwen.com/i6909446/7b9ab5b31d9cf928.png)
网友评论