Gavin’s Odd Bits of Code

2010-05-13 (Thu)

Automatic EasyDNS (or other dynamic DNS) updates from your iPhone

Filed under: Hacks,MacOS X — Gavin Brock @ 3:49 pm
Tags: , ,
2010/10/10: Update: It appaears that the current version of curl on Cydia does not support HTTPS so the dns.sh script was changed to use wget.
I use EasyDNS to provide name resolution for my domain names. They provide a web based dynamic DNS updates service that allows people with dynamic IP address to update their records to point back to their machines.
I wanted to do this for my (jailbroken) iphone, so I documented my procedure below.

1 – Jailbreak your iPhone

There are plenty of guides on the web about this, and it’s too much to go into here. Try Google.
Once you are jailbroken, continue…

2 – Using Cydia, install the following packages

  • SBSettings
  • OpenSSH
  • cURL (Now using wget, so no download needed)
  • BigBossRecommended Tools

3 – Start SSH and get your IP address

Swipe the top of the screen to bring up the SBSettings menu.
Make sure that SSH is started. If you cannot see “SSH”, goto More -> Set Toggles and enable the SSH toggle button.
Read off the “Data IP Address:” (Should be of the form 1.2.3.4)

4 – Check SSH is working

Check you can connect to the phone over ssh (replace the IP with the one you found above):
computer# ssh root@1.2.3.4
The default root password is “alpine”. If you have the default password, change it now, before doing anything else:
iphone# passwd root
Changing password for root.
New password: <type password>
Retype new password: <type password again>

iphone# passwd mobile
Changing password for mobile.
New password: <type another password>
Retype new password: <type another password again>
Now log out of the phone:
iphone# logout

5 – Create the following two files on your computer:

Use your favorite text editor and create the following files (changing the red text to match your account):

dns.sh

#!/bin/sh
LAST_IP=xxx
while (true); do
IP=`ifconfig  pdp_ip0 | grep inet |  cut -d " " -f 2`
if [ "$IP" != "" ]; then
if [ "$IP" != "$LAST_IP" ]; then
RES=`wget -qO - --no-check-certificate --user=username --password=password "https://members.easydns.com/dyn/dyndns.php?hostname=iphone.example.com&myip=${IP}"`
if [ "$RES" == "NOERROR" ]; then
LAST_IP=$IP
fi
fi
fi
sleep 60
done

easydns.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>easydns</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/var/root/dns.sh</string>
</array>
<key>StandardErrorPath</key>
<string>/dev/null</string>
</dict>
</plist>
6 - Copy the files to the phone
computer# scp dns.sh root@1.2.3.4:/var/root/
computer# scp easydns.plist root@1.2.3.4:/Library/LaunchDaemons/

7 – Setup permissions and Launchd item

computer# ssh root@1.2.3.4
iphone# chmod +x dns.sh
iphone# sh -x ./dns.sh
If it runs with no error (it will keep running), you should see (among a lot of debug):
+ RES=NOERROR
Now press control-c to stop it.
Next, load the launch agent to keep the script running in the background (the script needs to stay running so it remembers your last IP and only updates DNS if it changes):
iphone# launchctl load /Library/LaunchDaemons/easydns.plist
This should complete with no output. You can finally check the script is running
iphone# ps -ef |grep dns
0  1886     1   0   0:00.22 ??   0:00.29 /bin/bash /var/root/dns.sh

8 – You’re done

Try connecting to your phone by name:

computer# ssh root@iphone.example.com

4 Comments »

  1. Thanks for this post and the code – although I don’t have an iPhone, I will try it with my computer and see if it works for me as well.

    Thanks again.

    Comment by Helen Dangote — 2010-06-04 (Fri) @ 4:48 pm | Reply

  2. I’ve got it figured out.. I just don’t know how to forward the information to the author so he can post the changes.

    Comment by BigTex — 2010-10-10 (Sun) @ 7:34 pm | Reply

    • I just did a 4.1 upgrade, and reinstall of the scripts, and I realized curl was broken, and word-press messed up the the quote marks. Instructions should be ok now.

      If you have any more fixes, just post em here.

      Comment by Gavin Brock — 2010-10-11 (Mon) @ 10:44 pm | Reply

  3. Gavin,

    Thanks for the amazing code :). I’ve always wanted to ssh into my iphone just in case sb stole my phone.

    You helped me alot! I am a step closer to sshing into my phone.

    Anyway, I managed to modify your code slightly and came up with a script for no-ip.

    It seemed to work and updated my host’s ip address. I can see in the cp that it was changed successfully.

    However, I am stuck, as I am unable to ssh into my phone either via the host’s adress or via the ip address updated by my script.

    I confirmed that the ip updated through the script matches the external ip of my iphone.

    Shouldn’t I be able to ssh into it so long as I have the right external ip for it?

    I simply do not get why I get this message…

    root@abcd:/home/abcd# ssh root@abcd.no-ip.org
    ssh: connect to host abcd.no-ip.org port 22: Connection timed out

    Is there anything I missed?

    Port 22 on my phone is open.

    Why am I getting this error? I am clueless.

    Can you point out where I made mistakes?

    Thanks

    Here’s my version

    #!/bin/sh

    LAST_IP=xxx

    while (true); do

    IP=`ifconfig pdp_ip0 | grep inet | cut -d ” ” -f 2`

    if [ "$IP" != "" ]; then

    if [ "$IP" != "$LAST_IP" ]; then

    RES=`wget -qO – –no-check-certificate –user= xyz@no-ip.com–password=no-ip-password “https://dynupdate.no-ip.com/nic/update?hostname=xyz.no-ip.org&myip=${IP}”`

    if [ "$RES" == "NOERROR" ]; then

    LAST_IP=$IP

    fi

    fi

    fi

    sleep 60

    done

    Comment by Jason Shim — 2012-08-21 (Tue) @ 5:30 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: