Mobaxterm: Local port forwarding Remote port forwarding
文章目录
- Remote port forwarding
- Local port forwarding
- Appendix: Deploy clash in docker
Remote port forwarding
If you want to share the proxy on your local machine with the remote server, use Remote port forwarding.
Consider this scenario: There is no proxy configured in the remote server, you may fail to install software using the apt command, download code repositories using git clone, or access docker hub due to network problems, but in your laptop you have installed Clash for Windows, then you can share it with the remote server without installing clash on the server.
Follow these steps:
- In Mobaxterm, open Tools->MobaSSHTunnel(port forwarding)
- Open New SSH tunnel
- Set the port forwarding parameters
- <Local server>: 127.0.0.1
- <Local port>: 7890 (the port of your clash)
- <SSH server>: remote server’s ip (for example 10.xxx.xxx.xxx)
- <SSH login>: your username on the remote server
- <SSH port>: 22
- <Forwarded port>: 7890 (if you want to use port 7890 of the server for proxy)
Then Save and click Start button to enable forwarding.
- In the server, set the proxy parameters
- proxy for bash
export http_proxy="http://127.0.0.1:7890" && export https_proxy="http://127.0.0.1:7890"
- proxy for apt
sudo vim /etc/apt/apt.conf.d/proxy.conf
In proxy.conf, add these contents
Acquire {
http::proxy "http://127.0.0.1:7890";
https::proxy "http://127.0.0.1:7890";
}
- proxy for docker daemon
sudo vim /etc/systemd/system/docker.service.d/proxy.conf
In proxy.conf, add these contents
[Service]
Environment="HTTP_PROXY=127.0.0.1:7890"
Environment="HTTPS_PROXY=127.0.0.1:7890"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
sudo systemctl daemon-reload && sudo systemctl restart docker
- proxy for docker container
vim ~/.docker/config.json
In config.json, add these contents and replace 192.168.xxx.xxx with the real IP address of the remote server (do not use 127.0.0.1)
{
"proxies":
{
"default":
{
"httpProxy": "http://192.168.xxx.xxx:7890/",
"httpsProxy": "http://192.168.xxx.xxx:7890/",
"noProxy": "localhost,127.0.0.1"
}
}
}
- Now you have completed all the settings. Next time if you want to share the proxy when you connect to the same server, just click Start button to enable forwarding.
Local port forwarding
If you have installed clash on your server and you want to manage it through the web UI, use Local port forwarding.
Clash provides a web UI (https://clash.razord.top/#/proxies). After setting external-controller in ~/.config/clash/config.yaml, users can use the web UI to manage Clash through the specified port.
For example, in config.yaml external-controller: 0.0.0.0:9090, you can access the web UI through 10.xxx.xxx.xxx:9090, but if the server firewall does not open port 9090, you can use Local port forwarding to map port 9090 to other ports such as 9090 or 9091 on the local machine, and then access the local port.
- <Remote server>: 127.0.0.1
- <Remote port>: 9090 (the port of external-controller)
- <SSH server>: remote server’s ip (for example 10.xxx.xxx.xxx)
- <SSH login>: your username on the remote server
- <SSH port>: 22
- <Forwarded port>: 9091 (if you want to use port 9091 of your local machine to access the clash Web UI in the server)
Appendix: Deploy clash in docker
docker-compose.yaml
services:
clash:
image: dreamacro/clash-premium:2023.08.17
restart: always
volumes:
- ./config.yaml:/root/.config/clash/config.yaml:ro
# - ./yacd-gh-pages:/root/.config/clash/ui:rwx # 仪表盘 Volume 映射
ports:
- "7890:7890"
- "7891:7891"
- "9090:9090" # 外部控制 (RESTful API)
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
network_mode: "host"
You can copy config.yaml from your computer.
- Start
docker compose up -d
- Stop
docker compose down
- View logs
docker compose logs