How to access localhost from VirtualBox using a smartphone?

2

1

I want to access VirtualBox's localhost using a smartphone for me to see how the website looks like in a phone.

More Details:

  • Host OS - Windows 7 Pro
  • Guest OS - Ubuntu 16.0.4 LTS
  • SmartPhones' OS - Android and iOS

Dumb Question

Posted 2017-04-18T07:58:56.363

Reputation: 39

You can configure port forwarding on Virtualbox, and then connect to the IP of your Windows 7 machine using your smartphone (via a wifi connection or similar). – user2064000 – 2017-04-18T08:01:28.203

do you know or do you have a tutorial of how I can do it? – Dumb Question – 2017-04-18T08:03:34.007

Answers

3

You actually shouldn't need this, most browsers have a "responsive design view mode" which you can activate by pressing F12 to activate the developer console and clicking on the mobile phone/tablet icon on the left of it.

But to answer your question, yes, this can be done through port forwarding.

  • Go to the settings for the Ubuntu VM, and select the "Network" tab.
  • Make sure that the "Attached to" value is "NAT".
  • Click on the "Advanced" dropdown and click on the "Port Forwarding" button.
  • Click on the "+" symbol to add a port forwarding rule. Say, you have a server running in Ubuntu in port 80, so enter 80 in the "Guest Port" value. Now, say, you want to access the server on port 8080 of the host machine, so type in 8080 for the "Host Port" value.
  • Click on "OK" on the windows to save your settings.

At this point, you can access your server on your host machine by typing in localhost:8080.

To open it on your phone, connect the phone and the computer on the same network (such as a WiFi hotspot). Determine the local IP address of your computer with ipconfig /all. For example, if the IP is 192.168.1.1, type in 192.168.1.1:8080 on your phone.

user2064000

Posted 2017-04-18T07:58:56.363

Reputation: 1 326

Hi, do you know how I can access the phpmyadmin in the host machine? It gives me forbidden error. Thanks! – Dumb Question – 2017-06-27T01:46:14.680

Really useful, just don't forget to (disable the guest firewall or) add a rule on the guest firewall to allow incoming traffic from the host OS or any other device connected to the WiFi. – Jesús Hagiwara – 2019-05-30T02:44:25.560