ssh端口转发

本文详细介绍了SSH的三种端口转发方式:本地端口转发、远程端口转发和动态端口转发。通过SSH本地端口转发,外网可以加密访问内网主机;远程端口转发同样提供加密的外网访问;动态端口转发则用于创建代理,使得内网设备如192.168.43.6和Windows机器能够安全地访问互联网。

ssh本地端口转发

实现外网能够访问内网的一台主机,但需要防火墙放行sshd的22端口,外网线路径传输的数据是被 ssh协议加密的

在这里插入图片描述

192.168.43.17

yum install telnet-server -y
systemctl start telnet.socket
iptables -A INPUT -s 192.168.43.6 -j REJECT

useradd zs && echo zs |passwd --stdin zs

192.168.43.7

yum install telnet -y

192.168.43.6

yum install telnet -y
ssh -L 9527:192.168.43.17:23 192.168.43.7 -fN
telnet 127.0.0.1 9527

在这里插入图片描述

在这里插入图片描述

192.168.43.17

yum install postfix

vim /etc/postfix/main.cf
inet_interfaces = all
#inet_interfaces = localhost

systemctl restart postfix

192.168.43.6

ssh -L 9000:192.168.43.17:25 192.168.43.7 -fN

telnet 模拟邮件客户端发邮件

[root@Centos6-43-6 ~]# telnet 127.0.0.1 9000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 Centos7-43-17.linux ESMTP Postfix
helo a.com
250 Centos7-43-17.linux
mail from:mayun@alibaba.com
250 2.1.0 Ok
rcpt to:zs
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
from:mayun
to:zs
subject:test

Welcom to alibaba.
.
250 2.0.0 Ok: queued as 61B7A53D7B
quit
221 2.0.0 Bye
Connection closed by foreign host.

邮件被转发到 zs@192.168.43.17上,查证
在这里插入图片描述

ssh远程端口转发

实现外网能够访问内网的一台主机,外网线路径传输的数据是被 ssh协议加密的

在这里插入图片描述
192.168.43.17

yum install httpd -y
echo welcome to www.xuepeng.com > /var/www/html/index.html
systemctl start httpd

iptables -A INPUT -s 192.168.43.6 -j REJECT

192.168.43.7

ssh -R 9500:192.168.43.17:80 192.168.43.6 -fN

192.168.43.6

curl 192.168.43.17
	curl: (7) couldn't connect to host
curl 127.0.0.1:9500
	welcome to www.xuepeng.com

ssh动态端口转发

实现 192.168.43.6 能够上网,用了一台机主机作代理,可以访问互联网的所有机器
在这里插入图片描述
192.168.43.17

yum install httpd -y
echo welcome to www.xuepeng.com > /var/www/html/index.html
systemctl start httpd

iptables -A INPUT -s 192.168.43.6 -j REJECT

192.168.43.6

curl 192.168.43.17
	curl: (7) couldn't connect to host
	
ssh -D 6666 192.168.43.7 -fN
curl --socks5 127.0.0.1:6666 http://192.168.43.17
	welcome to www.xuepeng.com

在这里插入图片描述
实现 windows 机器 能够上网,用了2台机器作代理,能够访问互联网的所有主机

192.168.43.17

yum install httpd -y
echo welcome to www.xuepeng.com > /var/www/html/index.html
systemctl start httpd

iptables -A INPUT -s 192.168.43.6 -j REJECT
iptables -A INPUT -s 192.168.43.1 -p tcp --dport 80 -j REJECT

192.168.43.6

ssh -D 9999 192.168.43.7 -fNg

192.168.43.1

火狐浏览器 ->打开菜单->选项->网络设置
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
192.168.43.7

ssh -D 1080 192.168.43.7 -gfN

192.168.43.1
IE浏览器
工具->选项->连接 ->局域网设置->
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值