Skip to content
/ cupnp Public

Small CLI tool for embedding and quickly exposing ports with uPnP

License

Notifications You must be signed in to change notification settings

erikh/cupnp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Small CLI tool for embedding and quickly exposing ports with uPnP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages