Friday, April 04, 2008

Setting up a WRT54G as a tftp server

Install SDCard mod
Although this option is not 100% necessary it does make things a lot easier for you in the long run.
-DangerzAU-


Once you have your SDCard modded as per the instructions here, you will need to add a few extra lines to your routers startup configuration.

In the DD-WRT web interface, click on Administration --> Commands
You will need to enter the following into the text box on this page, and then click the Save Startup button.
umount /jffs
mount -o bind /mmc /jffs


Effectivly what these two lines do are quite simple. The first un-mounts the default JFFS2 partition, and the second, well it mounts the sd-card (/mmc) as the /jffs partition.

Install OptWare packages

Now that you have the SDCard functioning, its time to install the OptWare packages. This will be required to allow the installation of Atftpd later in the guide.
The installation is actually quite simple, however most is done via the SSH or TelNet interface of your router.

~ # mkdir /jffs/opt
~ # mount -o bind /jffs/opt /opt


This will first create a new jffs folder for us to use as a virtual mount point, it then uses the bind option of the mount command to "virtual" mount this folder as our new /opt folder. Doing this allows us both read and write access to the /opt folder which is usually marked as read only on the WRT54G's squashFS filesystem.

The next step is to simply use a nice warm and fuzzy script thats been created to setup all the required packages/folders and config files for using OptWare

wget http://pastebin.ca/raw/876251 -O - tr -d '\r' > /tmp/optware-install.sh
sh /tmp/optware-install.sh


Effectively what this does is download the config file to the /tmp folder (Ram) and then runs that file to install optware.

The next step in the process is to add a few extra variables into the routers default path. This can be done with the following line:

export PATH=/opt/bin:/opt/sbin:$PATH
unset LD_LIBRARY_PATH


This needs to be put into the Start-up commands folder of your router via the web interface.

Installing ATFTP

Now that we have OptWare installed, its time to finish up by installing tftp.

this quite simple to do. all thats required is to issue the following command:
~ #/opt/bin/ipkg-opt install atftp


once that completes its just a matter of adding some routing and virtual network interfaces to the router to allow a modem to communicate with the router, hence working as its TFTP Server.

Add the following to your Startup Commands and all should be well..

export IPKG_CONF_DIR=/opt/etc
export PATH=$PATH:/opt/bin:/opt/sbin

ifconfig vlan1:0 192.168.100.10 netmask 255.255.255.0
ip route add default via 192.168.100.1 dev vlan1 table default
iptables -I INPUT -p udp -i vlan1 -d 192.168.100.10 --sport 1024:65535 --dport 69 -j ACCEPT

iptables -I INPUT -p udp -d 192.168.0.1 --dport 69 -j ACCEPT
iptables -t nat -I PREROUTING 1 -p udp --dport 69 -j DNAT --to 192.168.100.10:69

iptables -I INPUT 1 -p udp --dport 53 -j ACCEPT

Thats all it takes.

Save the startup config, and all as the say.. Is DONE!

No comments:

Post a Comment