Accesing Linux localhost from Windows

Discussions related to using VirtualBox on Windows hosts.
Post Reply
Darktemplar
Posts: 9
Joined: 14. Apr 2021, 16:35

Accesing Linux localhost from Windows

Post by Darktemplar »

Hello,
I am trying to connect from my Windows host system to my localhost in a Linux guest. I tried setting to "nat adapter" in my machine but still doesn't work. I am working with Apache in my Linux Guest
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Accesing Linux localhost from Windows

Post by scottgus1 »

When looking to solve problems like this, pretend your VM is a separate computer next to your physical computer.

You need to access one computer's network services from another computer. This works best with a typical ethernet network between the computers.

See Virtualbox Networks: In Pictures. The easiest setup to put the VM in a typical network with the host is using Bridged or Host-Only.

NAT and NAT Network put a "router" between the VM and the host which can mess up DNS access from VM to host and causes the need for ports to be opened for the host to access the VM.
Darktemplar
Posts: 9
Joined: 14. Apr 2021, 16:35

Re: Accesing Linux localhost from Windows

Post by Darktemplar »

I used bridged option but still can't connect to my apache local host in linux. It works in the VM but the host can't reach there
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Accesing Linux localhost from Windows

Post by mpack »

The VM is effectively a separate PC attached via a switch. Why would "localhost" on the Windows host connect to an Apache server inside a different PC?

If I understand your problem then you need to find out what IP address has been assigned to the VM (I assume a DHCP server is present), then communicate using that (assumes you are using bridged, and a router is present to manage IP addresses).
Darktemplar
Posts: 9
Joined: 14. Apr 2021, 16:35

Re: Accesing Linux localhost from Windows

Post by Darktemplar »

Ok now i understand. I thought that vm could had same ip as the host so i could turn on apache server on linux and in host i could see it. Is there anyway to access to that server in my host system?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Accesing Linux localhost from Windows

Post by scottgus1 »

Darktemplar wrote:vm could had same ip as the host
This would be like two houses having the same street address: where does the mail get delivered? :lol:
Darktemplar wrote:Is there anyway to access to that server in my host system?
mpack wrote:you need to find out what IP address has been assigned to the VM
Let's see how your VM is networked:
Please right-click the VM in the main Virtualbox window's VM list, choose "Show in Explorer/Finder/File Manager". In the window that opens, zip the VM's .vbox file, and post the zip file, using the forum's Upload Attachment tab. (If you have a Windows host, please make sure all file extensions are shown, so you will be able to see the .vbox extension easier.)

Also, run ipconfig /all in the host's Command Prompt, and ip address or ifconfig in the VM's Terminal. Post the command outputs of both host and VM commands.
Darktemplar
Posts: 9
Joined: 14. Apr 2021, 16:35

Re: Accesing Linux localhost from Windows

Post by Darktemplar »

-------------------Command in host-------------------

C:\WINDOWS\system32>ipconfig /all

Configuración IP de Windows

Nombre de host. . . . . . . . . : DarkTemplar
Sufijo DNS principal . . . . . :
Tipo de nodo. . . . . . . . . . : híbrido
Enrutamiento IP habilitado. . . : no
Proxy WINS habilitado . . . . . : no

Adaptador desconocido WSSVPNTap0901:

Estado de los medios. . . . . . . . . . . : medios desconectados
Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : TAP-Windows Adapter V9
Dirección física. . . . . . . . . . . . . : 00-FF-A0-D0-53-41
DHCP habilitado . . . . . . . . . . . . . : sí
Configuración automática habilitada . . . : sí

Adaptador de Ethernet Hamachi:

Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : LogMeIn Hamachi Virtual Ethernet Adapter
Dirección física. . . . . . . . . . . . . : 7A-79-19-6F-4C-BE
DHCP habilitado . . . . . . . . . . . . . : sí
Configuración automática habilitada . . . : sí
Dirección IPv6 . . . . . . . . . . : 2620:9b::196f:4cbe(Preferido)
Vínculo: dirección IPv6 local. . . : fe80::d4ef:e1a1:bd47:49e5%12(Preferido)
Dirección IPv4. . . . . . . . . . . . . . : 25.111.76.190(Preferido)
Máscara de subred . . . . . . . . . . . . : 255.0.0.0
Concesión obtenida. . . . . . . . . . . . : martes, 4 de mayo de 2021 13:07:14
La concesión expira . . . . . . . . . . . : miércoles, 4 de mayo de 2022 13:07:13
Puerta de enlace predeterminada . . . . . : 2620:9b::1900:1
Servidor DHCP . . . . . . . . . . . . . . : 25.0.0.1
IAID DHCPv6 . . . . . . . . . . . . . . . : 939675890
DUID de cliente DHCPv6. . . . . . . . . . : 00-01-00-01-27-2E-9C-AA-2C-F0-5D-77-DE-72
Servidores DNS. . . . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS sobre TCP/IP. . . . . . . . . . . : habilitado

