LinuxCommandLibrary

upnpc

Forward ports using UPnP-enabled Internet Gateway Device

TLDR

Forward the external TCP port 80 to port 8080 on a local machine

$ upnpc -a [192.168.0.1] 8080 80 tcp
copy

Delete any port redirection for external TCP port 80
$ upnpc -d 80 tcp
copy

Get information about UPnP devices on your network
$ upnpc -s
copy

List existing redirections
$ upnpc -l
copy

SYNOPSIS

upnpc [-l | -a | -s [] [] | -d | -r [] [] | -L | -i ]

PARAMETERS

-l
    List all port mappings configured on the router.

-a [] []
    Add a new port mapping. internal_port is the port on the local machine, external_port is the port exposed on the router, protocol is 'TCP' or 'UDP', duration is the lease time in seconds (optional), and description is a short description of the rule (optional).

-s [] []
    The same as '-a' but uses the WAN IP returned by GetExternalIPAddress to add the mapping. This is useful when there are multiple WAN IP addresses.

-d
    Delete an existing port mapping. external_port and protocol must match an existing rule.

-r [] []
    Add a new port mapping specifying the internal IP address. This can be useful if the machine running upnpc is not the same as the service host.

-L
    Display local address (ip address and port) to be used with -r option.

-i
    Display information about the port mapping at the given index.

DESCRIPTION

The upnpc command is a simple command-line tool used to interact with UPnP (Universal Plug and Play) enabled Internet Gateway Devices (IGDs), typically routers. Its primary function is to configure port forwarding rules on these devices, allowing external access to services running on a local network.

By sending UPnP requests to the router, upnpc can automate the process of creating, deleting, and listing port mappings, eliminating the need for manual configuration through the router's web interface.

This command is frequently used in applications requiring direct connections from external clients, such as peer-to-peer file sharing, online gaming, and remote access to servers. It depends on a UPnP-enabled router and the 'miniupnpc' library for its functionality.

CAVEATS

upnpc requires a UPnP-enabled router to function correctly.

The effectiveness of port forwarding rules depends on the router's firmware and configuration.

Security considerations should be taken into account when opening ports to the internet.

The user running upnpc must have sufficient permissions to interact with network devices.

ERROR HANDLING

upnpc provides limited error reporting. Failed operations may not always produce clear error messages, making troubleshooting difficult. Check router logs for more details.

DEPENDENCIES

upnpc relies on the miniupnpc library. Ensure this library is installed and configured correctly for upnpc to function properly.

HISTORY

upnpc is part of the miniupnpc library, which was created to provide a lightweight and portable UPnP client for various platforms.

The development of upnpc was driven by the need to automate port forwarding in applications like peer-to-peer networking and online gaming.

Its usage has grown with the increasing adoption of UPnP-enabled routers in home and small office environments.

SEE ALSO

Copied to clipboard