透過 VBox NAT 的 SSH 無法運作 Ubuntu 20.04 主機(桌面) Ubuntu 20.04 伺服器(來賓)

透過 VBox NAT 的 SSH 無法運作 Ubuntu 20.04 主機(桌面) Ubuntu 20.04 伺服器(來賓)

我可以透過將 vbox 適配器 1 設定為來賓上網bridged network adapter

當我將適配器 2 設定為host-only adapter

如果我不想使用防火牆,這就足夠了,但我想...使用此解決方案,我需要不斷擺弄 UFW 以允許適配器 1 通訊。

經過一番閱讀後,我意識到我應該能夠將適配器 1 設定為 nat 適配器並配置連接埠轉發,如下所示。

name|proto| host ip   | Host port| Guest IP     | Guest Port
SSH | TCP | 127.0.0.1 | 2522     | 192.168.52.1 | 22

這樣我應該能夠使用以下命令 ssh 進入訪客: ssh -vvv -p 2522 -i ~/.ssh/id_rsa [email protected]

我的問題是這個方法簡單凍結無需解釋。

OpenSSH_8.2p1 Ubuntu-4ubuntu0.4, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/user/.ssh/config
debug1: /home/user/.ssh/config line 41: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 127.0.0.1 is address
debug2: ssh_connect_direct
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2522.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 0
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.4

(我在禁用 UFW 的情況下進行了測試。)

一切都說這應該有效,但它沒有......有任何猜測嗎?

如果 NAT 上的 ssh 有效,我可以透過 ssh 進入盒子並進行主機-來賓通信,而無需不斷編輯防火牆。

進步: 根據@steeldriver的建議和這個帖子連接埠轉送的正確 IP 位址應為 Guest IP = 10.0.2.15

但是,當使用該位址時,ssh 無法連線:

OpenSSH_8.2p1 Ubuntu-4ubuntu0.4, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/dragonpharaoh/.ssh/config
debug1: /home/dragonpharaoh/.ssh/config line 41: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 10.0.2.15 is address
debug2: ssh_connect_direct
debug1: Connecting to 10.0.2.15 [10.0.2.15] port 2522

適配器 2 僅主機 這是我的僅主機適配器配置: 在此輸入影像描述 在此輸入影像描述

適配器 1 NAT 在此輸入影像描述

轉送連接埠 在此輸入影像描述

這是訪客中 #ifconfig 的當前輸出 在此輸入影像描述

Netstat確認Vbox監聽埠 在此輸入影像描述

注意:主機都是全新安裝的(不到一個月),而訪客則是今天安裝的

答案1

我的貼文中 SSH over NAT 的設定都是正確的。

錯誤是我使用的 ssh 指令:

ssh命令可以不是是僅主機適配器 ip
ssh -p 2222 <login>@192.168.52.1 <- 不會解決

ssh命令可以不是是分配給 vbox
ssh -p 2222 <login>@10.0.2.15 <-的 nat 適配器 IP不會解決

SSH 指令必須是:
ssh -p 2222 <login>@127.0.0.1

相關內容