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.