miniupnpd config

发布时间 2023-06-13 10:20:51作者: lsgxeva

miniupnpd config

来源  https://blog.csdn.net/u011641885/article/details/49305373 

 

UPnP全名是Universal Plug and Play,UPnP 最大的愿景就是希望任何设备只要一接上网络,所有在网络上的设备马上就能知道有新设备加入,这些设备彼此之间能互相沟通,更能直接使用或控制它,一切都不需要设定,完全的Plug and Play 

1、UPNP开启后能方便智能监控设备直接透传到因特网,无需做烦琐的映射端口设置。
2、UPNP开启后能方便智能网络存储设备与因特网进行数据传输,节省手动设置时间。
3、UPNP开启后能方便在因特网使用ERP、CRM、第三方远程桌面等软件。
4、UPNP开启后能提高AnyChat系统的P2P成功率,节省服务器的带宽。

UPnP是一种对等即插即用网络协议,主要用于视频,音频领域的传输协议,对使用者来说,打开UPnP之后可以增加迅雷等下载软件的下载速度。

提示:UPnP服务开机启动会消耗一点CPU和内存资源。

  • 安装必要的包
    确保接入互联网,以及配置好安装源(安装源参考http://blog.csdn.net/u011641885/article/details/46375531),然后执行以下命令:
    opkg update
    opkg install miniupnpd
  • 配置 UPnP 参数
    UPnP 的配置参数在 /etc/config/upnp 中。

    config upnp 的配置参数表
    键                  值              是否必须设置          说明     
    enable_natpmp            1 开启 NAT-PMP 支持, 1 表示开启        
    enable_upnp 1 开启 UPnP 支持,1 表示开启
    secure_mode  1 安全模式,客户端只能给自己转发一个输入口   
    log_output 0 日志输出级别,0表示不输出日志,如果设置了将输出到syslog中   
    download 数字 允许来自wan口的数据输入带宽,单位是(KB/秒)。
    upload 数字 允许输出到wan口的数据输入带宽,单位是(KB/秒)。
    external_iface 字符串 外网的设备域,默认是wan
    internal_iface 字符串 内网的设备域,默认是lan
    port 数字 监听的端口
    upnp_lease_file 文件名 upnp客户端租用记录文件

    config perm_rule 许可设置配置参数表:
    是否必须设置 说明
    action  字符串    设置是否许可:allow 许可, deny 不许可
    ext_ports   字符串   外部端口范围
    int_addr 字符串 ip 地址,如果 0.0.0.0/0 表示全部
    int_ports 字符串 内部端口范围
  • 设置 miniupnpd 开机启动
    etc/init.d/miniupnpd enable
    设置完毕以后,下次开机即可驻留内存,使用/etc/init.d/miniupnpd start可以临时开启一次看看

  • 检测是否有效开启
    netstat -lnp|grep miniupnpd
    如果查看到监听的端口,表示开启完成。

 

路由器下电脑为实现互联网端到端的连接需要配置DNAT(端口映射),UPNP就相当于自动化DNAT的实现,路由和客户端软件都需支持UPNP。
Openwrt路由下安装UPNP服务:

1
2
opkg update
opkg install miniupnpd

配置Iptables UPNP链,用于发现UPNP后在此链自动添加端口映射。

1
2
3
4
5
6
#允许特定转发
iptables -N MINIUPNPD
iptables -I FORWARD -i pppoe-wan -o br-lan -j MINIUPNPD
#DNAT端口映射
iptables -t nat -N MINIUPNPD
iptables -t nat -I PREROUTING -i pppoe-wan -j MINIUPNPD

UPNP配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat /var/etc/miniupnpd.conf 
#http://www.haiyun.me
ext_ifname=pppoe-wan
listening_ip=192.168.1.1
port=5000
enable_natpmp=yes
enable_upnp=yes
secure_mode=yes
system_uptime=yes
bitrate_down=28672000
bitrate_up=2867200
uuid=a107991c-8b19-4ce4-a525-36bd2c814165
allow 1024-65535 0.0.0.0/0 1024-65535
deny 0-65535 0.0.0.0/0 0-65535

开启UPNP服务:

1
2
/etc/init .d /miniupnpd  enable
/etc/init .d /miniupnpd  start

使用迅雷开启UPNP测试,查看日志UPNP服务已为迅雷添加端口映射:

1
2
3
4
5
6
7
8
9
10
11
12
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: HTTP connection from 192.168.1.16:45067
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: HTTP REQUEST : POST /ctl/IPConn (HTTP/1.1)
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: SOAPAction: urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: AddPortMapping: ext port 65379 to 192.168.1.16:65379 protocol TCP for: Thunder5
Sep  7 19:06:01 OpenWrt daemon.debug miniupnpd[7232]: UPnP permission rule 0 matched : port mapping accepted
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: redirecting port 65379 to 192.168.1.16:65379 protocol TCP for: Thunder5
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: HTTP connection from 192.168.1.16:45068
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: HTTP REQUEST : POST /ctl/IPConn (HTTP/1.1)
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: SOAPAction: urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: AddPortMapping: ext port 65379 to 192.168.1.16:15301 protocol UDP for: Thunder5
Sep  7 19:06:01 OpenWrt daemon.debug miniupnpd[7232]: UPnP permission rule 0 matched : port mapping accepted
Sep  7 19:06:01 OpenWrt daemon.info miniupnpd[7232]: redirecting port 65379 to 192.168.1.16:15301 protocol UDP for: Thunder5

查看Iptables链UPNP添加的规则:

1
2
3
4
5
iptables -L MINIUPNPD -nv
Chain MINIUPNPD (1 references)
  pkts bytes target     prot opt in     out     source               destination         
26245   18M ACCEPT     tcp  --  *      *       0.0.0.0/0            192.168.1.16        tcp dpt:65379 
18182 4423K ACCEPT     udp  --  *      *       0.0.0.0/0            192.168.1.16        udp dpt:15301
1
2
3
4
5
iptables -t nat -L MINIUPNPD -nv
Chain MINIUPNPD (1 references)
  pkts bytes target     prot opt in     out     source               destination         
   676 61598 DNAT       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:65379 to:192.168.1.16:65379 
   316 22320 DNAT       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:65379 to:192.168.1.16:15301

 

============= End