Score:-1

SSH Over VBox NAT NOT Working Ubuntu 20.04 Host (desktop) Ubuntu 20.04 server (guest)

tr flag

I can get internet on guest by setting vbox adapter 1 to bridged network adapter

and host-guest communication works when I set adapter 2 as a host-only adapter

This is sufficient if I don't want to use a firewall, but I do... with this solution I need to constantly fiddle with UFW to allow adapter 1 communication.

After some reading, I realized that I should be able to set up adapter 1 as a nat adapter and configure port forwarding as shown below.

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

This way I should be able to ssh into the guest using: ssh -vvv -p 2522 -i ~/.ssh/id_rsa [email protected]

My problem is that this method simply freezes without explanation.

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

(I tested with UFW disabled.)

Everything, says this should work, but it doesn't... any guesses?

If ssh over NAT works, I can ssh into the box and have host-guest communication without constantly editing my firewall.

Progress: According to @steeldriver's suggestion and this post the correct ip address for port forwarding should be Guest IP = 10.0.2.15

However, when using that that address, ssh can't connect:

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

Adapter 2 Host-only This is my host-only adapter config: enter image description here enter image description here

Adapter 1 NAT enter image description here

Port Forwarding enter image description here

This is current output of #ifconfig inside the guest enter image description here

Netstat confirming Vbox listening port enter image description here

NOTE: Both the host is fairly fresh install (less than a month) and the guest was made today

in flag
For the Host-only adapter, have you created a device (probably called `vboxnet0`) and set the promiscuous mode to "Allow All"? The IP address should be something like `192.168.56.1` rather than the IP address that you are using ...
hr flag
Is your NAT guest IP in the same range as your host network? The default NAT setup would use a completely different private LAN range, such as `10.x.x.x` iirc. I can imagine SSH hanging if packets are getting misrouted by an addressing overlap.
nightwatch avatar
tr flag
@matigo I tried your suggestion... same problem, still freezes
nightwatch avatar
tr flag
@steeldriver the guest NAT ip is 10.0.2.15 I am testing it now... one sec..
nightwatch avatar
tr flag
@steeldriver When I use 10.0.2.15 for port forward. I can't ping and/or ssh to it...
nightwatch avatar
tr flag
According to this post https://www.xmodulo.com/access-nat-guest-from-host-virtualbox.html @steeldriver is correct. The netstat command even confirms vbox's listening port on my machine.. I will edit my post above because the ssh output is different..
hr flag
I think we need more information about how you set up the network - NAT netmask, DHCP and so on. You can use 2 distinct 192.168.x.0/24 networks for host and NAT if you wish - using 10.x.x.x was just a suggestion to try since it's unambiguously different from any 192.x.x.x range.
nightwatch avatar
tr flag
one sec... screenshots coming
nightwatch avatar
tr flag
I figured it out fellas... thanks for your help... the problem was user error. The actual ssh command has to be ssh -p 2522 <user>@127.0.0.1 (you MUST use the host ip, it cannot be host-only adapter ip, it can not be the NAT ip, it must be the host ip in the ssh command everything else fails because it can resolve
Score:0
tr flag

The settings for SSH over NAT in my post are all correct.

The error was the ssh command that I was using:

the ssh command can not be the host-only adapter ip
ssh -p 2222 <login>@192.168.52.1 <- will not resolve

the ssh command can not be the nat adapter ip that is assigned to the vbox
ssh -p 2222 <login>@10.0.2.15 <- will not resolve

The SSH Command MUST Be:
ssh -p 2222 <login>@127.0.0.1

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.