利用Upnp映射到外网

1. Upnp 下载地址
http://miniupnp.free.fr/files/

说明:miniupnpc 为客户端, miniupnpd 为服务端
这里下载 miniupnpc-1.6.20120125.tar.gz

2. 编译miniupnp:
# tar xf miniupnpc-1.6.20120125.tar.gz
# make
在此目录下会生成 upnpc-static  upnpc-share

3. 配置路由器 让其开启 upnp 功能
登录路由器后 选择 转发规则-->upnp 设置→ 开启

4. 在客户端(loongson 1B 开发板)添加upnp 规则
#  ifconfig  //查看本机IP
eth0     Link encap:Ethernet  HWaddr 00:1e:64:63:ab:fe  
          inet addr:192.168.3.111  Bcast:192.168.3.255  Mask:255.255.255.0Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:163376 errors:0 dropped:0 overruns:0 frame:0
          TX packets:136701 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:170220701 (170.2 MB)  TX bytes:21403783 (21.4 MB)

#  upnpc-static  -a 192.168.3.111 80 8008 TCP   //此处的IP为本机IP
upnpc : miniupnpc library test client. (c) 2006-2011 Thomas Bernard
Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
for more information.
List of UPNP devices found on the network :
 desc: http://192.168.3.1:1900/igd.xml
 st: urn:schemas-upnp-org:device:InternetGatewayDevice:1

Found valid IGD : http://192.168.3.1:1900/ipc
Local LAN ip address : 192.168.3.111
ExternalIPAddress = 192.168.1.12
InternalIP:Port = 192.168.3.111:80
external 192.168.1.12:8008 TCP is redirected to internal 192.168.3.111:80 (duration=0)

说明:80 为内部端口, 此端口号可随意设置,只要与 web server的提供的端口号相同就可以了。8008 为外端口,也就是在外面通过 192.168.1.12:8008 就可以访问客户端的web 页面了
Upnpc-static 的详细用法:#  Upnpc-static
upnpc : miniupnpc library test client. (c) 2006-2011 Thomas Bernard
Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
for more information.
Usage :    ./upnpc-static [options] -a ip port external_port protocol [duration]
        Add port redirection
           ./upnpc-static [options] -d external_port protocol [port2 protocol2] [...]
        Delete port redirection
           ./upnpc-static [options] -s
        Get Connection status
           ./upnpc-static [options] -l
        List redirections
           ./upnpc-static [options] -L
        List redirections (using GetListOfPortMappings, IGD v2)
           ./upnpc-static [options] -r port1 protocol1 [port2 protocol2] [...]
        Add all redirections to the current host
           ./upnpc-static [options] -A remote_ip remote_port internal_ip internal_port protocol lease_time
        Add Pinhole (for IGD:2 only)
           ./upnpc-static [options] -U uniqueID new_lease_time
        Update Pinhole (for IGD:2 only)
           ./upnpc-static [options] -C uniqueID
        Check if Pinhole is Working (for IGD:2 only)
           ./upnpc-static [options] -K uniqueID
        Get Number of packets going through the rule (for IGD:2 only)
           ./upnpc-static [options] -D uniqueID
        Delete Pinhole (for IGD:2 only)
           ./upnpc-static [options] -S
        Get Firewall status (for IGD:2 only)
           ./upnpc-static [options] -w routerip
        set the ip address of the router with upnp server
           ./upnpc-static [options] -G remote_ip remote_port internal_ip internal_port protocol
        Get Outbound Pinhole Timeout (for IGD:2 only)
           ./upnpc-static [options] -P
        Get Presentation url

protocol is UDP or TCP
Options:
  -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 v6) to use for sending SSDP multicast packets.
  -p path : use this path for MiniSSDPd socket.


备注:客户端要和路由器连在一起,因为upnp 只能穿透 1 层网络

这时再次登陆路由器 选择 转发规则-->upnp 设置→ 刷新 就可以看到添加了一条 upnp规则
当前UPnP设置列表
ID     应用描述     外部端口     协议类型     内部端口     IP地址     状态
1    libminiupnpc    8008    TCP    80    192.168.3.111    已启用
    

5. 在客户端开启web 服务器(loongson 1B开发板上用 boa 做web server,因为其大小只有 100 KB 多点 )
# cat /etc/boa/boa.conf | grep Port  //查看其端口号 看是否与upnp映射的端口号相同,不同则改为相同
 #Port: The port Boa runs on.  The default port for http servers is 80.
Port 80

# boa    //板上的web server ,

6. 在电脑上测试
这时找一个电脑在浏览器里输入: 192.168.1.12:8008 键入 enter ,客户端里的web页面就呈现在你的面前了

转载于:https://www.cnblogs.com/liaochangfei/p/7089852.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值