Solving IP loopback problem
Posted by Wesley on
[Related to: Use Mac as a Web Server]
Your Mac, which is also the webserver, is behind a router. You enter your website's domain name on your web browser. You cannot connect. You can still connect via your internal IP address, so the webserver is not down. What gives? Here's what might be happening.
Your Mac, which is also the webserver, is behind a router. You enter your website's domain name on your web browser. You cannot connect. You can still connect via your internal IP address, so the webserver is not down. What gives? Here's what might be happening.
If you're running your computer as the webserver behind a router, and if the router cannot 'loopback' to its own IP address, you might not be able to access your own website on your own computer under the domain name you registered. Since the IP address that the domain name is tied to is the external (i.e. router's) IP address, and your router cannot loopback to itself and let you access the internal address by that address, entering the domain name on your web browser in attempt to access your own website will end in failure.
So how do you configure your Mac so you can connect to your own website by the domain name? Here's a very good tip that gray, an ArsTechnica OpenForum member, wrote about.
What we need to do is modify some information on NetInfo. There is a graphical version and a command line version. In this case doing it on command line is simpler and quicker. Open up Terminal and type this (it's in ONE LINE):
sudo nicl . -create /locations/lookupd/hosts LookupOrder CacheAgent NIAgent FFAgent DNSAgent
Be careful, as that's N-I-C-L, nit N-I-C-1. And yes, there's a period between that and -create. What this basically does is to re-order the priority of the lookup daemon so that it checks NetInfo before DNS. This has to be done correctly if the next line is going to work. Type this now:
sudo nicl . -create /machines/localhost name localhost mydomain
Replace mydomain with your website's domain name (e.g. tool-box.info). If you want to add more domain names, add at the end of the line separated by blank. What this does is to add your domain name as an alias to the localhost hostname. In other words, when you enter your domain name on your web browser, it will be treated like entering 'localhost', and you will immediately be connecting to your website.
We're not quite done yet, though. We need to have the lookup daemon recognize these changes. Type like this:
sudo kill -HUP 'cat /var/run/lookupd.pid'
You should now be able to access your website via your web browser using the domain name. This is useful, and may be necessary in many occasions, as you need to enter the domain name information in configuring such systems as phpBB or s9y.
Later on, if you want to add/change/delete the domain name, you can run the NetInfo Manager and do it graphically. Run the application and unlock (click the lock and enter the admin password). Go in the order of '/ - machines - localhost'. Click the triangle next to the 'name' at the bottom pane to reveal the values. To edit an existing entry, double-click on the value you want to edit. To add a new entry, choose 'Directory - Insert Value' from the menu. To delete, choose 'Directory - Delete Value'.