Using the command line tool MiniUPnP client
Installation method:
Download the source code here and compile it as follows:
make sudo checkinstall
This way, you can uninstall it later.
usage method:
Usage : upnpc [options] -a ip port external_port protocol [duration] Add port redirection upnpc [options] -d external_port protocol <remote host> Delete port redirection upnpc [options] -s Get Connection status upnpc [options] -l List redirections upnpc [options] -L List redirections (using GetListOfPortMappings (for IGD:2 only) upnpc [options] -n ip port external_port protocol [duration] Add (any) port redirection allowing IGD to use alternative external_port (for IGD:2 only) upnpc [options] -N external_port_start external_port_end protocol [manage] Delete range of port redirections (for IGD:2 only) upnpc [options] -r port1 [external_port1] protocol1 [port2 [external_port2] protocol2] [...] Add all redirections to the current host upnpc [options] -A remote_ip remote_port internal_ip internal_port protocol lease_time Add Pinhole (for IGD:2 only) upnpc [options] -U uniqueID new_lease_time Update Pinhole (for IGD:2 only) upnpc [options] -C uniqueID Check if Pinhole is Working (for IGD:2 only) upnpc [options] -K uniqueID Get Number of packets going through the rule (for IGD:2 only) upnpc [options] -D uniqueID Delete Pinhole (for IGD:2 only) upnpc [options] -S Get Firewall status (for IGD:2 only) upnpc [options] -G remote_ip remote_port internal_ip internal_port protocol Get Outbound Pinhole Timeout (for IGD:2 only) upnpc [options] -P Get Presentation url protocol is UDP or TCP Options: -e description : set description for port mapping. -6 : use ip v6 instead of ip v4. -u url : bypass discovery process by providing the XML root description url. -m address/interface : provide ip address (ip v4) or interface name (ip v4 or v6) to use for sending SSDP multicast packets. -z localport : SSDP packets local (source) port (1024-65535). -p path : use this path for MiniSSDPd socket. -t ttl : set multicast TTL. Default value is 2.
For example, to map port 3222 of an external network to port 22 of 192.168.31.134, you can use the following command:
upnpc -a -e 'ssh' 192.168.31.134 22 3222 tcp
To remove the mapping for external port 3222, use the following command line:
upnpc -d 3222 tcp
Using the GUI tool UPnP Router Control
Search "Ubuntu software" for upnp. After installation, add port mapping according to the GUI prompts.