Skip to main content

Uncomplicated Port Forwarder (UPF)

Uncomplicated Port Forwarder (UPF) is a simple command-line tool to manage port forwarding rules using iptables. It supports both TCP and UDP protocols, making it easy to set up port forwarding for specific ports or ranges of ports.

Installation

sudo pipx install upf

Run the script with sudo for administrative privileges (required to modify iptables).

Usage

Add a Single Port Forwarding Rule

Add a port forwarding rule from a host to a remote IP and port.

TCP (default)

sudo upf add <host-port> <remote-ip>:<remote-port>

Example:

sudo upf add 2200 192.168.0.2:22 # tcp by default

UDP

sudo upf add <host-port> <remote-ip>:<remote-port> --udp
sudo upf add <host-port>/<protocol> <remote-ip>:<remote-port>

Example:

sudo upf add 2200 192.168.0.2:22 --udp
sudo upf add 2200/udp 192.168.0.2:22
sudo upf add 2200/tcp 192.168.0.2:22

Add a Range of Port Forwarding Rules

Add a range of port forwarding rules for a subnet starting from a specified port.

TCP (default)

sudo upf add-range <starting-port>/<protocol> <gateway>/<subnet>:<start port> [--max <count>] [--start-at <number>]

Example:

sudo upf add-range 2200 192.180.12.1/24:80 [--max 10] [--start-at 20]
sudo upf add-range 2200 192.180.12.20/24:80

UDP

sudo  upf add-range 2200/udp 192.180.12.1/24:80 --max 10 --start-at 20

List All Managed Port Forwarding Rules

List all the port forwarding rules that have been added using UPF.

sudo upf list

Delete a Specific Port Forwarding Rule

Delete a specific port forwarding rule by host port.

TCP (default)

sudo upf delete <host-port>/<protocol>

Example:

sudo upf delete 2200 # tcp by default
sudo upf delete 2200/tcp

UDP

sudo upf delete <host-port> --udp

Example:

sudo upf delete 2200 --udp
sudo upf delete 2200/udp

Prune portforwarding

Clear all portforwarding added by upf

sudo upf prune

Sync

In case there is rules which are not part of upf, you can sync them.

sudo upf sync

Notes

  • Persistence: By default, changes made using iptables are not persistent after reboot. To make them persistent, you can save the rules using iptables-save and restore them with iptables-restore.

Metadata

Release files for upf 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for upf 0.3.2
File Size Uploaded
upf-0.3.2.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for upf 0.3.2
File Interpreter ABI Platform
upf-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / upf-0.3.2.tar.gz

Download URL upf-0.3.2.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
af134ca83485b8ce2f84f5212d55c9ba8637ffca15aca83a0a75ac1e5163666d
BLAKE2b-256 checksum
How to use checksums
33bbd4693647375207ba3dc7d36e75685cb8c227a74f40b4b0e5b1ed5f05d31e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.10 Darwin/24.1.0

Release files / upf-0.3.2-py3-none-any.whl

Download URL upf-0.3.2-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83b3cb49486869d3a6b52a6ac903346bc0792a5eb775121db54eeebeda2e7712
BLAKE2b-256 checksum
How to use checksums
aefcb4a764aa393a3db1ca87046f3fc99bef20d6119912c7742509c2c61aad0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.10 Darwin/24.1.0

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page