Yes, you're correct that they do not share the same localhost (127.0.0.1) connection. The localhost address has different functions depending on whether you're using it outside the VM or inside the VM (based on what you've described, you want to use it outside). This is quite possible to do, even with other services running.

There won't necessarily be any conflicts—in fact it's totally avoidable by using port forwarding within VirtualBox. In practice, it works similarly to Docker containers (inside/outside ports). The following is the response from DevOps Guru (ChatGPT) when I asked if this was possible.

I use this GPT regularly for virtually everything computer-related. I can say based on my experience, this should work, though I haven't tried such a setup with VirtualBox myself.

I've also attached an image of the NAT rule setup in VirtualBox, since I have it installed and was curious myself.

---

Yes, VirtualBox can be configured to use 127.0.0.1 (localhost) for internal-only communication between the host and virtualized instances, but with some nuances. Here's how and when you can achieve this:

✅ Scenario: Restricting Access to Internal Only (127.0.0.1)
If you want the VM to be accessible only from the host (not from external devices or network), you're essentially aiming for local loopback-based communication. You can achieve this using Port Forwarding in NAT Mode or by using Host-only Networking.

🔧 Option 1: NAT with Port Forwarding to 127.0.0.1
This setup allows only the host to access VM services via localhost.

Example Use Case:
You run a web server inside the VM on port 80, and want to access it from the host using http://127.0.0.1:8080.

🧩 How to Configure:
Go to VM Settings → Network tab.

Adapter 1: Set to NAT.

Click Advanced → Port Forwarding.

Add a rule:

Name: HTTP
Protocol: TCP
Host IP: 127.0.0.1
Host Port: 8080
Guest IP: <leave blank or use internal VM IP>
Guest Port: 80

🔒 This restricts access to the VM's port 80 only to the host machine via localhost.

🔧 Option 2: Host-Only Adapter
This allows communication between host and VM, but not to the internet or external systems.

The host and VM are on a private virtual network (e.g., 192.168.56.1/24).

VM gets an IP like 192.168.56.101, only reachable by the host.

This doesn't use 127.0.0.1 directly, but still confines traffic to host-to-VM only.

Use this if you want to SSH into the VM or expose internal services, but avoid external exposure.

🧪 Advanced (Optional): Loopback Binding Inside VM
Inside the VM, you can bind services only to 127.0.0.1, which makes them reachable only from within the VM. That’s different from making them available to the host via localhost.

> HUMAN NOTE: Binding services to 127.0.0.1 within a VM would result in the service only being accessible from *within* that VM, not from the host.

✅ Recommended for Internal Access:
Use NAT + Port Forwarding with 127.0.0.1 for most cases.

Use Host-only Adapter if you want more control, e.g., Ansible provisioning, SSH, etc.

---

This is the response regarding using the Windows hosts file:

Excellent question — and yes, you can add entries to the Windows hosts file to reference VMs, but there’s an important distinction depending on how you access the VMs:

✅ Scenario Recap:
Each VM uses NAT networking.

Each VM has a service (e.g., web server) exposed via port forwarding from the host’s 127.0.0.1:X → VM_IP:PORT.

You want to use friendly names like vm1.local in a browser or curl.

✅ Yes — You Can Use the hosts File on Windows:
The Windows hosts file is located at:

C:\Windows\System32\drivers\etc\hosts
You can add entries like:

127.0.0.1   vm1.local
127.0.0.1   vm2.local

Now you can access:
http://vm1.local:8080 → gets forwarded to VM1's internal port (e.g., 80)
http://vm2.local:8081 → gets forwarded to VM2's internal port (e.g., 80)

📌 Caveats & Important Notes:
Hostnames only map to IPs, not ports.

So vm1.local will resolve to 127.0.0.1, but you still need to specify the port in the browser unless you’re using the default port (80 for HTTP, 443 for HTTPS).

If you want http://vm1.local to work without a port, you'd need:

The forwarded port on host to be 80, e.g.: 127.0.0.1:80 → VM1:80

But then you can't reuse port 80 for other VMs, so it's a one-to-one mapping.

Binding services to 127.0.0.1 inside the VM would prevent this from working, as noted earlier.

🔄 Full Example:
🖥️ VM 1 (Ubuntu):
Running NGINX on port 80

Inside the VM, NGINX is listening on 0.0.0.0:80

VirtualBox port forward: 127.0.0.1:8080 → VM1:80

🪟 Windows hosts file:
127.0.0.1 vm1.local
✅ Access:
Open browser: http://vm1.local:8080 → works!

💡 Optional: dnsmasq or Reverse Proxy
If you’re trying to make this more scalable (e.g., route multiple names to different VMs or ports), you might look into:

A local reverse proxy (like nginx or Traefik) on the host routing based on hostname

A local DNS resolver like dnsmasq to add name-to-IP resolution with more flexibility

---

So long as you plan to keep it fairly basic, this should work for you, given that you don't mind specifying port.

You *can* use ports 80 and 443 and, by default, this shouldn't necessarily be an issue. It would only be a conflict if you have another program or service on your computer already utilizing those ports (80/443).

Using 80 or 443 would allow you to just specify the hostname you enter in the hosts file, without needing to specify a port. Without additional software (such as nginx), however, you can only map those ports once.

--
Scott Lopez
Email: [email protected]

On 7/21/2025 7:44 AM, [email protected] wrote:
Thanks!!

When using virtualization isn't the virtual host a different machine that the host so that do not share the same localhost?

Thanks!!
Keith.

On 2025-07-21 07:40, Stephen Partington via PLUG-discuss wrote:
This will break any software that wants to communicate with itself on
your local machine. And it would be a conflict because you would have
2 machines using the localhost IP address. but technically it's valid.
Just a conflict.

On Mon, Jul 21, 2025 at 10:34 AM Keith Smith via PLUG-discuss
<[email protected]> wrote:

Thank you all for your responses.

Someone suggested setting the virtual machine IP to the local host
IP of
127.0.0.1.

I use the Linux and Win hosts files to create a kind of local DNS.
I
use a private IP such as 192,168,20.65, making the hosts entry
"192,168,20.65<tab>example.internal".  I do not think an entry like
"127.0.0.1<tab>example.internal" would work.

I'm a PHP Dev and I know a bit of Linux so I am unqualified to say
if it
would be ok to use "127.0.0.1<tab>example.internal" in my hosts
files.

---
Lets ask ChatGPT
Prompt : would it be ok to use "127.0.0.1<tab>example.internal" in
my
windows and Linux hosts files?
Chat's reply:

Yes, it's perfectly okay to use:

127.0.0.1    example.internal

in your Windows and Linux hosts files — and you can absolutely use
a tab
character or spaces between the IP and the hostname. Both operating
systems support this.
✅ Valid Example

127.0.0.1    example.internal

or

127.0.0.1       example.internal

(both tab and spaces are fine)
📌 Important Notes:

.internal is valid for private/local use

Although .internal is not a public top-level domain, it’s
fine
to use on local networks or development environments.

Just avoid using real domains unless you own them.

No DNS lookup involved

When you map example.internal to 127.0.0.1, your system
will
skip DNS and directly resolve it to localhost.

Location of hosts file:

Windows: C:\Windows\System32\drivers\etc\hosts

Linux: /etc/hosts

Permissions:

You’ll need admin/sudo privileges to edit the hosts file
on both
systems.

🛠️ Use Case Example

Useful for local development:

127.0.0.1    mysite.local
127.0.0.1    admin.example.internal
127.0.0.1    php.test

You can now open http://example.internal in your browser, and it
will
route to your local server (e.g., Apache/Nginx on 127.0.0.1).

---
Chat says it is ok, however it seems to be just wrong!

It seems that some on the list are using VirtualBox on their daily
driver.  Given I use private IP addresses and non routable domains
maybe
it is ok.

I think all my LAMP configurations are name-based virtual hosting.
Given
this I can create a "shared hosting" type of configuration where
multiple virtual hosts use the sane IP address.

Other than running lots of stuff on Kubuntu, my daily, I wonder how
risky that would be virus running a separate box running VirtualBox
or
Proxmox,

Your thoughts?

Thanks!!
Keith

On 2025-07-16 13:20, Stephen Partington via PLUG-discuss wrote:
I would not do this in my situation, but if i had needs and the
desktop is the only thing i had to work with I would use docker or
a
VM in order to segment it afro my workstation/desktop

On Wed, Jul 16, 2025 at 4:57 AM Scott L. via PLUG-discuss
<[email protected]> wrote:

If it's bound to localhost (127.0.0.1[https://127.0.0.1]), is not
opening
listening ports externally (or said ports are blocked), and is
effectively walled off from the Internet, the risk is very low.

You could always block the program at the software level (and I
would),
but ideally you'd want to avoid forwarding any ports or allowing
external
(WAN) communication.

It's not unusual to run a web server on-demand, such as to
preview a
web
page you're coding (e.g., when utilizing a JS-based framework).
This

would be preferable to running it 24/7 if possible.

The weak point will probably be your router. Most consumer
routers
allow
you to manually forward ports (which you wouldn't want to do
here),
but
they'll also often automatically allow the program out via either
UPnP
and/or NAT-PMP (if requested).

If you know the program doesn't trigger that, or you've disabled
it,
you
should be fine. It's really a matter of segmenting it from the
Internet.
If you're confident that you can do that, then you should be
golden.

---
Scott Lopez
Email: [email protected]
Web: https://bio.neteng.pro
----------------------------------------

Jul 14, 2025 1:43:29 AM David Schwartz
<[email protected]>:

I found that article and forwarded it to Keith. It was
specifically
about setting up and running a local web service for your own
personal
needs. The guy was not a developer. In fact, a couple of things
he
said
he uses this for suggest just the opposite. He very briefly
mentions
external access, but that was clearly not the focus of the
article.

But I think Keith's question has to do with security
implications
of
running a local web service on your main machine for LOCAL use
at
localhost.

I’ve got a LAN at home and I’ve given some thought to what
it
would
take to run a server on one machine ONLY for internal access. I
almost
set it up at one point, but changed my mind, but I haven’t
ruled
it
out.

That article includes a single command you can run on a Mac to
turn on
your web server.

Windows includes IIS, and he shows how to activate it. Newer
versions
only install it if you request, and it’s easy to start it up
as
a
service.

But MAMP, WAMP, and similar solutions have been available for
about 20
years now and I haven’t heard much about any security issues
simply
from running them on localhost / 127.0.0.1[https://127.0.0.1] .

Is there anything to worry about?

-David Schwartz



On Jul 14, 2025, at 12:10 AM, Eric Oyen via PLUG-discuss
<[email protected]> wrote:

Honestly,
I would rather the web server be on it’s own dedicated vm
with
minimal
other services running and it’s own internal IP address on a
virtual
bridge answerable to the external ethernet interface. This is
actually
similar to what I ran post 2000 using VMWARE.
External ethernet card 1: unposted by host OS, linked to
OpenBSD
vm as
internet interface
2nd ethernet interface was attached to internal virtual bridge
that
was also connected as a second interface to the openBSD vm.
Host
OS
was linked to virtual bridge along with all other vm’s. This
way, all
instances and the host OS were protected behind the OpenBSD
instance
which acted as the firewall. One of those instances was a web
server
that hosted a simple website (one of the many things I tried to
learn
how to do).

At the time, that configuration for VMWare was not even
supported, let
alone documented. So, I had a pretty unique setup (and I did
document
it eventually and submitted it to the dev team at VMWare). Oh
man,
were they surprised.

-Eric
From the Central Offices of the Technomage Guild, Virtual
Environments
Coordinator Dept.


On Jul 13, 2025, at 3:00 PM, Keith Smith via PLUG-discuss
<[email protected]> wrote:

Hi,

A friend sent me an article about a guy that always configures
a
web
server on his desktop. I did some work with a guy who
configured
his
daily driver MAC as a web server and used it for development.

I'm running Kubuntu on my desk top and Ubuntu on my
virtualization.

I could configure my desktop as a web server.... however I an
not
so
sure I want to.

My main concern is security.

What are your thoughts?

Thanks!!

Keith
---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss

---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:




https://lists.phxlinux.org/mailman/listinfo/plug- discuss---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss

--
A mouse trap, placed on top of your alarm clock, will prevent you
from
rolling over and going back to sleep after you hit the snooze
button.

Stephen
---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss

--
A mouse trap, placed on top of your alarm clock, will prevent you from
rolling over and going back to sleep after you hit the snooze button.

Stephen
---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss


Attachment: OpenPGP_0x62A9F276DAD0BAC0.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss

Reply via email to