如何将远程主机端口经加密隧道映射到本地主机?
- By : Will
- Category : Debian-Like

Debian-Like
1 前言
一个问题,一篇文章,一出故事。
笔者最近需要将远程的一台主机“127.0.0.1:3128”端口经过加密隧道映射到本地主机“0.0.0.0:3128”端口,于是整理本章节。
2 最佳实践
2.1 安装软件包
apt install -y autossh
2.2 测试端口ssh隧道转发
autossh -M 0 -L 3128:0.0.0.0:3128 -N -f -o "GatewayPorts=yes" -i ~/.ssh/id_rsa root@proxy.cmdschool.org
2.3 创建隧道转发服务
vim /etc/systemd/system/autossh-tunnel.service
加入如下设置,
[Unit] Description=AutoSSH Tunnel for Squid Proxy After=network.target [Service] Type=simple User=root ExecStart=/usr/bin/autossh -M 0 -L 3128:0.0.0.0:3128 -N -o "GatewayPorts=yes" -i ~/.ssh/id_rsa root@proxy.cmdschool.org ExecReload=/bin/kill -HUP $MAINPID UMask=0007 KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target
配置保存后,需要使用如下命令重载使配置生效,
systemctl daemon-reload
然后,你可以使用如下命令启动服务或配置自启动,
systemctl start autossh-tunnel systemctl enable autossh-tunnel
没有评论