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

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 user@127.0.0.1

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 hereenter image description here

Adapter 1 NATenter image description here

Port Forwardingenter image description here

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

Netstat confirming Vbox listening portenter image description here

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

9

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like