Friday, February 17, 2012

Dynamic DNS and Port Forwarding Revisited

After several years of supporting our Live Cams products we still find that Dynamic DNS and port forwarding is the biggest challenge for most people to understand.

Let's explain some basics first:

WHAT IS THE DIFFERENCE BETWEEN A HOST, AN IP ADDRESS AND A PORT?
Devices on your home network use a combination of IP addresses (unique numbers) and ports (a number specifying a "connection point" to a service from a device).

For example, your router might have an IP address of 192.168.1.1 and your computer or laptop might be 192.168.1.2

On your computer you could be running a website on port 80, an FTP server (file transfer service) on port 27 and a copy of WebcamXP for viewing your USB webcam. WebcamXP can be configured to broadcast the webcam via an internal web server on port 8080. These addresses would look like this in a browser window:

Website - http://192.168.1.2
FTP Server - ftp://192.168.1.2
WebcamXP - http://192.168.1.2:8080

Note that the third address shows ":8080" to specify the port of 8080 for WebcamXP. We could use ":80" on the first address but internet standards assume that "HTTP" services use a default port of 80 if it is unspecified. This is the same for FTP. If a port is not specified then the FTP services use a default of 27. As confusing as this sounds it simply means that you can skip the ":80" or ":27" to save some typing.

Now let's throw an IP camera into the mix. Let's pretend that it gets an IP address of 192.168.1.3

You can reach the camera in your browser via http://192.168.1.3 (or http://192.168.1.3:80)

EXTERNAL ACCESS
How do we get both WebcamXP and the IP camera to be available from another network? What if you go to work and want to connect to your laptop camera or view the video from the IP camera?

The answer: port forwarding.

Your router actually has TWO IP addresses. One is the internal address (or local address) which works within your home network. This is the 192.168.1.1 value. The second IP address is usually called the WAN address (or external address). This could be any number, like 99.249.3.123
The WAN address is registered with external name servers and routers and is reachable from anywhere in the world. The 192.168.1.1 address will not work unless you are connected to the router on your home network.

We need to be able to reach your router and then pass through it to either your computer or the IP camera. We could get to the router by typing http://99.249.3.123 but this would ask us to log into the router and not the software or camera that we want.

Port Forwarding is the process of configuring "services" on your router that are simply passthroughs to other devices and services on the network. Let's set up ports on the router that will pass data through to our two video sources.

For the WebcamXP instance we'll set up port 3000 (randomly selected number, high enough to avoid conflict with commonly used ports).

On the router you will need to find the port forwarding setup page. Set up a rule so that any data on external port 3000 (your router) is forwarded to a local IP address of 192.168.1.2 (your computer) on port 8080 (WebcamXP). If asked for either TCP, UDP or Both you can select TCP or Both.

That's it! You've just poked a "hole" through your router and firewall so that when someone types "http://99.249.3.123:3000" it magically passes the request through to "http://192.168.1.2:8080". From all appearances you will be staring at the WebcamXP web interface as if it actually lives at the address you typed.

Repeat the process for the IP camera by setting up port 3001 (TCP or Both) on your router so that it is forwarded to the IP camera at 192.168.1.3 on port 80.

Now you can type "http://99.249.3.123:3001" and it should pop up the login screen for your IP camera.

Dynamic DNS is the next step, which simply gives the router's ugly WAN address a nice name so that you don't have to type 99.249.3.123 (or memorize it). It would be simpler to call it "mycamera.home-ip.net". In this case you can type "http://mycamera.home-ip.net:3001" and the browser will pass through your router on port 3001 and end up at your camera with a local address of 192.168.1.3 and port 80. Magic, but VERY CONFUSING :)

It should be very clear however that by doing this you are exposing your computer or camera to the internet (necessary if you wish to reach it from anywhere in the world). You should ABSOLUTELY take steps to assign usernames and passwords to the software and devices on your network. If you leave your IP camera unsecured then you can expect to see web crawlers and unexpected visitors connecting to it from time to time.