3

I need to SSH from guest VM (Linux/Debian 9) to its host running VirtualBox on a Windows 10 machine. Network configuration: NAT.

Which Linux command can I use to figure out the IP of the host from within the guest?

1 Answer 1

2

Show VirtualBox host's internal IP address

$ ip route show default
default via 10.0.2.2 dev eth0 proto static
10.0.2.0/24 dev etho proto kernel scope link src 10.0.2.15

In the above, 10.0.2.2 is the address of the host which is routing packets from the guest's IP (10.0.2.15 above for reference)

If you prefer getting the IP itself, you could use grep and cut (or just awk), eg:

$ ip route show default | grep default | cut -d ' ' -f3
10.0.2.2
13
  • Isn't 10.0.2.2 just the ip-address used by the host for the host-side of the virtual network between hosts and guest(s) in stead of the real network facing address of the host ? Would the SSH service of the host be listening to that ip for incoming requests ? That may be highly dependent of the specific OS and software used on the host .
    – Tonny
    Commented Apr 11, 2018 at 14:20
  • @Tonny - host OS - Windows 10. SSH server - either the built-in SSH server, or built-in OpenSSH server. Ideally it should work for both. Thank you! Commented Apr 11, 2018 at 14:27
  • 1
    @user1876484 That is my situation, and I am able to connect from guest to host using the internal IP address. Might vary depending on sshd flavour though.
    – bertieb
    Commented Apr 11, 2018 at 14:34
  • 2
    @user1876484 I just tested this with a debian guest and a Win10 host (using RDP as the test-conenction) and that works, because Windows 10 by default binds the RDP service to all ip-addresses. I don't have a SSH-server around on Windows 10 at the moment to test with that. As long as the SSH service binds to * it should work (and I guess that the Microsoft supplied one will bind to all ip-addresses.)
    – Tonny
    Commented Apr 11, 2018 at 14:36
  • 1
    For sake of completeness: there is an API available which might expose a host IP; but I can't downlaoded and read through the SDK to find out. Going way beyond a quick determination but might be handy for those who need that.
    – bertieb
    Commented Apr 11, 2018 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .