linux 网卡丢弃多播包,rp_filter及Linux下多网卡接收多播的问题
工作中曾遇到一個很奇怪的問題,我奉命調(diào)查。事情是這樣的,有一臺雙網(wǎng)卡的機器,上面裝有Fedora8,運行一個程序。該程序分別在兩個網(wǎng)口上都接收多播數(shù)據(jù),程序運行是正常的。但是,后來升級系統(tǒng)到Fedora13,發(fā)現(xiàn)就出問題了:在運行幾秒鐘后,第2個網(wǎng)口上就接收不到多播數(shù)據(jù)了。
能不能收到多播,取決于交換機是不是往這個網(wǎng)口上轉(zhuǎn)發(fā)多播數(shù)據(jù)。程序在起動的時候,會發(fā)一個IGMP的AddMembership的消息,交換機將把這個網(wǎng)口加入多播組。當(dāng)在其他網(wǎng)口上收到該地址的多播包后,會轉(zhuǎn)至這個網(wǎng)口。其后,為了確認(rèn)該接收者一直在線,交換機會發(fā)送一個IGMPQuery消息,接收者反饋一個IGMP Report消息,以確認(rèn)自己的存在。如果交換機沒有收到IGMPReport,則認(rèn)為該接收者已經(jīng)斷線,就不再往該網(wǎng)口上轉(zhuǎn)發(fā)多播包了。
用抓包工具定位了一下,發(fā)現(xiàn)程序在啟動時確實發(fā)了AddMembership消息,這是正常的。在接收下來的5秒時間內(nèi),程序能夠收到多播數(shù)據(jù)。接著,交換機發(fā)來了一條IGMPQuery,問題來了,這個Fedora13系統(tǒng)卻沒有反饋Report。這是很奇怪的。按理說,IGMP屬于系統(tǒng)自動完成的協(xié)議,無需用戶干預(yù);那么按照預(yù)期,Linux會自動反饋IGMPReport的。事實上,Feodra8和WinXP系統(tǒng)就是這么做的,都很正常。為什么到了Fedora13反而不正常了呢?
在調(diào)查“為什么不反饋IGMPReport”的事情上,花了一周時間都沒有進展,后來發(fā)現(xiàn)其實不至Fedora13,其他的主流linux如Ubuntu10,SUSE14也存在同樣的問題。
查了眾多論壇都沒有一點提示信息。后來,終于在一個英文網(wǎng)站上掃到了一個信息:rp_filter。后來證明,這個關(guān)鍵詞是解決問題的關(guān)鍵。reverse-pathfiltering,反向過濾技術(shù),系統(tǒng)在接收到一個IP包后,檢查該IP是不是合乎要求,不合要求的IP包會被系統(tǒng)丟棄。該技術(shù)就稱為rpfilter。怎么樣的包才算不合要求呢?例如,用戶在A網(wǎng)口上收到一個IP包,檢查其IP為B。然后考查:對于B這個IP,在發(fā)送時應(yīng)該用哪個網(wǎng)口,“如果在不應(yīng)該接收到該包的網(wǎng)口上接收到該IP包,則認(rèn)為該IP包是hacker行為”。
例如:
A: 192.168.8.100
B: (IGMP Query) 10.0.0.1 來自路由器
查找路由表
網(wǎng)卡1為默認(rèn)路由: 172.17.5.100 ?172.17.5.1
網(wǎng)卡2 ?192.168.8.100 ?192.168.8.1
系統(tǒng)根據(jù)路由表,認(rèn)為10.0.0.1這個IP應(yīng)該在第一個網(wǎng)卡172.17.5.100上收到,現(xiàn)實的情況是在第二張網(wǎng)卡192.168.8.100上收到了。認(rèn)為這是不合理的,丟棄該包。致命的問題的,該包是來自路由器的IGMPQuery包。
The rp_filter can reject incoming packets if their sourceaddress doesn’t match the network interface that they’re arrivingon, which helps to prevent IP spoofing. Turning this on, however,has its consequences: If your host has several IP addresses ondifferent interfaces, or if your single interface has multiple IPaddresses on it, you’ll find that your kernel may end up rejectingvalid traffic. It’s also important to note that even if you do notenable the rp_filter, protection against broadcast spoofing isalways on. Also, the protection it provides is only against spoofedinternal addresses; external addresses can still be spoofed.. Bydefault, it is disabled.
解決方法:
系統(tǒng)配置文件
1. /etc/sysctl.conf
把 net.ipv4.conf.all.rp_filter和net.ipv4.conf.default.rp_filter設(shè)為0即可
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
系統(tǒng)啟動后,會自動加載這個配置文件,內(nèi)核會使用這個變量
2. 命令行 顯示一個內(nèi)核變量 sysctl net.ipv4.conf.all.rp_filter 設(shè)置一個內(nèi)核變量 sysctl -w net.ipv4.conf.all.rp_filter=0 設(shè)置完后,會更新內(nèi)核(實時的內(nèi)存)中的變量的值,但不會修改sysctl.conf的值 3. 使用/proc文件系統(tǒng) 查看 cat /proc/sys/net/ipv4/conf/all/rp_filter 設(shè)置 echo "0">/proc/sys/net/ipv4/conf/all/rp_filter
總結(jié)
以上是生活随笔為你收集整理的linux 网卡丢弃多播包,rp_filter及Linux下多网卡接收多播的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 全志linux led驱动程序,芯灵思S
- 下一篇: linux编译器6,Linux安装gcc