Saturday, 5 January 2013

Remote Access to Home Router Using SSH Port Forwarding

Here's the problem: I'm going to be at MadLab for the Coder Dojo today and I want to be able to remotely set up new Minecraft servers running on my machine at home. I can SSH in just fine, but to set up a new server I'll need to set up a new port-forwarding rule on my home router. The router is only accessible from within my home LAN.

SSH port-forwarding to the rescue:

At first I thought I could set up a simple local forwarding rule on the server with

ssh dave@myhost.com -L 8080:192.168.1.254:80

It connected fine, and then I tried in the local browser,

http://localhost:8080/

The page returned, but wouldn't let me access the router. It responded with HTTP error of 403 forbidden. Presumably this is because chrome is sending my laptop IP as the source IP.

In order to get round this I tried dynamic SSH forwarding as a SOCKS server:

ssh -C -D 1080 dave@myhost.com

I set up the SOCKS settings in Firefox to proxy port 1080 on local host and...

Bingo! http://192.168.1.254/ in firefox now gave me access to the router's configuration page.


Wednesday, 2 January 2013

Rimu Hosting DNS API

Here's the shell script that I'm using on my linux boxes to keep the DNS hosted by Rimu Hosting up to date with any changes to my dynamically allocated IP address from BT.


#!/bin/bash
wget -q -O -  -i rimu-dns-urls.txt  > /dev/null


The idea is to have a text file of URLs each of which updates the DNS for one address.  The list currently looks like this:

https://rimuhosting.com/dns/dyndns.jsp?host=lego.goopot.co.uk&api_key=MY-SECRET-NUMBER&ttl=300
https://rimuhosting.com/dns/dyndns.jsp?host=lego-wiki.goopot.co.uk&api_key=MY-SECRET-NUMBER&ttl=300


I then set up a one-line crontab entry to run this every five minutes:

*/5 * * * * cd ~dave/code/dynadns; ./dns-rimu.sh