IPTV单线复用——在Linux系统上配置

继之前的文章《使用 Gentoo Linux 搭建简单路由器并支持IPTV功能》, 我感觉写的太复杂了,里面乱七八糟的。我把 IPTV 单线复用的部分单独抽出来写写吧。

以上海电信,先简单的说说原理吧。很多家庭网络布线中,电信信息箱只有一条线到客厅电视,智能电视本身需要一条能上网的网线,IPTV盒子需要一条 IPTV 的专用信号线,这个时候光猫的 VLAN 功能就派上用场上,把 IPTV 和上网合2为1,用1条网线传输,然后另一端利用Switch(交换机),把信号分离出来。而 Linux 中的 Bridge 的功能等同交换机。

第一步:配置bridge

Gentoo Linux 使用 netifrc 的配置文件在 /etc/conf.d/net . 假设 WAN 网卡的名字是enp1s0f1:,具体配置如下:

 1#分享85和51, 上海电信的IPTV VLAN ID是85(直播),51是点播,先说说直播
 2vlans_enp1s0f1="85 51"
 3config_enp1s0f1_85="null"
 4config_enp1s0f1_51="null"
 5bridge_briptv85="enp1s0f1.85"
 6config_briptv85="dhcp"
 7briptv85_dhcp="nodns nogateway"
 8emtric_briptv85=20
 9# bridge_briptv51="enp1s0f1.51"
10# config_briptv51="dhcp"
11# emtric_briptv51=20
12# dns_servers_briptv85="null"
1/etc/init.d/net.briptv85 restart

可以看到 briptv85 已经获取到 IP 地址了

1Lion /home/zmhu/bin # ifconfig briptv85
2briptv85: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
3        inet 22.162.161.16  netmask 255.255.128.0  broadcast 22.162.255.255
4        inet6 fe80::a236:9fff:fe47:abc5  prefixlen 64  scopeid 0x20<link>
5        ether a0:36:9f:47:ab:c5  txqueuelen 1000  (Ethernet)
6        RX packets 1598328  bytes 2151873137 (2.0 GiB)
7        RX errors 0  dropped 0  overruns 0  frame 0
8        TX packets 11994  bytes 517572 (505.4 KiB)
9        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

IPTV是组播协议,我不希望把组播信号广播到我的局域网内。所以采用 组播转单播方案。 使用 udpxy. Gentoo 默认 udpxy 被 mask 了。 所以在 /etc/portage/package.accept_keywords/default 添加一条

1=net-misc/udpxy-1.0.23.7-r2 ~amd64

我这里指定了版本,如果后续有版本更新, 这里还需要加新的版本,当然你也可以把版本号去掉,这样就 unmask 了所有的版本,每次更新都会自动更新

udpxy需要配置一下,配置文件的位置在 /etc/conf.d/udpxy , 把原来的最后一行注释掉,添加如下配置。

1#Examples:
2#  udpxy -p 4022
3#       listen for HTTP requests on port 4022, all network interfaces
4#  udpxy -a lan0 -p 4022 -m lan1
5#       listen for HTTP requests on interface lan0, port 4022;
6#       subscribe to multicast groups on interface lan1
7
8# UDPXYOPTS="-p 4022"
9UDPXYOPTS="-S -a 0.0.0.0 -p 4022 -m briptv85"

然后启动 udpxy

1/etc/init.d/udpxy restart

输入 http://192.168.88.1:4022/status

udpxy status

如果 iptables 写的比较严格的, 记得放开一下 briptv85 的 INPUT , 一般 OUTPUT 的默认规则都是 ACCEPT. 我自己的 Linux Router 就是严格的模式, 默认规则是 DROP

1iptables -A INPUT -i briptv85 -j ACCEPT

假设你的路由器IP地址是 192.168.88.1, 使用 iina 或是 vlc 播放器就可直接播放了

CCTV-1

1http://192.168.88.1:4022/udp/239.45.3.145:5140

你也可以把播放地址制作成 m3u8 文件, 再附加上节目单。这样手机的体验就比较好了。 Android: IPTV Pro . 以下是 IINA 的效果

IINA

注意: 如果不能播放,参考这里

打开 /etc/sysctl.conf 添加如下内容

1net.ipv4.conf.default.rp_filter = 0
2net.ipv4.conf.all.rp_filter = 0
3## WAN 网的策略还是使用严格模式
4net.ipv4.conf.enp1s0f1.rp_filter = 1
5net.ipv4.conf.briptv85.rp_filter = 0
6net.ipv4.icmp_echo_ignore_broadcasts = 0

再执行 sysctl -p

OpenWRT 貌似没有采用严格模式,所以不会有这样的问题。当然一个家用路由器也不存被攻击的可能性,即使被攻击也不会产生实际意义的经济损失。OpenWRT 的配置 看我之前的文章写的文档就可以了 《使用软路由播放上海电信IPTV,完美去掉这个很丑的盒子

这个是什么意思呢?

rp_filter配置对 INPUT 的影响

rp_filter配置影响了系统响应IGMP general query查询,当rp_filter设置为0后,系统正常响应交换机GIMP general query报文,组播码流就不会出现断流。

rp_filter 详细描述 ip-sysctl.txt

 1rp_filter - INTEGER
 2	0 - No source validation.
 3	1 - Strict mode as defined in RFC3704 Strict Reverse Path
 4	    Each incoming packet is tested against the FIB and if the interface
 5	    is not the best reverse path the packet check will fail.
 6	    By default failed packets are discarded.
 7	2 - Loose mode as defined in RFC3704 Loose Reverse Path
 8	    Each incoming packet's source address is also tested against the FIB
 9	    and if the source address is not reachable via any interface
10	    the packet check will fail.
11
12	Current recommended practice in RFC3704 is to enable strict mode
13	to prevent IP spoofing from DDos attacks. If using asymmetric routing
14	or other complicated routing, then loose mode is recommended.
15
16	The max value from conf/{all,interface}/rp_filter is used
17	when doing source validation on the {interface}.
18
19	Default value is 0. Note that some distributions enable it
20	in startup scripts.

Posts in this series