盤點如何在Linux上檢查網(wǎng)絡(luò)連接狀況命令方法
2018-02-24 10:07:14
5220瀏覽
在現(xiàn)如今,大多數(shù)開發(fā)編程語言都會有命令可以幫助到你,比如在Linux系統(tǒng)上看到網(wǎng)絡(luò)狀況,其中包括ip、ethtool、traceroute、tcptraceroute和tcpdump等。下面我們一起來看下一吧。
ifconfig和netstat命令當(dāng)然非常有用,但還有很多其它命令能幫你查看Linux系統(tǒng)上的網(wǎng)絡(luò)狀況。本文探索了一些檢查網(wǎng)絡(luò)連接的非常簡便的命令。
ip命令
ip命令顯示了許多與你使用ifconfig命令時的一樣信息。其中一些信息以不同的格式呈現(xiàn),比如顯示192.168.0.6/24,而不是inetaddr:192.168.0.6Bcast:192.168.0.255,盡管ifconfig更適合數(shù)據(jù)包計數(shù),但ip命令有許多有用的選項。
首先,ipa命令可以列出所有網(wǎng)絡(luò)接口的信息。
$ipa
1:lo:<LOOPBACK,UP,LOWER_UP>mtu65536qdiscnoqueuestateUNKNOWNgroupdefaultqlen1
link/loopback00:00:00:00:00:00brd00:00:00:00:00:00
inet127.0.0.1/8scopehostlo
valid_lftforeverpreferred_lftforever
inet6::1/128scopehost
valid_lftforeverpreferred_lftforever
2:eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500qdiscpfifo_faststateUPgroupdefaultqlen1000
link/ether00:1e:4f:c8:43:fcbrdff:ff:ff:ff:ff:ff
inet192.168.0.6/24brd192.168.0.255scopeglobaleth0
valid_lftforeverpreferred_lftforever
inet6fe80::21e:4fff:fec8:43fc/64scopelink
valid_lftforeverpreferred_lftforever
如果你只想看到簡單的網(wǎng)絡(luò)接口列表,你可以用grep限制它的輸出。
$ipa|grepinet
inet127.0.0.1/8scopehostlo
inet6::1/128scopehost
inet192.168.0.6/24brd192.168.0.255scopeglobaleth0
inet6fe80::21e:4fff:fec8:43fc/64scopelink
使用如下面的命令,你可以看到你的默認(rèn)路由:
$iprouteshow
defaultvia192.168.0.1deveth0
192.168.0.0/24deveth0protokernelscopelinksrc192.168.0.6
在這個輸出中,你可以看到通過eth0的默認(rèn)網(wǎng)關(guān)是192.168.0.1,并且本地網(wǎng)絡(luò)是相當(dāng)標(biāo)準(zhǔn)的192.168.0.0/24。
你也可以使用ip命令來啟用和禁用網(wǎng)絡(luò)接口。
$sudoiplinkseteth1up
$sudoiplinkseteth1down
ethtool命令
另一個檢查網(wǎng)絡(luò)非常有用的工具是ethtool。這個命令提供了網(wǎng)絡(luò)接口上的許多描述性的數(shù)據(jù)。
$ethtooleth0
Settingsforeth0:
Supportedports:[TP]
Supportedlinkmodes:10baseT/Half10baseT/Full
100baseT/Half100baseT/Full
1000baseT/Full
Supportedpauseframeuse:No
Supportsauto-negotiation:Yes
Advertisedlinkmodes:10baseT/Half10baseT/Full
100baseT/Half100baseT/Full
1000baseT/Full
Advertisedpauseframeuse:No
Advertisedauto-negotiation:Yes
Speed:100Mb/s
Duplex:Full
Port:TwistedPair
PHYAD:1
Transceiver:internal
Auto-negotiation:on
MDI-X:on(auto)
Cannotgetwake-on-lansettings:Operationnotpermitted
Currentmessagelevel:0x00000007(7)
drvprobelink
Linkdetected:yes
你也可以使用ethtool命令來檢查以太網(wǎng)驅(qū)動程序的設(shè)置。
$ethtool-ieth0
driver:e1000e
version:3.2.6-k
firmware-version:1.4-0
expansion-rom-version:
bus-info:0000:00:19.0
supports-statistics:yes
supports-test:yes
supports-eeprom-access:yes
supports-register-dump:yes
supports-priv-flags:no
自動協(xié)商的詳細(xì)信息可以用這樣的命令來顯示:
$ethtool-aeth0
Pauseparametersforeth0:
Autonegotiate:on
RX:on
TX:on
traceroute命令
traceroute命令用于顯示路由路徑。它通過在一系列數(shù)據(jù)包中設(shè)置數(shù)據(jù)包頭的TTL(生存時間)字段來捕獲數(shù)據(jù)包所經(jīng)過的路徑,以及數(shù)據(jù)包從一跳到下一跳需要的時間。traceroute的輸出有助于評估網(wǎng)絡(luò)連接的健康狀況,因為某些路由可能需要花費更長的時間才能到達(dá)最終的目的地。
$sudotracerouteworld.std.com
traceroutetoworld.std.com(192.74.137.5),30hopsmax,60bytepackets
1192.168.0.1(192.168.0.1)3.691ms3.678ms3.665ms
210.224.64.1(10.224.64.1)26.273ms27.354ms28.574ms
310.20.0.33(10.20.0.33)28.293ms30.625ms33.959ms
410.20.0.226(10.20.0.226)36.807ms37.868ms37.857ms
5204.111.0.132(204.111.0.132)38.256ms39.091ms40.429ms
6ash-b1-link.telia.net(80.239.161.69)41.612ms28.214ms29.573ms
7xe-1-3-1.er1.iad10.us.zip.zayo.com(64.125.13.157)30.429ms27.915ms29.065ms
8ae6.cr1.dca2.us.zip.zayo.com(64.125.20.117)31.353ms32.413ms33.821ms
9ae27.cs1.dca2.us.eth.zayo.com(64.125.30.246)43.474ms44.519ms46.037ms
10ae4.cs1.lga5.us.eth.zayo.com(64.125.29.202)48.107ms48.960ms50.024ms
11ae8.mpr3.bos2.us.zip.zayo.com(64.125.30.139)51.626ms51.200ms39.283ms
1264.124.51.229.t495-rtr.towerstream.com(64.124.51.229)40.233ms41.295ms39.651ms
1369.38.149.18(69.38.149.18)44.955ms46.210ms55.673ms
1464.119.137.154(64.119.137.154)56.076ms56.064ms56.052ms
15world.std.com(192.74.137.5)63.440ms63.886ms63.870ms
tcptraceroute命令
tcptraceroute命令與traceroute基本上是一樣的,只是它能夠繞過最常見的防火墻的過濾。正如該命令的手冊頁所述,tcptraceroute發(fā)送TCPSYN數(shù)據(jù)包而不是UDP或ICMPECHO數(shù)據(jù)包,所以其不易被阻塞。
tcpdump命令
tcpdump命令允許你捕獲網(wǎng)絡(luò)數(shù)據(jù)包來進(jìn)一步分析。使用-D選項列出可用的網(wǎng)絡(luò)接口。
$tcpdump-D
1.eth0[Up,Running]
2.any(Pseudo-devicethatcapturesonallinterfaces)[Up,Running]
3.lo[Up,Running,Loopback]
4.nflog(Linuxnetfilterlog(NFLOG)interface)
5.nfqueue(Linuxnetfilterqueue(NFQUEUE)interface)
6.usbmon1(USBbusnumber1)
7.usbmon2(USBbusnumber2)
8.usbmon3(USBbusnumber3)
9.usbmon4(USBbusnumber4)
10.usbmon5(USBbusnumber5)
11.usbmon6(USBbusnumber6)
12.usbmon7(USBbusnumber7)
-v選項控制你看到的細(xì)節(jié)程度——越多的v,越詳細(xì),但超過3個v不會有更多意義。
$sudotcpdump-vvhost192.168.0.32
tcpdump:listeningoneth0,link-typeEN10MB(Ethernet),capturesize262144bytes
20:26:31.321816IP(tos0x10,ttl64,id22411,offset0,flags[DF],protoTCP(6),length184)
192.168.0.6.ssh>192.168.0.32.57294:Flags[P.],cksum0x8221(incorrect->0x0254),seq3891093411:3891093555,ack2388988308,win329,length144
20:26:31.321984IP(tos0x10,ttl64,id22412,offset0,flags[DF],protoTCP(6),length200)
192.168.0.6.ssh>192.168.0.32.57294:Flags[P.],cksum0x8231(incorrect->0x3db0),seq144:304,ack1,win329,length160
20:26:31.323791IP(tos0x0,ttl128,id20259,offset0,flags[DF],protoTCP(6),length40)
192.168.0.32.57294>192.168.0.6.ssh:Flags[.],cksum0x643d(correct),seq1,ack304,win385,length0
20:26:31.383954IP(tos0x10,ttl64,id22413,offset0,flags[DF],protoTCP(6),length248)
...
當(dāng)你運行像這樣的命令時,會看到非常多的輸出。
這個命令捕獲來自特定主機(jī)和eth0上的11個數(shù)據(jù)包。-w選項標(biāo)識保存捕獲包的文件。在這個示例命令中,我們只要求捕獲11個數(shù)據(jù)包。
$sudotcpdump-c11-ieth0src192.168.0.32-wpackets.pcap
tcpdump:listeningoneth0,link-typeEN10MB(Ethernet),capturesize262144bytes
11packetscaptured
11packetsreceivedbyfilter
0packetsdroppedbykernel
arp命令
arp命令將IPv4地址映射到硬件地址。它所提供的信息也可以在一定程度上用于識別系統(tǒng),因為網(wǎng)絡(luò)適配器可以告訴你使用它們的系統(tǒng)的一些信息。下面的第二個MAC地址,以f8:8e:85開頭,很容易被識別出是Comtrend路由器。
$arp-a
?(192.168.0.12)atb0:c0:90:3f:10:15[ether]oneth0
?(192.168.0.1)atf8:8e:85:35:7f:b9[ether]oneth0
最后想要了解更多關(guān)于Linux發(fā)展前景趨勢,請關(guān)注扣丁學(xué)堂Linux培訓(xùn)官網(wǎng)、微信等平臺,扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育平臺為您提供權(quán)威的
Linux培訓(xùn)視頻教程系統(tǒng),通過千鋒扣丁學(xué)堂金牌講師在線錄制的
Linux視頻教程課程,讓你快速掌握Linux從入門到精通開發(fā)實戰(zhàn)技能??鄱W(xué)堂Linux技術(shù)交流群:422345477。
【關(guān)注微信公眾號獲取更多的學(xué)習(xí)資料】
查看更多關(guān)于“Linux培訓(xùn)資訊”的相關(guān)文章>>
標(biāo)簽:
Linux命令
Linux視頻教程
Linux培訓(xùn)
Linux在線學(xué)習(xí)
Linux在線視頻
Linux系統(tǒng)