Proxy server
Some readers may have heard of shadowsocks
, which allows users to access the Internet through a remote server. Well, OpenSSH can do the same thing.
1 | ~ ❤ ssh -D 9000 ali |
It means you listen to the 9000 ports as an entry port for proxy. A good way to test this is to use the Firefox proxy settings.
Well, you could check the port by using netstat
:
1 | ~ ❤ netstat -tnlp |
You probably know that OpenSSH tunnels can be used to handle traffic, let me give you two more specific examples of packet communication.
Remote Port Forwarding
Cast local port to the remote port.
Here is a scenario, when I need to develop on my local host, I have an HTTP service listening on TCP port 8080. Now, if I want to share this service to a remote host, so that anyone who has access to the remote host can access my service.
Here is the command:
1 | # In local host: cast local 8080 to the remote 8080 |
1 | # In remote host: we can see the port listend by ssh daemon |
Here is the configuration:
1 | Host ali |
Local Port Forwarding
Cast remote port to the local port
There is also a situation where I am running a MySQL host on a remote host, listening on TCP port 3306.
But incoming traffic to that port has been blocked by iptables, which means I can’t directly access
MySQL with remote_host:3306
.
1 | ## There is an mysql service in the remote host |
Now, I can use OpenSSH to forward traffic to the remote hosts:
1 | ## ssh will convert the traffic to `local_host:13306 => remote_host:33061 |
It’s also can be used in ssh_config
.
1 | Host ali |