闲得没事干,突然看到一篇文章介绍 Linux 的 UPnP 的,于是也想做一下
所需软件:libupnp-1.3.1.tar.gz、linuxigd-1.0.tar.gz,sourceforge 上都有,下最新版的
先安装 libupnp,按照 INSTALL 做就可以
后安装 linuxigd,也就是 Linux 下的 daemon 程序,upnpd
根据 INSTALL 的提示,可以选择有 libiptc 的情况,我的系统也确实有,是在编译 iptables 的时候生成的一个动态链接库,但编译后发现创建 PortMap 错误,于是去掉了 libiptc 的支持
另,INSTALL 里提示要加组播路由并在 INPUT 里允许组播地址进入,这个是一定要做的,否则有的软件无法通过。# tail -f /var/log/upnpd
Aug 28 12:47:21 platinum upnpd[13713]: IGD root device successfully registered.
Aug 28 12:47:23 platinum upnpd[13713]: Advertisements Sent. Listening for requests ...
Aug 28 12:47:49 platinum upnpd[13720]: AddPortMap: DevUDN: uuid:75802409-bccb-40e7-8e6c-fa095ecce13e ServiceID: urn:upnp-org:serviceId:WANIPConn1 RemoteHost: (null) Prot: TCP ExtPort: 36881 Int: 192.168.39.170.36881
Aug 28 12:47:50 platinum upnpd[13720]: AddPortMap: DevUDN: uuid:75802409-bccb-40e7-8e6c-fa095ecce13e ServiceID: urn:upnp-org:serviceId:WANIPConn1 RemoteHost: (null) Prot: UDP ExtPort: 36881 Int: 192.168.39.170.36881
Aug 28 12:58:08 platinum upnpd[13720]: DeletePortMap: Proto:UDP Port:36881
Aug 28 12:58:08 platinum upnpd[13720]: DeletePortMap: Proto:TCP Port:36881
Aug 28 13:06:54 platinum upnpd[13720]: Failure in GateDeviceDeletePortMapping: DeletePortMap: Proto:UDP Port:36881
Aug 28 13:06:55 platinum upnpd[13720]: Failure in GateDeviceDeletePortMapping: DeletePortMap: Proto:TCP Port:36881
Aug 28 13:06:55 platinum upnpd[13720]: AddPortMap: DevUDN: uuid:75802409-bccb-40e7-8e6c-fa095ecce13e ServiceID: urn:upnp-org:serviceId:WANIPConn1 RemoteHost: (null) Prot: TCP ExtPort: 36881 Int: 192.168.39.170.36881
Aug 28 13:06:56 platinum upnpd[13720]: AddPortMap: DevUDN: uuid:75802409-bccb-40e7-8e6c-fa095ecce13e ServiceID: urn:upnp-org:serviceId:WANIPConn1 RemoteHost: (null) Prot: UDP ExtPort: 36881 Int: 192.168.39.170.36881
root@platinum /data/KERNEL
## iptables -vnL FORWARD
Chain FORWARD (policy ACCEPT 57M packets, 31G bytes)
pkts bytes target prot opt in out source destination
22973 24M ACCEPT tcp -- * * 0.0.0.0/0 192.168.39.170 tcp dpt:36881
3803 375K ACCEPT udp -- * * 0.0.0.0/0 192.168.39.170 udp dpt:36881
root@platinum /data/KERNEL
# iptables -t nat -vnL PREROUTING
Chain PREROUTING (policy ACCEPT 678K packets, 90M bytes)
pkts bytes target prot opt in out source destination
654 58197 DNAT udp -- ppp0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:36881 to:192.168.39.170:36881
340 24283 DNAT tcp -- ppp0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:36881 to:192.168.39.170:36881
root@platinum /data/KERNEL
#其中 nat 表 PREROUTING 链里面以及 filter 表 FORWARD 链里面的内容是 upnpd 自动添加的。
经过测试,迅雷软件必须在有组播路由的情况下才能使用,比特精灵则怎么都无法通过,而 eMule 是能力最强的,无论是否加组播路由都可以识别并使用 IGD 的 UPnP。# tail /var/log/upnpd
Aug 28 212248 platinum upnpd[32204] Advertisements Sent. Listening for requests ...
Aug 28 212404 platinum upnpd[32277] UPnP SDK Successfully Initialized.
Aug 28 212404 platinum upnpd[32277] Succesfully set the Web Server Root Directory.
Aug 28 212404 platinum upnpd[32277] IGD root device successfully registered.
Aug 28 212407 platinum upnpd[32277] Advertisements Sent. Listening for requests ...
Aug 28 212412 platinum upnpd[32285] AddPortMap DevUDN uuid75802409-bccb-40e7-8e6c-fa095ecce13e ServiceID urnupnp-orgserviceIdWANIPConn1 RemoteHost (null) Prot TCP ExtPort 14540 Int 192.168.39.170.6115
Aug 28 212422 platinum upnpd[32285] DeletePortMap ProtoTCP Port14540root@platinum /data/KERNEL
#