欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ubuntu 下使用 upnp 配置路由器端口映射

程序员文章站 2024-02-11 15:05:22
...

使用命令行工具 MiniUPnP client

安装方法:

这里下载源代码,然后编译,如下:

make
sudo checkinstall

这样安装,以后还可以卸载掉。

使用方法:

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.

例如,要将外网的端口3222映射到内外的192.168.31.134的22端口,可以使用下面的命令:

upnpc -a -e 'ssh' 192.168.31.134 22 3222 tcp

要删除外网端口 3222 的映射,可以用下面的命令行:

upnpc -d 3222 tcp

使用GUI工具 UPnP Router Control

从“Ubuntu软件”中搜索 upnp 即可找到,安装后按照GUI上的提示添加端口映射即可。