Create your own What’s My IP service.

Here’s an easy way to make your own IP echoing service on your own website if you’re hosting that website with Apache on a Debian-based Linux distro.

  • 1. Add a new site to the apache configuration. The file should be named as the URL with `.conf` at the end:

nano /etc/apache2/sites-available/myip.stephenfranklin.info.conf

And it should look like this:

ServerAdmin stephen@stephenfranklin.info
ServerName myip.stephenfranklin.info
DocumentRoot /var/www/myip.stephenfranklin.info/htdocs
ErrorLog /var/www/myip.stephenfranklin.info/logs/error.log
CustomLog /var/www/myip.stephenfranklin.info/logs/access.log combined

  • 2. Enable the site and reload apache:

root@www:sites-available$ a2ensite myip.stephenfranklin.info.conf Enabling site myip.stephenfranklin.info. To activate the new configuration, you need to run: service apache2 reload root@www:sites-available$ service apache2 reload * Reloading web server apache2 * root@www:sites-available$
  • 3. Then create the appropriate directories for that site in `/var/www/`:

mkdir -p /var/www/myip.stephenfranklin.info/htdocs
mkdir /var/www/myip.stephenfranklin.info/logs/

Create an index.php script in the htdocs directory:

nano /var/www/myip.stephenfranklin.info/htdocs/index.php
And put this in there:


< ?php echo $_SERVER['REMOTE_ADDR']."\n"; ?>
  • 4. Test it from another machine with `curl`:

stephen@mac:~$ curl -s http://myip.stephenfranklin.info/ 191.145.122.55 stephen@mac:~$

That’s it! Try it out from a browser:
1_myip.stephenfranklin.info

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.