|
| 1 | +# Accessing SwanLab Cloud from Internal Computing Nodes |
| 2 | + |
| 3 | +Typically, computing nodes in a computing cluster cannot connect to the internet, and external development machines must connect to computing nodes through a jump server. If you cannot connect to the public network, you won't be able to upload data to SwanLab Cloud. However, since the jump server acts as an "intermediary" that can connect to the internet, we can utilize it to proxy the computing nodes' connection to the public network environment. |
| 4 | + |
| 5 | +<img src="./ssh-portforwarding/cluster-network_en.png" alt="cluster-network" style="zoom:30%;" /> |
| 6 | + |
| 7 | +We can use SSH proxy forwarding to enable computing nodes to connect to [SwanLab Cloud](https://swanlab.cn/). |
| 8 | + |
| 9 | +## Enable Proxy Forwarding Network |
| 10 | + |
| 11 | +> Ensure that your computing node can connect to the jump server via SSH |
| 12 | +
|
| 13 | +Execute the following command on the computing node to connect to the jump server: |
| 14 | + |
| 15 | +```bash |
| 16 | +ssh -D {port} {user}@{ip} |
| 17 | +``` |
| 18 | + |
| 19 | +- `port` parameter is the port used for proxy forwarding, for example `2015` |
| 20 | +- `user` and `ip` parameters are the username and internal IP address of the jump server |
| 21 | + |
| 22 | +For example: `ssh -D 2015 [email protected]` |
| 23 | + |
| 24 | +After successfully connecting to the jump server, a SOCKS proxy tunnel is opened on the corresponding port. You can then configure the proxy by setting environment variables in the terminal, for example: |
| 25 | + |
| 26 | +```bash |
| 27 | +export http_proxy=socks5://127.0.0.1:{port} https_proxy=socks5://127.0.0.1:{port} |
| 28 | +``` |
| 29 | + |
| 30 | +> Note: Replace the corresponding `port` with your configured port, the protocol is [socks5](https://en.wikipedia.org/wiki/SOCKS) |
| 31 | +
|
| 32 | +After configuration, you can test if you're correctly connected to the public network using the following command: |
| 33 | + |
| 34 | +```bash |
| 35 | +curl ipinfo.io |
| 36 | +``` |
| 37 | + |
| 38 | +Once configured successfully, you can happily use SwanLab Cloud version 🥳. |
| 39 | + |
| 40 | +Note that the SSH connection must not be disconnected, and closing the terminal session will cause the connection to drop. You can use [tmux](https://github.com/tmux/tmux/wiki) to keep the SSH connection command running in the background. |
| 41 | + |
| 42 | +```bash |
| 43 | +tmux |
| 44 | +# Execute the SSH connection command in tmux |
| 45 | +ssh -D {port} {user}@{ip} |
| 46 | +``` |
| 47 | + |
| 48 | +New terminal sessions require reconfiguring environment variables. Of course, you can write the above environment variable export commands into the `.bashrc` file to automatically set the environment variables each time a new terminal session is opened. For example: |
| 49 | +```bash |
| 50 | +echo "export http_proxy=socks5://127.0.0.1:{port}" >> ~/.bashrc |
| 51 | +echo "export https_proxy=socks5://127.0.0.1:{port}" >> ~/.bashrc |
| 52 | +``` |
| 53 | +> Note Replace '{port}' with the port you set |
| 54 | +
|
| 55 | +## Working Principle |
| 56 | + |
| 57 | +The above implementation relies on [SSH Dynamic Port Forwarding](https://en.wikipedia.org/wiki/Port_forwarding#Dynamic_port_forwarding), which turns the SSH server into a SOCKS proxy server that applications on your computer can use as an intermediary to connect to remote servers. |
| 58 | + |
| 59 | +> **Note:** The program must support SOCKS type proxies for you to be able to route traffic from that application using dynamic port forwarding. |
0 commit comments