openwrt upnp 技术验证

本文详细介绍了UPnP(通用即插即用)功能在路由器中的作用,包括自动端口转换,使得局域网内的计算机资源可被互联网访问,提升在线视频和多点下载软件的稳定性。并通过华为路由器A1和Openwrt系统具体演示了UPnP功能的验证过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、参考网站

http://www.miui.com/thread-1849642-1-1.html

http://www.360doc.com/content/14/1009/17/13468863_415575489.shtml

http://www.doc88.com/p-9933368077090.html

upnp在路由器中的作用

开启 UPnP (Universal Plug and Play,通用即插即用)功能后,局域网中的计算机可以请求路由器自动进行端口转换。这样,互联网上的计算机就能在需要时访问局域网计算机上的资源(如 MSN Messenger 或迅雷、BT、PPTV 等支持 UPnP 协议的应用程序),让您在观看在线视频或使用多点下载等方面的软件时,享受更加稳定的网络。

二、如何验证华为路由器 A1的UPnP功能

华为路由器 A1显示界面

启动迅雷下载功能以后  华为路由器 A1显示界面 自动添加upnp端口映射功能 

结论

路由器支持开启upnp功能以后,如果使用迅雷下载,会看到UPnP端口映射是自动添加的端口映射,不需要手工添加。

问题:为什么UPnP状态,内部外部端口是不一致的?

解答:UPnP是自动的NAT,是设备和路由器之间安装UPnP协议,自动协商端口。

    即使内网设备重启,IP地址改变,二者之间都会重新协商获得新的UPnP端口号(即自动的NAT端口映射)

四、Openwrt如何验证 UPnP功能

①依赖

   1. miniupnpd

    2. luci-app-upnp

②配置界面

    未使能upnp界面显示

使能upnp的界面显示

openwrt也是自动刷新将对应的upnp自动映射端口添加在界面上,需要等待迅雷开启一段时间后才能看到

     

③配置文件

配置前

   

配置后

然后重启防火墙和upnp

/etc/init.d/firewall restart

/etc/init.d/miniupnpd start  有些版本支持restart命令但是14版本的不支持start命令

upnp产生的结果为 

cat /tmp/upnp.leases 
TCP:12592:192.168.1.178:16000:0:PPLive
UDP:9573:192.168.1.178:5041:0:PPLive  

这才是重点,需要将这个文件的内容通过http协议返回给web 界面

 

If you are experiencing problems with the Universal Plug and Play service, your computer might not be able to automatically detect the presence of other networked devices, such as PCs, printers, Internet access points and so on. That is where the UPnP Test application comes in. This simple program is designed to help you identify the issues that prevent the UPnP protocol from functioning correctly. Before you get your hopes up, you should know that this tool does not solve the detected problems, but only performs a series of tests to identify the possible causes. One advantage is that the application does not require installation, so your system registry is not affected in any way. The interface is compact and simple, comprising only two panels: one that displays the test type and its short description and the other for viewing which of the tests passed and which failed. The program can verify whether the operating system provides support for the UPnP service and allows you to check if the Simple Service Discovery Protocol (SSDP) and the UPnPHost services are running. It also verifies the connection between your network adapter and your router and the system's capacity to receive UPnP messages, as well as the router's capability to report an external IP address. One of the tests is designed to check if the Windows firewall service is blocking the traffic between your router and the system, thus preventing UPnP from working. The results can be copied to your clipboard by simply pressing a button and the tests can be redone easily. If you want to fix the detected issues, the link in the main interface can prove useful. In conclusion, UPnP Test is a simple tool for detecting problems related to device-to-device networking. However, it can only suggest possible reasons why the UPnP is not working, fixing the detected issues is totally up to you.
### OpenWRT端口转发问题的解决方法 在配置OpenWRT时,如果发现端口转发(Port Forwarding)后无法从外网访问,可能的原因和解决方案包括以下几个方面: 1. **检查NAT设置** 确保路由器启用了NAT(网络地址转换),因为大多数情况下,家庭或小型办公网络使用私有IP地址,而外部互联网只能通过公共IP地址访问。确保以下命令启用: ```bash iptables -t nat -A POSTROUTING -o wan -j MASQUERADE ``` 此规则会将来自局域网的数据包进行地址转换,使其能够通过WAN接口发送到外部网络[^4]。 2. **验证防火墙规则** OpenWRT默认的防火墙可能会阻止某些流量。需要添加允许特定端口进入的规则。例如,要允许外部网络通过HTTP(80)和HTTPS(443)端口访问内部服务器,可以添加如下规则: ```bash config rule option name 'Allow-HTTP' option src 'wan' option proto 'tcp' option dest_port '80' option target 'ACCEPT' config rule option name 'Allow-HTTPS' option src 'wan' option proto 'tcp' option dest_port '443' option target 'ACCEPT' ``` 这些规则允许外部流量到达指定端口,从而实现服务的公开访问[^2]。 3. **确认端口转发规则正确性** 在`/etc/config/firewall`文件中,检查是否已经正确设置了端口转发规则。例如,假设希望将外部端口8080映射到内部IP为`192.168.1.100`的主机上的端口80,应配置如下规则: ```bash config redirect option name 'Web Server' option src 'wan' option proto 'tcp' option src_dport '8080' option dest_ip '192.168.1.100' option dest_port '80' option target 'DNAT' ``` 该规则指示路由器将来自WAN接口的TCP流量从端口8080转发到内部主机的端口80[^3]。 4. **检查本地网络设备的IP配置** 确保目标设备(如Web服务器)的IP地址与端口转发规则中指定的一致,并且其网关指向正确的OpenWRT路由器。此外,目标设备的防火墙也应允许接收所需端口的流量。 5. **测试端口转发** 可以使用在线工具(如[CanYouSeeMe.org](https://canyouseeme.org/))来测试特定端口是否可以从外部网络访问。输入想要测试的端口号并提交,系统会尝试连接并报告结果。这有助于快速判断问题是出在网络配置还是其他地方。 6. **重启相关服务** 修改完配置文件后,记得重启相关的网络服务以使更改生效: ```bash /etc/init.d/firewall restart ``` 或者直接重启整个路由器: ```bash reboot ``` 7. **检查运营商限制** 某些ISP(互联网服务提供商)可能会封锁常见的服务端口(如80、443等)。在这种情况下,即使所有配置都正确,也无法从外部访问这些服务。可以通过更换端口(如使用非标准端口8080代替80)来绕过这种限制。 8. **动态DNS更新** 如果使用的是动态公网IP地址,则建议配置DDNS(动态域名解析服务),以便即使IP发生变化也能保持对外的服务可用性。OpenWRT支持多种DDNS服务商,只需按照官方文档进行设置即可。 9. **排查UPnP冲突** 如果启用了UPnP(通用即插即用)功能,它可能会与其他手动配置的端口转发规则产生冲突。建议暂时禁用UPnP,或者确保两者之间没有重叠的端口设置。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值