[Howto]Restrict admin access to your IP using DNS-O-Matic.

This tutorial will show you how to restrict WordPress logins and the WordPress admin area to only your IP using DNS-O-Matic.

Step 1.

Sign up for a free account at DNS-O-Matic. We will us this to update the IP.
This account is also useful for updating you IP for OpenDNS if you use it 😉

Step 2.
Sign up for a free account at  no-ip and create your free hostname.

Step 3.
Go back to DNS-O-Matic and configure your no-ip username, password and hostname.

Step 4.
Download the DNS-O-Matic update utility then install and configure. I’m using the mac client but there are several clients available, even router options.

Now your almost there. Your update client should have updated your IP to DNS-O-Matic.

Step 5.
Add a new plugin to check your login/admin IP is the same as your no-ip IP.
Create a new php file in wp-content/mu-plugins and add the following:

add_action( 'login_init', 'my_dns_check' );
add_action( 'admin_init', 'my_dns_check' );
function my_dns_check() {
if ( gethostbyname( '## NO-IP HOST HERE ##' ) !== $_SERVER['REMOTE_ADDR'] )
wp_die( 'Your IP is not allowed to access the admin area.', 'ACCESS DENIED!', array( 'response' => 403 ) );
}

Thats it!

1 Comment

  1. Danny on 8th August 2011 at 12:06 am

    Thats pretty cool, thanks for sharing!

Leave a Comment