There are a number of different ways that local websites can be viewed from other computers (running Windows, Mac OS X, Linux) and mobile devices (iPads, iPhones, Android phones, etc), that are all connected within the same LAN (local network).
To get every LAN connected computer and mobile device to find and connect to a local website, you have these options:
Use the LAN IP of Server
Connect directly to the server via its LAN IP address, using that IP in the URL:
For this to work, the LAN IP address must be assigned as one of the website’s Domain Aliases, and all redirects from Aliases to the Primary Domain Name must be turned off.
Downside – as only 1 IP address is assigned per NIC (network card), only 1 website can be accessed.
Use the LAN host-name of Server
Connect to the server via its LAN host-name (computer name), using that host-name in the URL:
For this to work, the LAN host-name must be assigned as one of the website’s Domain Aliases, and all redirects from Aliases to the Primary Domain Name must be turned off.
Downside – as only 1 host-name (computer name) is assigned per computer, only 1 website can be accessed. Also, there might be issues with some non-Windows devices, such as the iPad, which either don’t inter-operate (work with) WINS and NetBIOS or require further configuration.
Use a LAN-wide Hosts file Set Up
Connect to the server by using LAN-wide (global) Hosts files…
This is done by editing every LAN systems’ Hosts file with entries that resolve each and every website’s domain-name and aliases to the LAN IP of the server:
192.168.1.100 www.domain1.name domain1.alias1 domain1.alias2 192.168.1.100 www.domain2.name domain2.alias1 domain2.alias2 192.168.1.100 www.domain3.name domain3.alias1 domain3.alias2
This way all the other LAN systems know to which IP address to send the request to when the
www.domain.name is used in the local Browser.
Downside – while this will work on Windows, Linux, and Mac OS X, this will not work on most mobile devices unless they are jail-broken / rooted (as you can’t edit their Hosts file).
Hosts file path:
Use Registered Domain Names
Connect via any website’s domain-name, as long as that domain-name is:
- Registered (bought and paid for on Namecheap, GoDaddy, etc)
- And has a DNS “A” record set (resolved) to either the LAN IP of the server (ex: 192.168.1.100) or the Public IP of the Router (via the domain Registrar’s DNS servers).
* It’s perfectly valid to resolve a domain-name to a local LAN IP address.
If you only have 1 registered domain name, you can use its sub-domains to represent your different local websites, by using a wild-card (*) / catch-all DNS record. This way all
*.domain.name requests, regardless of what they are, will always be resolved to your LAN IP or Public IP. And once that request reaches your web server, the web server will match the
sub.domain.name to the proper website. The downside of this is that every website’s domain-name must use a common base (which can make the full address long).
Use a WiFi Router that’s capable of DNS Masquerading
Both OpenWRT and DD-WRT are able to inject custom domain-name to IP address resolves via their own internal Hosts files and/or internal bundled DNS Masquerading software such as DNSmasq.
This is probably the best option as ALL WiFi connected computers (regardless of OS) and mobile devices (everything from iPads to Android phones) will be able to connect to each and every website… Without configuring anything or doing anything to those computers and devices.
Use Own DNS Servers
Local networks (that are behind a typical wifi Router) use outside DNS servers, which “resolve” (convert) domain names to IP addresses.
Typically, the Router gets the addresses of 2-4 DNS servers from your Internet Provider (via a protocol called DHCP), and acts as the middle-man, for domain name resolve requests, between the computers and devices within the LAN, and the external DNS servers.
These external DNS servers are unable to answer and resolve requests for your “virtual” (non-registered) domain names to your locally hosted websites and their LAN IPs.
You can however, via your Router settings, switch-over these DNS servers with your own local DNS server, which will be able to resolve all “virtual” (fake) domain names, and wildcards (ex: *.local), to the server’s LAN IP address.
There are several options for DNS Servers for Windows, and Linux.
On some mobile devices, you can set them to use an HTTP Proxy server, that will then custom-resolve the domain-name to the LAN IP address. This gets around the problem of not being able to edit the device’s Hosts file without jail-breaking or rooting it. But you’ll need one Linux PC or VM running the proxy server software.
Mobile devices have to be connected to your WiFi to be able to access the server via the LAN IP address. Otherwise, you must use a registered domain-name that has a DNS record resolving the domain-name to the the Public IP of the Router (which then “port-forwards” from WAN:80 to LAN:80 of server).
LAN IPs are usually reassigned/changed after reboot or power-off of the LAN connected computers and devices and/or the Router. You’ll have to go into the Router’s configuration and settings, and make sure to manually assign the same LAN IP to the same LAN system (by assigning that LAN IP to the server’s MAC address).
When a request comes in to the web-server for a domain-name or IP address that is not assigned to any website, the first Apache Virtual Host (DefaultWebsite, localhost) gets returned.
When accessing the server directly via an IP address, you’ll only be able to access 1 website (the website that has that IP assigned as a Domain Alias)… Unless you run each website on a separate port number (8080, 8081, etc). *Some Apache configurations/setups and some PHP web-app scripts might not work correctly, as they expect regular port 80 access.
While most mobile devices OS (iOS, Android) has a Hosts file, those devices have to be jail-broken/rooted, and/or you have to go through complicated steps to modify their Hosts file.
Running your own DNS server is not recommended as it could be complicated to set up and operate, and the system it’s on has to always be On for everything else to work. If you do run your own DNS, you’ll need to set it’s LAN IP in the Router’s settings and make sure no other DNS servers are used (by the Router). DNSMasq is the recommended choice.
You can host multiple websites under 1 main domain-name/website by treating the other websites as folders: C:\WampDeveloper\Websites\main.domain.name\webroot\other.domain\
* Make sure to turn off any redirects of the Domain Aliases to the Primary Domain Name (*select website in WampDeveloper’s Websites Tab, click Settings; or just create a website with the LAN host-name as the Primary Domain Name, and the LAN IP as one of the Domain Aliases).
* Make sure to open (on the web-server) the Windows Firewall inbound port 80 (http) and 443 (https) connections (TCP and UDP). Windows Firewall will block these by default.
* If you are resolving domain-names to the Public IP (of the Router), make sure to update the Router’s settings to “port forward” incoming port 80 (http) and 443 (https) requests to the proper LAN IP of the web-server.