cupnp

Crates.iocupnp
lib.rscupnp
version0.1.1
created_at2025-10-25 22:13:43.423444+00
updated_at2025-10-25 22:22:40.220886+00
descriptioncupnp is a CLI tool to manage uPnP trivially
homepagehttps://github.com/erikh/cupnp
repositoryhttps://github.com/erikh/cupnp
max_upload_size
id1900717
size34,465
Erik Hollensbe (erikh)

documentation

README

cupnp: small tool for forwarding uPnP

cupnp is a tiny tool for managing port forwards on your home router. Suitable for short sessions where you just need a quick port forward, or for putting in systemd timers, cron, etc to keep ports regularly open without having to dive into your router's terrible user interface for this.

You do not need to be root to run this program; it requires no elevated permissions.

Installation

Please install cargo and a rust compiler. rustup makes this easy. Then run this:

cargo install cupnp

Example

NOTE: a lot of (even nice ones) home routers don't support lease duration on uPnP port forwards; they will not expire, so you must remove them yourself.

# expose port 8000 over tcp with a 1 hour lease
$ cupnp expose 8000 tcp 3600

# tcp and 3600 are the default, so we can do this:
$ cupnp expose 8000

# to remove, the same, just delete instead of expose:
$ cupnp delete 8000

# for udp:
$ cupnp delete 8000 udp

cron

Note that this will never remove the port forward, but you can add this line to the system (/etc/crontab) or user (crontab -e) crontab to keep your ports open:

User:

*/30 * * * * cupnp enable 8000

System:

*/30 * * * * nobody cupnp enable 8000

systemd Timer

You can create systemd files to keep this port forward up until you tell it to turn off. Should work just fine in $HOME/.config/systemd/user if that is desired. You will want to create a pair for each port forward, and be sure to systemctl start the timer file, not the service.

.timer file:

[Unit]
Description=cupnp port forward
After=network-online.target

[Timer]
OnUnitInactiveSec=30min

[Install]
WantedBy=timers.target

.service file:

[Unit]
Description=cupnp port forward
After=network-online.target

[Service]
Type=oneshot
ExecStart=cupnp expose 8000
ExecStop=cupnp delete 8000

License

MIT

Author

Erik Hollensbe git@hollensbe.org

Commit count: 0

cargo fmt