Adaptador de Ethernet Ethernet:

Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : Realtek PCIe 2.5GbE Family Controller
Dirección física. . . . . . . . . . . . . : 2C-F0-5D-77-DE-72
DHCP habilitado . . . . . . . . . . . . . : sí
Configuración automática habilitada . . . : sí
Vínculo: dirección IPv6 local. . . : fe80::ec89:9079:6514:fb7d%2(Preferido)
Dirección IPv4. . . . . . . . . . . . . . : 192.168.1.48(Preferido)
Máscara de subred . . . . . . . . . . . . : 255.255.255.0
Concesión obtenida. . . . . . . . . . . . : martes, 4 de mayo de 2021 13:11:28
La concesión expira . . . . . . . . . . . : miércoles, 5 de mayo de 2021 1:11:27
Puerta de enlace predeterminada . . . . . : 192.168.1.1
Servidor DHCP . . . . . . . . . . . . . . : 192.168.1.1
IAID DHCPv6 . . . . . . . . . . . . . . . : 53276765
DUID de cliente DHCPv6. . . . . . . . . . : 00-01-00-01-27-2E-9C-AA-2C-F0-5D-77-DE-72
Servidores DNS. . . . . . . . . . . . . . : 80.58.61.250
80.58.61.254
NetBIOS sobre TCP/IP. . . . . . . . . . . : habilitado

Adaptador de Ethernet Ethernet 2:

Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter
Dirección física. . . . . . . . . . . . . : 0A-00-27-00-00-19
DHCP habilitado . . . . . . . . . . . . . : no
Configuración automática habilitada . . . : sí
Vínculo: dirección IPv6 local. . . : fe80::5579:fb61:a1cb:a781%25(Preferido)
Dirección IPv4. . . . . . . . . . . . . . : 192.168.56.1(Preferido)
Máscara de subred . . . . . . . . . . . . : 255.255.255.0
Puerta de enlace predeterminada . . . . . :
IAID DHCPv6 . . . . . . . . . . . . . . . : 1124728871
DUID de cliente DHCPv6. . . . . . . . . . : 00-01-00-01-27-2E-9C-AA-2C-F0-5D-77-DE-72
Servidores DNS. . . . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS sobre TCP/IP. . . . . . . . . . . : habilitado

Adaptador de LAN inalámbrica Wi-Fi:

Estado de los medios. . . . . . . . . . . : medios desconectados
Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : Intel(R) Wi-Fi 6 AX200 160MHz
Dirección física. . . . . . . . . . . . . : 34-CF-F6-29-A1-3A
DHCP habilitado . . . . . . . . . . . . . : sí
Configuración automática habilitada . . . : sí

Adaptador de LAN inalámbrica Conexión de área local* 2:

Estado de los medios. . . . . . . . . . . : medios desconectados
Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #3
Dirección física. . . . . . . . . . . . . : 34-CF-F6-29-A1-3B
DHCP habilitado . . . . . . . . . . . . . : sí
Configuración automática habilitada . . . : sí

Adaptador de LAN inalámbrica Conexión de área local* 12:

Estado de los medios. . . . . . . . . . . : medios desconectados
Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #4
Dirección física. . . . . . . . . . . . . : 36-CF-F6-29-A1-3A
DHCP habilitado . . . . . . . . . . . . . : no
Configuración automática habilitada . . . : sí

Adaptador de Ethernet Conexión de red Bluetooth:

Estado de los medios. . . . . . . . . . . : medios desconectados
Sufijo DNS específico para la conexión. . :
Descripción . . . . . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
Dirección física. . . . . . . . . . . . . : 34-CF-F6-29-A1-3E
DHCP habilitado . . . . . . . . . . . . . : sí
Configuración automática habilitada . . . : sí

-------------------Command on VM-------------------

 ╱  ~  ifconfig  ✔ ╱ 13:42:48 
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::8950:e8f9:f183:bb98 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:08:67:03 txqueuelen 1000 (Ethernet)
RX packets 15 bytes 2440 (2.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 65 bytes 7077 (7.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Bucle local)
RX packets 40 bytes 3860 (3.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 40 bytes 3860 (3.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Attachments
linux mint.zip
.vbox file
(2.6 KiB) Downloaded 8 times
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Accesing Linux localhost from Windows

Post by scottgus1 »

Sorry for the delay getting back to this, had some projects going.

Your VM is set to NAT, and is receiving the usual NAT IP address. See the "In Pictures" link above, it explains what happens when your VM is set to NAT.

To use NAT and communicate with the VM from the host, you must open ports in the NAT interface.

Or switch to Host-Only, if the VM only needs to talk to the host. Use Bridged if the VM needs to talk to the host and the internet. Neither Host-Only nor Bridged require ports to be opened in Virtualbox.
Darktemplar
Posts: 9
Joined: 14. Apr 2021, 16:35

Re: Accesing Linux localhost from Windows

Post by Darktemplar »

i set it to bridged but i don't find where to opeen ports
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Accesing Linux localhost from Windows

Post by scottgus1 »

Darktemplar wrote:i set it to bridged but i don't find where to opeen ports
scottgus1 wrote:Neither Host-Only nor Bridged require ports to be opened in Virtualbox
Post Reply