OpenWrt on the WRT54G

From PrimeatechWiki
Jump to: navigation, search

OpenWrt is described as a Linux distribution for embedded devices, namely routers like the Linksys WRT54G.

The beginner should read this before starting.

More documention and HOWTOs can be found here in the Openwrt OldWiki.

Installation

ssh to the router using a ssh client like PuTTY.

At the prompt type in the following to go to the tmp directory.

root@OpenWrt:~# cd /tmp

Use wget to get the latest release of OpenWrt firmware, currently 8.09.2:

root@OpenWrt:tmp# wget http://kamikaze.openwrt.org/8.09.2/brcm-2.4/openwrt-brcm-2.4-squashfs.trx

8.09.2 fixes the nasty port forwarding bug in the previous release.

WARNING!! Flashing the firmware will erase everything in the router and may brick the device.

Then flash the firmware:

root@OpenWrt:tmp# mtd -r write openwrt-brcm-2.4-squashfs.trx linux

The router will reboot after successfully writing the firmware to its flash memory.

Configuring OpenWrt

First Login

Telnet to 192.168.1.1

At the prompt issue the command "passwd" to add a password.

Then login using ssh, login as "root" and type in the password.

Port Forwarding

Port forwarding is done by modifying the file /etc/config/firewall using vi:

root@OpenWrt:~# vi /etc/config/firewall

In the "#port redirect port coming in on wan to lan" section add the lines:

config redirect
     option src       wan 
     option src_dport 8080
     option dest      lan
     option dest_ip   192.168.1.207
     option dest_port 80
     option proto     tcp

The above forwards tcp port 8080 of the wan to port 80 of the machine at 192.168.1.207.

Restart firewall:

root@OpenWrt:~# /etc/init.d/firewall restart

Enabling WPA-PSK

Edit the file /etc/config/wireless:

root@OpenWrt:~# vi /etc/config/wireless

Modify or add the lines:

config 'wifi-iface'
    option  'device' 'wl0'
    option  'mode' 'ap'
    option  'ssid' 'your_ssid'
    option  'encryption' 'psk'
    option  'key' 'your_psk_key'

Change 'your_ssid' to the ssid of your choice and 'your_psk_key' to your pre-shared-key.

Restart the network:

root@OpenWrt:~# /etc/init.d/network restart

Time Synchronization with NTP

First install ntpclient using the package manager:

root@OpenWrt:~# opkg install ntpclient

The config file of ntpclient is in /etc/config/ntpclient. You may want to change the ntp servers to suit your need.

Next, set the time zone by editing /etc/config/system:

root@OpenWrt:~# vi /etc/config/system

And add the line "option timezone HKT-8" under "Config System":

Config System
    option hostname OpenWrt
    option timezone HKT-8

Note: Changing the timezone in /etc/TZ will not make it persistent on next boot.

The startup script is /etc/hotplug.d/iface/20-ntpclient and is linked to the hotplug event of the wan starting up. There needs to be one change in the script to make ntp work. Edit the script:

root@OpenWrt:~# vi /etc/hotplug.d/iface/20-ntpclient

And change the line containing "NTPC" to:

NTPC="/usr/sbin/ntpclient"

Reboot or bring up wan:

root@OpenWrt:~# ifup wan

or run

root@OpenWrt:~# ACTION=ifup INTERFACE=wan /sbin/hotplug-call iface

Use 'ps' to check if ntpclient is running:

root@OpenWrt:~# ps | grep ntpclient
 3597 root      1316 S    /usr/sbin/ntpclient -i 600 -s -l -D -p 123 -h 0.openw
 3607 root      1916 S    grep ntpclient

There may be an issue with the ntp servers not being resolved when the wan is brought up at boot.