美文网首页
服务器SSH隧道联网设置

服务器SSH隧道联网设置

作者: KanL | 来源:发表于2020-11-19 01:19 被阅读0次

地址:https://www.jianshu.com/p/5e84046de28c
部分服务器集群运行在局域网环境,无法联网,使用conda或pip时需在本地下载安装包上传再安装。可设置本机http监听端口,通过SSH隧道的反向代理功能实现服务器联网,下载各种安装包。


1. 本地联网电脑设置

需安装http代理软件,Ubuntu系统可使用TinyProxy,Windows系统则使用WProxy。

WProxy下载地址

i. Ubuntu系统( 或使用win10的WSL1子系统 )

使用sudo apt-get install tinyproxy命令安装TinyProxy代理服务器,修改/etc/tinyproxy/tinyproxy.conf第23行Port监听端口(示例为20810),注释第212行Allow 127.0.0.1允许所有IP连接。运行sudo service tinyproxy start启动TinyProxy代理服务器。

ii. Windows系统

使用WProxy软件设置http代理。


WProxy软件界面
WProxy软件http代理配置界面

2. 服务器端设置

i. 若服务器可以连接本地电脑(在同一局域网)

示例192.168.26.151为本地电脑IP,在本地电脑防火墙设置中开放20810端口外部连接权限。

环境变量中设置代理

export http_proxy=http://192.168.26.151:20810
export https_proxy=http://192.168.26.151:20810
export ftp_proxy=http://192.168.26.151:20810

可添加至.bashrc文件中,该代理设置会影响所有可通过http代理联网的软件命令,也可以分别针对conda、pip、wget设置代理。

conda

在服务器用户根目录下新建.condarc文本文件,写入代理IP及端口,最后五行为设置使用国内镜像及显示包来源。

proxy_servers:
  http: http://192.168.26.151:20810
  https: http://192.168.26.151:20810
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - conda-forge
  - defaults
show_channel_urls: true

pip

在pip命令后添加--proxy="192.168.26.151:20810"使用临时代理,或在服务器用户根目录下新建.pip文件夹,在文件夹中新建pip.conf文本文件,写入代理IP及端口,最后一行为设置使用国内镜像。

[global]
proxy=192.168.26.151:20810
index-url=https://mirrors.aliyun.com/pypi/simple

wget

在wget命令后添加-e "http_proxy=192.168.26.151:20810"使用临时代理,或在服务器用户根目录下新建.wgetrc文件,写入代理IP及端口。

# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy = http://192.168.26.151:20810
http_proxy = http://192.168.26.151:20810
ftp_proxy = http://192.168.26.151:20810
# If you do not want to use proxy at all, set this to off.
use_proxy = on

ii. 若服务器无法连接本地电脑

利用ssh的隧道的反向代理功能将本地http监听端口转移到服务器。


Xshell隧道端口转发设置

命令行参数为

ssh -gnNTf -R 20814:localhost:20814 test@10.68.0.111

代理配置中的IP改为127.0.0.1,同时可设置conda和pip使用国内镜像。

环境变量中设置代理

export http_proxy=http://127.0.0.1:20810
export https_proxy=http://127.0.0.1:20810
export ftp_proxy=http://127.0.0.1:20810

conda

proxy_servers:
  http: http://127.0.0.1:20810
  https: http://127.0.0.1:20810
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - conda-forge
  - defaults
show_channel_urls: true

pip

[global]
proxy=127.0.0.1:20810
index-url=https://mirrors.aliyun.com/pypi/simple

wget

# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy = http://127.0.0.1:20810
http_proxy = http://127.0.0.1:20810
ftp_proxy = http://127.0.0.1:20810
# If you do not want to use proxy at all, set this to off.
use_proxy = on

3. 使用SOCKS代理

conda、pip及wget无法直接使用SOCKS代理,可安装tsocks工具,在服务器用户根目录下新建.tsocks.conf文件,写入SOCKS类型、代理IP及端口。

server = 127.0.0.1
server_type = 5
server_port = 20810

在需使用代理的命令前添加tsocks即可。

相关文章

  • 服务器SSH隧道联网设置

    地址:https://www.jianshu.com/p/5e84046de28c[https://www.jia...

  • putty ssh 开启隧道进行穿墙表演

    一、开启隧道。 添加服务器(如:香港的阿里云服务器)。展开Connection ⋙ SSH ⋙ Tunnels ...

  • 通过SSH隧道配置http代理

    如何配置SSH隧道,请参考使用SSH隧道通过海外服务器访问外部网络,本文在前一篇的基础上继续探索Window上So...

  • 通过SSH反向隧道建立SSH中继服务

    建立目标机器到中继服务器之间的SSH隧道 检查中继服务器sshd服务 通过中断服务器登录目标机器

  • ssh-简单配置

    一、配置文件 1.1 全局配置 /etc/ssh/sshd_config ssh服务器设置 /etc/ssh/ss...

  • ssh隧道连接数据库

    1、打开数据库连接工具,找到ssh或者ssh隧道(不同软件名字差不多) 填写服务器的地址,端口号(ssh默认是22...

  • 设置ssh快捷命令

    经常要用ssh登录远程服务器,每次都输入用户名和密码比较麻烦。可以设置一下ssh免密码和ssh服务器别名。 ssh...

  • 命令ssh 安全隧道/端口转发

    有待整理 SSH协议 通过公钥加密技术实现服务器身份验证。 安全的隧道SSH会自动加密和解密所有SSh客户端与服务...

  • Linux一些小技巧

    设置SSH登录时间 配置man中文帮助文档 未完待续~~ 1 设置SSH登录时间 我们一般远程连接Linux服务器...

  • SSH隧道技术

    SSH隧道(即SSH代理、端口转发),现在linux默认支持的就是ssh登录。对于SSH隧道,如果之前没接触过,只...

网友评论

      本文标题:服务器SSH隧道联网设置

      本文链接:https://www.haomeiwen.com/subject/ebitiktx.html