- 將所有本地127.0.0.1:2222端口數(shù)據(jù)通過(guò)root@s1.aaa.us的ssh轉(zhuǎn)發(fā)到s1.aaa.us所在內(nèi)網(wǎng)的192.168.1.20:2222端口。
ssh -NfL 127.0.0.1:2222:192.168.1.20:2222 root@s1.aaa.us
- sock5代理,本機(jī)端口2222
ssh -NfD 127.0.0.1:2222 root@s1.aaa.us
-
這個(gè)命令里面,其中 7070 是要建立加密隧道的本地一個(gè)未占用的端口,username@sshserver.com 分別指代你的 SSH 服務(wù)器的用戶名和密碼。
在終端中輸入這個(gè)命令,回車,然后輸入密碼,即可建立 SSH 端口轉(zhuǎn)發(fā)了。這個(gè)命令的好處是即使你關(guān)閉了終端窗口,ssh 仍然會(huì)在后臺(tái)運(yùn)行,
成功建立了一個(gè) ssh 加密代理后,設(shè)置你的 FireFox 瀏覽器的 socks 代理服務(wù)器為 127.0.0.1 端口為 7070 即可繞道訪問(wèn)正常情況下打不開(kāi)的目標(biāo)網(wǎng)址了。
ssh -qTfnN -D 7070 username@sshserver.com
動(dòng)態(tài)轉(zhuǎn)發(fā)
![]() |
|---|
適用場(chǎng)景:在本地搭建socks5代理服務(wù),可用于代理上網(wǎng)
#[www.baidu.com] - sock5 127.0.0.1:1080 -> [SSH client] - ssh -> [SSH server 192.168.1.1] -> #[www.baidu.com]
ssh -NfD 127.0.0.1:1080 root@192.168.1.1
本地轉(zhuǎn)發(fā)
![]() |
|---|
適用場(chǎng)景:在本地搭建正向代理服務(wù),可以隱藏客戶端IP
# [mysql client] -> 127.0.0.1:2206 -> [SSH client] ->ssh-> [SSH server 192.168.1.1] ->192.168.1.2:3306-> [mysql server]
ssh -NfL 127.0.0.1:3306:192.168.1.2:3306 root@192.168.1.1
遠(yuǎn)程轉(zhuǎn)發(fā)
![]() |
|---|
#[mysql client] ******** [SSH client] - ssh -> [SSH server 192.168.1.1] -192.168.1.2:3306-> [mysql server]
#修改SSH server的配置文件
root@localhost:~# vim /etc/ssh/sshd_config
GatewayPorts yes
root@localhost:~# vim /etc/ssh/sshd_config
ssh -NfR 1.1.1.1:3306:192.168.1.2:3306 root@192.168.1.1
[ssh 端口映射到本地]
ssh -f -N -g -L 12345:localhost:19229 root@ss -b 0.0.0.0
ssh -f -N -g -L 12346:localhost:19229 root@ss -b 0.0.0.0
ssh -f -N -g -L 12347:localhost:19229 root@ss -b 0.0.0.0
ssh -f -N -g -L 12348:localhost:19229 root@ss -b 0.0.0.0
1.-L選項(xiàng)表示本地沒(méi)有遠(yuǎn)程服務(wù)器ss 19229端口提供的服務(wù)映射到本地12348的端口上,ss是遠(yuǎn)程服務(wù)器的別名,-b表示是bind綁定到本地機(jī)器網(wǎng)卡 ,0.0.0.0表示任何網(wǎng)卡
ssh -f -N -g -R 12345:localhost:19229 root@ss -b 0.0.0.0
ssh -f -N -g -R 12345:localhost:19228 root@ss -b 0.0.0.0
2.-R表示把本地12345端口提供的服務(wù)綁定到服務(wù)器ss的19228端口,-b表示是綁定遠(yuǎn)程主機(jī)的任何網(wǎng)卡


