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.
sudo pipx install upfRun the script with sudo for administrative privileges (required to modify iptables).
Add a port forwarding rule from a host to a remote IP and port.
sudo upf add <host-port> <remote-ip>:<remote-port>Example:
sudo upf add 2200 192.168.0.2:22 # tcp by defaultsudo 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:22Add a range of port forwarding rules for a subnet starting from a specified port.
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:80sudo upf add-range 2200/udp 192.180.12.1/24:80 --max 10 --start-at 20List all the port forwarding rules that have been added using UPF.
sudo upf listDelete a specific port forwarding rule by host port.
sudo upf delete <host-port>/<protocol>Example:
sudo upf delete 2200 # tcp by default
sudo upf delete 2200/tcpsudo upf delete <host-port> --udpExample:
sudo upf delete 2200 --udp
sudo upf delete 2200/udpClear all portforwarding added by upf
sudo upf pruneIn case there is rules which are not part of upf, you can sync them.
sudo upf sync- Persistence: By default, changes made using
iptablesare not persistent after reboot. To make them persistent, you can save the rules usingiptables-saveand restore them withiptables-restore.