Tech Notes

Tech Note #20120001

It is possible to implement low-volume Web sites or other services, that are available to Internet users, on small office or home systems which are connected to the Internet through cable, DSL, fiber or even dialup connections. However, since these types of connections are usually dynamic in nature and are seldom assigned a static IP address by the ISP, the problem becomes how to advertise the assigned IP address so that the Internet users can find the system.

Problem Description:

The user wishes to implement a low-volume Web site, using ISS or Apache, for example, on their small office or home computer. Or, they wish to implement a Web service (such as temperature/power monitoring or remote control of their DVR).

There is nothing intrinsic in Unix/Linux or Windows that precludes them from doing so. It is only the fact that the WAN IP address that the Internet users must use to access the Web site/Web service must be advertised to the world so that they can find the small office or home computer. This is because the types of Internet connections employed by such computers are not usually assigned static addresses by the ISP. Rather, a dynamic address is often assigned from the ISP's pool of IP addresses and it may change over time, as the connection is renewed.

Advertising the WAN IP address in such a way that the Internet users can easily find it is not a problem. There are an ample number of dynamic DNS services available which allow one to dynamically associate a current WAN IP address with a static name that can be looked up through DNS. Many of them offer simple programs, that can be run from a script which is executed whenever the link is brought up, or at regular intervals via cron, which will set the current WAN IP address. It is merely a matter of calling the program with the correct IP address.

If your small office or home computer's Internet connection is made via PPP, it is easy to just look at the "other" end of the PPP connection (e.g. using ifconfig) to get the WAN IP address. On the other hand, if your computer's Internet connection is through an edge router (typically supplied by the ISP, to connect your network directly to their DSL, fiber, cable, etc. plant), this edge router will often negotiate the connection with the ISP whenever it feels like it and when the WAN IP address changes, your computer will receive no notification whatsoever. In fact, the address is probably obscured by the router in such a way as to make it impossible to query the WAN IP address.

The problem then becomes how to obtain the assigned WAN IP address.

Problem Resolution:

Fortunately, there are more than a few Web sites that will echo a client's IP address back to them. The solution to the problem is a Perl script that sends a page request to one or more of these sites, from the small office or home computer, and retrieves the Web page containing the WAN IP address. The page is parsed and the IP address extracted. This address can then be advertised to your Internet users via whatever dynamic DNS service that you deem appropriate. The fact that an external, Internet-based Web site is used to look up the IP address is no hardship, in this case, since the whole point of this exercise is to connect to the Internet anyway.

There are a number of open source programs, that purport to solve this problem, available on the Internet. Unfortunately, none of them seems to be a reasonable solution. Firstly, many of them are pre-compiled source that will only run on Windoze. Yeah, we know that most of you are implementing your Web sites under IIS on Windoze and would never want to run Apache on a Linux box so this is perfectly acceptable but, secondly, there may be many occasions where you don't want to use the pre-defined Web pages to look up your WAN IP address, or, worse yet, cannot. Then, where are you?

Our solution is a Perl script that will run anywhere that Perl (and a few Internet support modules) are installed. We run it on both Linux and Windoze but it will probably do just as well on a Mac or any other system that you can think of (Perl is everywhere). And, the list of Web pages (currently six) that we use to look up WAN IP addresses can easily be altered by you to use Web sites that are closer to you or just not blocked. Parsing of the returned page is easily tailored by adding a regular expression to the list of parser strings.

The source (a single file) is packaged as a gzipped file that can be downloaded here. You can simply cut and paste the source, if your browser unzips the file and displays it as a Web page, or you can right click on the link and save the gzipped file directly.

To install the Perl script, unzip it and copy the file to a convenient spot. Then, either run it from your /etc/ppp/ip-up.local script or invoke it at regular intervals from a script that is run by cron or via a scheduled job (on Windoze). The Perl script itself has more notes about how to install it.

The script that invokes it will need to do something with the returned IP address, to push it out to one of the dynamic DNS services but that part should be simple. For example, if you are using no-ip as you dynamic DNS service, these two lines of shell code should do the trick:


WANAddr=`.../dyndns/WANIP.pl`
.../dyndns/noip -i $WANAddr -c .../dyndns/no-ip.conf