How to expose local loopback to (VirtualBox) VM connecting to host via NAT (VirtualBox NatNetwork)

2

I'm using the VirtualBox NatNetwork type to connect most of my VMs to the host (with the required ports set up for forwarding). I'd like to know how I can connect to the local loopback ("localhost") of the host from inside the VM (e.g. use apt-cacher-ng inside the VM).

The usage of NAT with connections to IPs of interfaces of the host is clear for me and works.

I'm using VirtualBox 4.3.10 on Ubuntu 14.04 with Linux 3.11.13.

Karl Richter

Posted 2014-05-04T10:09:45.807

Reputation: 1 641

See host-only networking in the manual.

– reinierpost – 2016-03-24T11:49:15.750

You cannot do that. Localhost is always a local interface that never leaves the computer it is used in. – Tero Kilkanen – 2014-05-04T10:32:14.163

Answers

4

Try 10.0.2.2 on the Virtual Machine. It should hit 127.0.0.1 on your Host Machine.

10.0.2.2 is gateway IP on the Virtual Machine in NAT mode since the Host Machine provides the networking for the Virtual Machine. (Similar to how your gateway IP is the IP to your router, and is the IP you use to bring up the router management page)

byoungb

Posted 2014-05-04T10:09:45.807

Reputation: 186

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

– Ramhound – 2016-09-26T16:35:51.763

Yes this answers the question. Maybe I wasn't clear but 10.0.2.2 on the VM will hit 127.0.0.1 on the Host, in NAT mode. – byoungb – 2016-09-26T20:38:32.737

"ry 10.0.2.2 (the gateway IP) on the Virtual Macing. It should hit 127.0.0.1 on your Host Machine." - My automatic comment was because your original answer contained a single sentence. If you disagree with that comment just improve the answer. You don't need to reply to the comment. – Ramhound – 2016-09-26T20:44:34.813

Yeah I looked for documentation on this but couldn't find it otherwise I would have added a link. I did update my answer to be more complete – byoungb – 2016-09-26T20:53:16.050

The answer has improved slightly. – Ramhound – 2016-09-27T14:17:57.897

0

Use this forwarding rule: e.g., forwarding ssh traffic

Protocol:TCP
Host IP: 127.0.0.1
Host Port: xxx
Guest IP : Blank
Guest Port: 22

Ghassan Al Mamar

Posted 2014-05-04T10:09:45.807

Reputation: 1