取得 autossh 隧道的狀態

取得 autossh 隧道的狀態

我使用 autossh 建立了一個 ssh 隧道autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -fN -T -R 22222:localhost:22 console@<server_ip>。它在一段時間內運行良好,但現在似乎已關閉。如何查看隧道是否開放?

我試過:

lsof -i -n | egrep '\<ssh\>' | grep <server_ip>

這返回了:

ssh 28517 username 3u IPv4 4649313 0t0 TCP 192.168.13.100:37096-><server_ip>:ssh (ESTABLISHED)

我認為響應應該表明隧道已打開(如果沒有隧道,我希望 return=1),但是當我嘗試使用隧道時,我得到:

ssh: connect to host localhost port 22: Connection refused

我需要使用什麼來從客戶端檢查隧道的狀態?

答案1

看起來有人在 Stack Exchange 上給了一個非常全面的答案使用 shell 腳本

答案2

您可以在遠端檢查

watch -n 0.5 "netstat -tulpn"

相關內容