在Linux服務(wù)器上使用tcpdump對eth0這塊網(wǎng)卡抓包時俐东,如果你仔細(xì)看屏幕會發(fā)現(xiàn)有如下一行:
device eth0 entered promiscuius mode
這句的意思是網(wǎng)卡eth0進入了混雜模式柔昼,意思就是只要是eth0收到的網(wǎng)絡(luò)包都抓恰梢,不管這些網(wǎng)絡(luò)包是不是發(fā)給我的。以下是網(wǎng)上大牛寫的關(guān)于網(wǎng)卡所處的幾種模式,供大家進一步學(xué)習(xí)。
下面為轉(zhuǎn)載。
版權(quán)聲明:本文為CSDN博主「chengqiuming」的原創(chuàng)文章匙姜,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明冯痢。
原文鏈接:https://blog.csdn.net/chengqiuming/article/details/89603272
一 混雜模式基本概念
一般情況下氮昧,網(wǎng)卡往往只會接收目的地址是它的數(shù)據(jù)包而不會接收目的地址不是它的數(shù)據(jù)包。
混雜模式就是接收所有經(jīng)過網(wǎng)卡的數(shù)據(jù)包浦楣,包括不是發(fā)給本機的包袖肥。默認(rèn)情況下,網(wǎng)卡只把發(fā)給本機的包(包括廣播包)傳遞給上層程序振劳,其他的包一律丟棄椎组。
混雜模式就是指網(wǎng)卡能接受所有通過它的數(shù)據(jù)流,無論是什么模式历恐、什么地址的寸癌。當(dāng)網(wǎng)卡處于這種“混雜”模式時,它對所有遇到的每一個數(shù)據(jù)幀都產(chǎn)生一個硬件中斷弱贼,以提醒操作系統(tǒng)處理流經(jīng)該物理媒體上的每一個報文包蒸苇。
二 網(wǎng)卡工作模式
廣播模式:物理地址(MAC)是0Xffffff的幀為廣播幀,工作在廣播模式的網(wǎng)卡接收廣播幀吮旅。
多播模式:如果將網(wǎng)卡設(shè)置為多播模式溪烤,它可以接收所有的多播傳送幀,而不論他是不是組內(nèi)成員庇勃。
直接模式:只接收目的地址是自己MAC地址的幀檬嘀。
混雜模式:工作在混雜模式下的網(wǎng)卡接收所有流經(jīng)網(wǎng)卡的幀。
網(wǎng)卡默認(rèn)工作模式包括廣播模式和直接模式责嚷,即它只接收廣播幀和發(fā)給自己的幀鸳兽。如果采用混雜模式,一個站點的網(wǎng)卡將接收同一網(wǎng)絡(luò)內(nèi)所有站點所發(fā)送的數(shù)據(jù)包罕拂,這樣就可以達到對網(wǎng)絡(luò)信息監(jiān)視捕獲的目的揍异。
三 命令行查看、設(shè)置聂受、取消混雜模式
1 查看網(wǎng)卡是否為混雜模式
[root@localhost test]# ifconfig
enp0s3: flags=4163? mtu 1500
inet 192.168.0.110? netmask 255.255.255.0? broadcast 192.168.0.255
inet6 fe80::df33:8333:2d63:e4b? prefixlen 64? scopeid 0x20
ether 08:00:27:60:7b:7f? txqueuelen 1000? (Ethernet)
RX packets 5415? bytes 468898 (457.9 KiB)
RX errors 0? dropped 3? overruns 0? frame 0
TX packets 1035? bytes 95233 (93.0 KiB)
TX errors 0? dropped 0 overruns 0? carrier 0? collisions 0
flags=4163
信息中沒有PROMISC蒿秦,就說明當(dāng)前不在混雜模式下烤镐,如果有蛋济,則在混雜模式下。
2 設(shè)置網(wǎng)卡為混雜模式
[root@localhost test]# ifconfig enp0s3 promisc
設(shè)置完后炮叶,再查看網(wǎng)卡
[root@localhost test]# ifconfig enp0s3
enp0s3: flags=4419? mtu 1500
inet 192.168.0.110? netmask 255.255.255.0? broadcast 192.168.0.255
inet6 fe80::df33:8333:2d63:e4b? prefixlen 64? scopeid 0x20
ether 08:00:27:60:7b:7f? txqueuelen 1000? (Ethernet)
RX packets 5451? bytes 472410 (461.3 KiB)
RX errors 0? dropped 3? overruns 0? frame 0
TX packets 1037? bytes 95383 (93.1 KiB)
TX errors 0? dropped 0 overruns 0? carrier 0? collisions 0
可以發(fā)現(xiàn)第一行尖括號里有了PROMISC碗旅,說明網(wǎng)卡在混雜模式下
3 取消網(wǎng)卡混雜模式
[root@localhost test]# ifconfig enp0s3 -promisc
# 再查看
[root@localhost test]# ifconfig enp0s3
enp0s3: flags=4163? mtu 1500
inet 192.168.0.110? netmask 255.255.255.0? broadcast 192.168.0.255
inet6 fe80::df33:8333:2d63:e4b? prefixlen 64? scopeid 0x20
ether 08:00:27:60:7b:7f? txqueuelen 1000? (Ethernet)
RX packets 5526? bytes 487616 (476.1 KiB)
RX errors 0? dropped 3? overruns 0? frame 0
TX packets 1037? bytes 95383 (93.1 KiB)
TX errors 0? dropped 0 overruns 0? carrier 0? collisions 0
結(jié)果說明混雜模式取消了渡处。
————————————————
版權(quán)聲明:本文為CSDN博主「chengqiuming」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議祟辟,轉(zhuǎn)載請附上原文出處鏈接及本聲明医瘫。
原文鏈接:https://blog.csdn.net/chengqiuming/article/details/89603272