我已经在一个内部网络中安装了两个大华IPC-C15 IP摄像机,并希望通过VPN访问它们。
当地网络的建立情况如下:
我保持默认的GW和vpn连接的机器分开,并希望避免它们混合(默认GW是一个股票ADSL路由器,vpn客户端是有点零碎从硬件的角度来看)。
我考虑过以下通过VPN曝光摄像机的计划:
下面的图表会使它变得清晰。
[cam-0]
(1080, 5664) \
--> [vpn-client] --> (VPN)
[cam-1] (forwards 1080, 1081)
(1081, 5665) / ( 5664, 5665)摄像机与修改后的端口工作得很好,所以我试图通过端口转发使它们可用。我转发了cam-0所需的所有端口(甚至有点过分热情)
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 1080 -j DNAT --to-destination 192.168.1.40:1080
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 1554 -j DNAT --to-destination 192.168.1.40:1554
iptables -t nat -A PREROUTING -p udp -i eth0 --dport 1554 -j DNAT --to-destination 192.168.1.40:1554
iptables -t nat -A PREROUTING -p udp -i eth0 --dport 37777 -j DNAT --to-destination 192.168.1.40:37777
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 37777 -j DNAT --to-destination 192.168.1.40:37777
iptables -t nat -A PREROUTING -p udp -i eth0 --dport 37778 -j DNAT --to-destination 192.168.1.40:37778
iptables -A FORWARD -p udp -d 192.168.1.40 --dport 37778 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -d 192.168.1.40 --dport 37777 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -d 192.168.1.40 --dport 1080 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -d 192.168.1.40 --dport 1554 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE最终的结果是HTTP访问可以正常工作,但RTSP回放却不能。我不敢尝试ONVIF的发现,可能是一团糟。
使用ffplay的RTSP错误如下所示
$ ffplay -hide_banner 'rtsp://$USER:$PASS@192.168.1.31:1554'
[rtsp @ 0x7fa124000b80] UDP timeout, retrying with TCP 0B f=0/0
[rtsp @ 0x7fa124000b80] method PAUSE failed: 455 Method Not Valid in This State
[rtsp @ 0x7fa124000b80] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, rtsp, from 'rtsp://admin:50076929dhA!@192.168.1.31:1554':
Metadata:
title : Media Server
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264, none, 90k tbr, 90k tbn, 180k tbc
Stream #0:1: Audio: aac, 16000 Hz, mono, fltp
[rtsp @ 0x7fa124000b80] UDP timeout, retrying with TCP 0B f=0/0
[rtsp @ 0x7fa124000b80] method PAUSE failed: 455 Method Not Valid in This State如果我查看正在进行转发的机器上的iptable统计数据,数据包似乎会流:
# iptables -L -vn
Chain INPUT (policy ACCEPT 9827 packets, 6479K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 196 packets, 17202 bytes)
pkts bytes target prot opt in out source destination
1620 183K ACCEPT tcp -- * * 0.0.0.0/0 192.168.1.40 tcp dpt:1080 state NEW,RELATED,ESTABLISHED
107 21217 ACCEPT tcp -- * * 0.0.0.0/0 192.168.1.40 tcp dpt:1554 state NEW,RELATED,ESTABLISHED
0 0 ACCEPT udp -- * * 0.0.0.0/0 192.168.1.40 udp dpt:1554 state NEW,RELATED,ESTABLISHED
0 0 ACCEPT udp -- * * 0.0.0.0/0 192.168.1.40 udp dpt:37778 state NEW,RELATED,ESTABLISHED
0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.1.40 tcp dpt:37777 state NEW,RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT 857 packets, 96412 bytes)
pkts bytes target prot opt in out source destination
# iptables -t nat -L -vn
Chain PREROUTING (policy ACCEPT 233 packets, 45610 bytes)
pkts bytes target prot opt in out source destination
128 7680 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1080 to:192.168.1.40:1080
7 420 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1554 to:192.168.1.40:1554
0 0 DNAT udp -- eth0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:1554 to:192.168.1.40:1554
0 0 DNAT udp -- eth0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:37777 to:192.168.1.40:37777
0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:37777 to:192.168.1.40:37777
0 0 DNAT udp -- eth0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:37778 to:192.168.1.40:37778
Chain INPUT (policy ACCEPT 233 packets, 45610 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 246 packets, 23141 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
455 38579 MASQUERADE all -- * * 0.0.0.0/0 0.0.0.0/0我现在没有想法了,所以任何关于如何推进这件事的建议都是非常感谢的。
发布于 2018-06-25 22:36:25
显然,转发规则起作用了,我只是要求ffmpeg使用ffplay -rtsp_transport tcp来使用tcp。
此外,我使用的Android应用程序(Ovn显)很高兴只转发了HTTP和RSTP端口,所以我称之为“完成”。
https://serverfault.com/questions/918164
复制相似问题