What's new

Add/Remove Port Forwards on a schedule

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

kramttocs

Occasional Visitor
Is there a way to schedule adding and removing port forwarding entries?
I am thinking since it's only needed for cert renewal, I'd like to have it closed for all but an hour or so once a week.
 
You could create a nat-start script and add your own port forward(s) which includes its own scheduling using the time module.

Code:
#!/bin/sh
ext_ip="$(nvram get wan_ipaddr)"
ext_port=3389
int_ip=192.168.1.100
int_port=3389
proto=tcp

iptables -t nat -I PREROUTING -p $proto -d $ext_ip --dport $ext_port \
    -m time --timestart 20:00 --timestop 00:00 --weekdays Mon,Tue,Wed,Thu,Sun --kerneltz \
    -j DNAT --to $int_ip:$int_port
iptables -t nat -I PREROUTING -p $proto -d $ext_ip --dport $ext_port \
    -m time --timestart 00:00 --timestop 08:00 --weekdays Mon,Tue,Wed,Thu,Fri --kerneltz \
    -j DNAT --to $int_ip:$int_port

exit 0

I provided an example that crosses the midnight hour since that requires two rules to handle the crossover. But if you're just opening the port for an hour in the middle of a specific day, the required rule is much simpler.

Note, this will NOT work if the remote access is NOT really a port forward, such as needing to access a a service on the router itself (i.e., the router is the target). I'm strictly talking about actual port forwarding, which means to devices *other* than the router.
 
That is excellent! Really appreciate it. I am assuming this won't show in the UI/nvram, right?

I know it's a feature request but it would be nice to enable/disable port forwards vs having the delete/add them.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top