Understanding DynDNS

Loopback Connections

A common problem that some customers encounter when using a NAT router is that they want to be able to access their web site from within their local network, but their NAT router does not support “loopback” connections. This prevents them from being able to reach their own services, even though external visitors are able to connect.

The Problem

Let’s say, for example, that we have a local network consisting of two machines behind a NAT router with the router in turn connected to a DSL or Cable modem. Each of the two machines will be assigned an IP address by the NAT router within a “local” IP space such as the 192.168 block. The NAT router in turn is assigned an IP address by the ISP within the “public” space. When you setup a host or domain within our system, it is this public IP address that the host/domain points to.

The following diagram shows the example network’s two computers behind a NAT router:

image014

In this diagram, the “public” address is 65.54.43.32 and the NAT router has a LAN/”private” address of 192.168.0.1. The other computers on the network are assigned numbers within this private space.

Now, let’s say that we have registered the domain “example.com” with the host “www.example.com” mapped to this public IP address. When somebody out on the internet attempts to connect to www.example.com, they end up connecting to the WAN interface on the NAT router. The NAT router in turn “routes” the packets to an internal machine based on the port that the connection came in on.

The loopback problem arises when somebody using the “Work Station” computer wants to access the “Web Server” computer. If they try to access the computer via the hostname www.example.com, the NAT router will attempt to route this out its WAN interface and then back in. In most cases this will either fail or return the web interface for the router itself because the router doesn’t understand what the user is trying to do.

The Solutions

Configure port forwarding

First, before trying any other solutions, you should configure port forwarding on your router. Some routers experience loopback errors until the correct ports are forwarded, especially when running a webserver. By adding an entry on port 80, your router will be correctly configured to allow access to your webserver. You can learn more about routers and port forwarding here, and visit PortForward.com for detailed guides on how to configure your router’s forwarding features.

Check security settings

Some routers also have security options that cause the loopback error to occur. Check your router’s settings for references to local connections, loopback connections, NAT redirection, and so on, then toggle them to see if this fixes the issue. The WRT54G, for example, has a variety of security checkboxes on its Security tab, one of which disables NAT redirections – and therefore causes loopback errors.

Modify your HOSTS file

If you have ensured the port forwarding in your router is correct and have enabled loopback redirections in the router’s configuration, the device may be incapable of performing loopback connections properly. If this is the case, you can edit your HOSTS file on the local computers in your network to circumvent the problem. The HOSTS file is a legacy file from the days of ARPANET, before DNS existed, where users had to download latest list of networked machines. (You can learn more here.)

On a standard UNIX/Linux system (including Apple’s Mac OS X) the HOSTS file will generaly be found at

        /etc/hosts

On Windows systems the location of this file varies.

  • Windows 9x – (x):\Windows\Hosts
  • Windows XP – (x):\Windows\System32\Drivers\etc\Hosts
  • Windows 2000 – (x):\WinNT\System32\Drivers\etc\Hosts

Regardless of the system, the format of this file should be essentially the same. Using the above network example you would want to add the following lines to this file:

        192.168.0.1    router.example.com
        192.168.0.2    www.example.com
        192.168.0.3    foo.example.com

Now, any time you use a web browser or any other application to connect to www.example.com, the hostname will resolve locally via the HOSTS file instead of resolving via the DNS and you’ll connect via the local IP address. At the same time, anyone not on your network will continue to use DNS to resolve this hostname and will connect via the public IP address.

(Note: If you use Spybot-Search & Destroy or other anti-spyware applications, you may notice hundreds or even thousands of entries in your HOSTS file set to 127.0.0.1. These entries protect you from accidentally visiting malicious websites by redirecting your connection to your own machine instead of the potentially dangerous external server. You may safely ignore these entries.)

Dynamic DNS, Apache, and Windows

Instead of paying for web hosting, you can run your own web server on your own cable or DSL line on your home computer. Since many ISPs do not offer static IP addresses or charge extra, you can setup dynamic DNS through DynDNS.com to achieve the same result. You can then give your friends or anyone else the hostname and they should always be able to access your website.

Most people use Windows for an operating system but that doesn’t mean you cannot run an industrial strength webserver, Apache. Apache is the most installed and popular web server and there is a lot of help out there if you get stuck.

Once you install your web server, you can host your own web site, host your MP3 files, allow friends and co-workers to view documents, share pictures, and plenty of other things.

Dynamic DNS And Customs DNS

DynDNS.com offers two flavors of dynamic DNS. One is Dynamic DNS (clever name) and the other is Custom DNS. Dynamic DNS allows you have a hostname like yourname.dyndns.org always point to your IP address. Custom DNS allows you to setup a domain, like www.yourname.com to point to your IP address. Custom DNS is a paid service and Dynamic DNS is free. Setup is pretty easy and you can use our Custom DNS How-To or our Dynamic DNS How-To.

Web Server : Apache

Once dynamic DNS is setup, we know the hostname of our web site. Where we use  yourhost.dyndns.org, replace that with the actual host you created.

Installing the server

  • Go to http://httpd.apache.org/download.cgi and download the latest version of Apache using the “Win32 Binary (MSI Installer)” link.
  • Accept the agreement and use the default location for installation.
  • Once you reach the screen asking for your server information, enter the information as follows:

Network Domain (e.g somenet.com): dyndns.org

Server Name (e.g. www.somenet.com): yourhost.dyndns.org

Administrator’s Email Address (e.g. webmaster@somenet.com): youremailaddress

  • At the bottom, select for All Users and then click on Next.
  • Complete the installation wizard using the “Typical installation” setting.
  • When it’s done, open your web browser and go to http://localhost/. If the page you see reads, “If you can see this, it means that the installation of the Apache web server software on this system was successful,” you installed Apache.

Storing files in the right place

Let’s say you have a slew of pictures from your vacation and you want to share them on your shiny new web server. I store my pictures in C:\RecentPics so I’ll use that in this sample.

Configuration

Using a plain text editor like Notepad, open the C:\Program Files\Apache Group\Apache2\conf\httpd.conf file. This is Apache’s configuration file. Don’t be alarmed. It looks worse than it is and we are only going to change a couple things and leave the rest as their defaults.

In this httpd.conf file, comment out the line that starts with DocumentRoot and add another with your directory, like this:

#DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
DocumentRoot "C:/RecentPics"

Then, comment out the line that starts with <Directory "C:/Program...> and add another with the directory you want to share:

#<Directory "C:/Program Files/Apache Group/Apache2/htdocs">
<Directory "C:/ RecentPics">

Last, about 20 lines below that <Directory> line, then modify that to read (this allows file listing):

#AllowOverride None
AllowOverride All

When you’re done, save httpd.conf.

Start it up

Click on the Apache icon in your taskbar and choose “Restart.” If Apache restarts successfully, you edited your the file correctly. Visit http://localhost/ in your web browser and you should see a list of your pictures!

Troubleshooting

If you can not connect to your server using the addresses above, you need to check the following:

  • Make sure yourhost.dyndns.org is pointing to the external IP, the one your ISP has assigned you. If not, log in and update it. You won’t be able to access the host from inside your network if you are behind a router.
  • Check with your router manufacturer to see if you are forwarding port 80 properly
  • Make sure no firewall is blocking access
  • Contact your ISP to see if they are blocking port 80. If they are, try our HTTP redirection, WebHop

Leave a Reply