Last weekend I installed OpenWRT (v12 Attitude Adjustment) on my WRT160Nv2 router device. Out of the “box”, the internal LAN is setup as 192.168.1.1, and I can ssh into the router for configuration. I plan to plug this router into another router device, so I would like to configure it for the following:
- DHCP on the WAN port: If I take this to a hotel or hook it up to a another router device, I want it to automatically obtain an IP address on the WAN port
- Private network on the LAN ports: 192.168.2.x addresses
- [Optional] Enable wireless access so that I don’t have to plug my laptop computer into this router via Ethernet cable each time I access it.
WAN port configuration
To modify settings, one can either edit /etc/config/network directly, or use the unified configuration interface (UCI) to issue commands from the shell. I chose to do the latter. Of course you can also use the web interface if you have a normal router and not a WRT160Nv2.
The commands below modify the wan port to use DHCP to obtain an IP address and DNS settings, and then bring up the WAN interface.
uci set network.wan.proto=dhcp uci commit network ifup wan
To verify that the WAN port has an IP address, issue the ifconfig command and look for the IP address used from the DHCP server, in this the router device issued to me by my ISP.
As shown below, the WAN port is given the IP address 192.168.1.10.
eth0.2 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:7135 errors:0 dropped:406 overruns:0 frame:0 TX packets:4675 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4727515 (4.5 MiB) TX bytes:745096 (727.6 KiB)
LAN IP address re-assignment
The DHCP server on my network is running on the private network 192.168.1.x, and that conflicts with the default configuration from the OpenWRT installation. The WRT160Nv2’s LAN ports need to be moved to another network. I decided to move them to 192.168.2.x.
uci set network.lan.ipaddr=192.168.2.1 uci commit network reboot
Rebooting closes the SSH session, so reconnect to the router, but remember the address is now 192.168.2.1 for the router device!
Testing Internet access
After logging into the machine, I issued a ping command to http://www.google.com: