Ubuntu – Is it possible to change a Linksys router’s configuration from a command line

command linesshUbuntu

I am constantly logged into my home machine, which runs Ubuntu, from various remote locations via SSH. Sometimes I would like to change the settings on my home Linksys router – port forwarding settings or disable/enable wireless, things like that.

When I try to use the links2 text browser to configure it, there isn't much I can do, because the tab titles don't show up (presumably because they are pictures).

Is there another way of configuring a Linksys router from a command line? I guess I could set up a proxy on my home machine and use a browser connected to that proxy to configure it, but I would think there might be a non-browser way of doing it.

Best Answer

Some third-party router firmwares (like DD-WRT, OpenWRT, Tomato, etc) provide an SSH interface to the router. I'd enable this on the LAN side but not the WAN. (You could also enable it on the WAN side using a nonstandard port, and a very strong password; likewise you could enable WAN access to the web interface; but I don't recommend those configurations.)

Once enabled, you can SSH into your router from within the LAN. (Eg, if the SSH interface is enabled on the LAN but not the WAN, you'd SSH into your Ubuntu machine, and SSH again from there into the router.) Once there you get a minimal shell (often provided by BusyBox), and have access to configuration files, daemon scripts, firmware settings and whatever commands are installed.

For example, I have an older Linksys WRT54G running OpenWRT. Via the SSH interface, I have access to:

  • iptables (eg, for opening temporary ports);
  • the /etc/hosts and /etc/dnsmasq.conf files (eg, for adding local DNS overrides or tweaking the DHCP server); and
  • the reboot command (if needed).

I can also inspect firmware settings (nvram show), alter them (nvram set), and write them to nonvolitile flash memory (nvram commit). Much of what you can access in the web interface is directly accessible with nvram, but be careful. This old OpenWRT HowTo describes basic nvram usage; there are probably better and more recent guides online, so read up and take care when using that utility.

Related Question