Edit DD-WRT Port Forwarding over Telnet

I made a mistake before leaving town on my DD-WRT Router’s port forwarding. I had set up ports 22 and 3389 to forward to the same IP address, when in reality I needed them to forward to two different IP addresses.

I still cannot tell where on the DD-WRT file system the configs are that contain the data on the Port Forwarding Web GUI settings page.  But through various sources on the web I was able to get my RDP Port forwarding enabled so I could remote in to fix the web gui and get the changes to commit.

Here’s what I did.

  1. Used SSH to get into my server and then from there telnet to my DD-WRT Router.
  2. From the command prompt on the router I ran this command:
    iptables -t nat -vnL PREROUTING
  3. This showed me my current port forwarding rules that were being applied when the router boots.  I saw my errors in my IP addresses settings.
  4. Next I ran these two commands to set up a route from my WAN connection to my internal IP over port 3389:
    iptables -t nat -I PREROUTING -p tcp -d $(nvram get wan_ipaddr) --dport 3389 -j DNAT --to
    iptables -I FORWARD -p tcp -d --dport 3389 -j ACCEPT
  5. Once those two commands were run, I was able to connect via RDP to my internal PC and then log into the web gui to fix my error permanently.

I would still like to know how to do all these changes from the command line, but that will have to be saved for a post on the DD-WRT forums.

These two links were able to get me what I needed to get going:

DD-WRT IPTables Commands