DEV Community

alok-38
alok-38

Posted on

How to Access Nginx Homepage on Your Smartphone from an Ubuntu VM

🧪 Accessing Nginx from Mobile: Full Journey

Accessing your Nginx web server from a smartphone might seem tricky at first, especially when it’s running inside an Ubuntu VM on VMware. Whether you’re experimenting with web development, learning DevOps, or just testing your local projects, being able to view your Nginx homepage on any device is a crucial skill. In this guide, we’ll walk you through every step — from setting up the VM’s network correctly, configuring Nginx, and troubleshooting connectivity issues, to finally accessing your server from a phone or other devices on the same network. By the end, you’ll understand how LAN networking, private IPs, and bridging work in practice, and you’ll be confidently serving your Nginx pages across multiple devices.

💻 Tech Stack

  • Virtualization: VMware Workstation

  • Guest OS: Ubuntu (any recent LTS, e.g., 22.04)

  • Web Server: Nginx (latest stable)

  • Networking:

    • Bridged networking (VMnet0)
    • Host firewall: UFW (Ubuntu)
    • LAN access for devices on same Wi-Fi
  • Host OS: Windows 10/11 (used to SSH and browser test)

  • Client Devices:

  • Windows browser (Chrome/Edge)

  • Smartphone (iOS/Android) on same Wi-Fi

  • Optional Tools:

  • SSH (PowerShell or terminal)

  • curl (for local testing)

  • ngrok / localtunnel (if exposing Nginx outside LAN)

1️⃣ Initial Attempt

Observation: Windows can access VM (same host), phone cannot.


2️⃣ Diagnosing the problem

  • ping 192.168.45.100 from Windows host → timed out at first when NAT IP was used with earlier network misconfiguration.

  • ssh alok@192.168.45.100connection timed out

  • hostname -I on Ubuntu VM showed both NAT and Bridged IPs after some bridging attempts:

192.168.45.100 192.168.0.169
Enter fullscreen mode Exit fullscreen mode
  • ip route showed default via NAT: 192.168.45.2

Conclusion:

  • The VM had two IPs and the default route pointed to NAT, so devices outside Windows host could not reach the VM.

  • Network was inconsistent due to VMware NAT + Bridged mix.


3️⃣ Switching to Bridged networking

  • In VMware Workstation:

    • Network adapter set to Bridged (explicit Wi-Fi adapter selected)
    • ✅ “Replicate physical network connection state” checked
  • Virtual Network Editor checked:

    • VMnet0 → Bridged → Wi-Fi adapter
    • VMnet1 → Host-only → ok
    • VMnet8 → NAT → not used

Observation:

  • Ubuntu still had old NAT IP (192.168.45.100)

  • Default route still pointed to NAT

  • Windows host could reach Bridged IP (192.168.0.169), but the phone could not because it was on mobile data.


4️⃣ Cleaning up Ubuntu network

  • Removed NAT IP:
sudo ip addr del 192.168.45.100/24 dev ens33
Enter fullscreen mode Exit fullscreen mode
  • Deleted old default route (if present):
sudo ip route del default via 192.168.45.2
Enter fullscreen mode Exit fullscreen mode
  • Renewed DHCP to get proper LAN IP:
sudo dhclient -v -r ens33
sudo dhclient -v ens33
Enter fullscreen mode Exit fullscreen mode
  • Verified with:
hostname -I
ip route
Enter fullscreen mode Exit fullscreen mode

Result:

192.168.0.169
default via 192.168.0.1 dev ens33
Enter fullscreen mode Exit fullscreen mode
  • Clean, single IP on LAN → default route correct.

5️⃣ Testing Nginx from Windows

  • http://192.168.0.169 → Nginx default page loads ✅

Observation: Works on Windows because host and VM are on same LAN/subnet.


7️⃣ Solution: phone must be on same LAN

  • Connected phone to same public Wi-Fi as laptop/VM

  • http://192.168.0.169 on phone → works

Explanation:

  • Both phone and VM are now on same subnet

  • Phone can send packets directly to VM

  • Nginx responds → page loads


8️⃣ Key Networking Lessons

Symptom Cause Fix / Concept
Page loads on Windows, not phone Phone on different network (carrier) Connect phone to same Wi-Fi
VM has two IPs (192.168.45.x + 192.168.0.x) NAT + Bridged overlap Remove NAT IP and renew DHCP
SSH/ping fail Wrong default route Reset default route to LAN gateway
Page loads on LAN only Nginx listens on all interfaces Ensure 0.0.0.0:80 in Nginx

Important Concepts:

  • NAT vs Bridged

    • NAT → VM hidden behind host → only host can reach VM
    • Bridged → VM is like a real LAN computer → any device on LAN can reach
  • Private IPs are local

    • 192.168.x.x not routable over internet → devices outside LAN cannot reach
  • Default route matters

    • All traffic leaves via default gateway → stale NAT route breaks connectivity

✅ Optional: Access VM outside LAN

  • Use a tunneling tool like ngrok or localtunnel

  • Port-forward on your router to make VM public (not recommended for public Wi-Fi)

Nginx worked from Windows because host and VM shared the LAN; it failed on the phone because the phone was on a different network. Connecting the phone to the same Wi-Fi brought it into the same subnet, making the VM reachable.

Top comments (0)