快轉到主要內容

Simply setting up a Proxy Server with SSH

·344 字
Computer-Science SSH
目錄

Did you know that SSH can make your host as a proxy server?


SSH
#

Connecte to the remote host with SSH:

1# ssh <user-name>@<host-ip>
2# example
3ssh alpaca@192.168.0.2
4# the default port of SSH is 22, or you can use the parameter "-p" to specify the ssh port of the remote host.

Local port forwarding (TCP port / Unix socket forward)
#

Forward local TCP Port or Unix Socket with parameter “-L”.

1-L [bind_address:]port:host:hostport
2-L [bind_address:]port:remote_socket
3-L local_socket:host:hostport
4-L local_socket:remote_socket

Specifies that connections to the given TCP port or Unix socket on the local (client) host are to be for-warded to the given host and port, or Unix socket, on the remote side.

1# example
2ssh -L 8877:192.168.0.101:7766 alpaca@192.168.0.102

In the example above, it will forward the connections that given in arg(192.168.0.102) from local port 8877 to remote server port 7766 , and compelete the progress.


Reverse tunneling
#

It’s used in the same way as Local port forwarding (-L), just reverse.

1-R [bind_address:]port:host:hostport
2-R [bind_address:]port:local_socket
3-R remote_socket:host:hostport
4-R remote_socket:local_socket
5-R [bind_address:]port

Specifies that connections to the given TCP port or Unix socket on the remote (server) host are to be forwarded to the local side.

1# example
2ssh -R 192.168.0.101:7766:localhost:8085 alpaca@192.168.0.102

It will forward the traffic from 192.168.0.101:7766 to localhost:8085.

If it’s not working
#

Probably is because of permission denied.

Go to check the file /etc/ssh/sshd_config on ssh server, and find the option GatewayPorts, set it yes.
(If it’s annotated, uncomment it first, or can’t find the option, just add it by yourself.)

And don’t forget to restart the ssh server.


Make the host a proxy server with SSH (Dynamic Tunneling)
#

In SSH commands, we can use parameter “-D” to make a tunnel between local host and remote server.

Specifies a local “dynamic” application-level port forwarding.

For example:

1# ssh <user-name>@<host-ip> [-D [bind_address:]port]
2# example
3ssh alpaca@123.123.123.123 -D 1234

We made a tunnel that connects host 123.123.123.123, and port of tunnel is 1234.

Now, we can take localhost:1234 as a proxy server. (That can forward for our connection to 123.123.123.123:22.)

Alpaca
作者
Alpaca
No one can stop my feet.

相關文章

How to use GnuPG to sign files and messages?
·1769 字
Computer-Science Cryptography PGP

用 GnuPG 簽署、驗證、加密、解密 你的檔案及訊息。

How to use GnuPG to generate PGP key?
·1393 字
Computer-Science Cryptography PGP

怎麼使用 GnuPG 生成 PGP 金鑰?

《SQL Basics-03》UPDATE、ALTER、DROP
·907 字
Computer-Science SQL Database

一些基礎常見的 SQL 語法。

《SQL Basics-02》SELECT、LIKE
·962 字
Computer-Science SQL Database

一些基礎常見的 SQL 語法。

《SQL Basics-01》CREATE、INSERT
·1421 字
Computer-Science SQL Database

一些基礎常見的 SQL 語法。

資料庫概念 DB、DBMS、SQL 之間的關係
·966 字
Computer-Science SQL Database

資料庫早已被大量使用,如果還分不清楚 Database 與 DBMS 及 SQL 的關係,那還真是場災難呢!