目錄
?
監(jiān)控系統(tǒng)狀態(tài)
?
監(jiān)控網(wǎng)卡流量
?
監(jiān)控IO性能
?
查看系統(tǒng)進(jìn)程
?
查看網(wǎng)絡(luò)狀態(tài)
Linux下抓包
Linux網(wǎng)絡(luò)相關(guān)
監(jiān)控系統(tǒng)狀態(tài)
[root@zyshanlinux-01 ~]# w
##當(dāng)前系統(tǒng)時(shí)間,啟動(dòng)至今時(shí)間,目前登錄用戶數(shù),系統(tǒng)負(fù)載:1分鐘,5分鐘,15分鐘內(nèi)系統(tǒng)負(fù)載是多少(單位時(shí)間內(nèi)cpu使用的活動(dòng)進(jìn)程有多少個(gè),不一定是整數(shù),平均值)12:08:10 up 44 min, 2 users, load average: 0.06, 0.04, 0.05
USER ? ? TTY ? ? FROM ? ? ? ? ? ? LOGIN@ ? IDLE ? JCPU ? PCPU WHAT
root ? ? tty1 ? ? ? ? ? ? ? ? ? ? 11:47 ? 20:58 ? 0.03s 0.03s -bash ##本地登錄的用戶
root ? ? pts/0 ? 192.168.106.1 ? 11:34 ? 2.00s 0.05s 0.02s w ##遠(yuǎn)程登錄的用戶
##登錄的是誰(shuí),登錄的終端(從網(wǎng)絡(luò)遠(yuǎn)程登錄來(lái)的就是pts/0,從本地登錄就是tty1),從哪里登錄來(lái)的(遠(yuǎn)程就是ip),用戶登錄的時(shí)間點(diǎn),空閑了多少時(shí)間,使用CPU的時(shí)間,命令。
[root@zyshanlinux-01 ~]# date
2018年 06月 10日 星期日 11:41:41 CST
?
[root@zyshanlinux-01 ~]# uptime ##和w命令是一樣的。12:08:27 up 45 min, 2 users, load average: 0.04, 0.04, 0.05
?
##當(dāng)系統(tǒng)中只有一個(gè)邏輯CPU的時(shí)候,load average: 0.00, 0.01, 0.05中在1分鐘的時(shí)候數(shù)值為1是最理想的,不閑也沒(méi)壓力,即每個(gè)邏輯CPU有一個(gè)進(jìn)程在占用它。第2、3個(gè)數(shù)值分別體現(xiàn)在5分鐘和15分鐘內(nèi)邏輯CPU中進(jìn)程占有量;1分鐘的是最能體現(xiàn)當(dāng)前系統(tǒng)的負(fù)載量的參數(shù)。
12:08:10UP 44 MIN2 USERSLOAD AVERAGE0.060.040.05 當(dāng)前系統(tǒng)時(shí)間 啟動(dòng)至今時(shí)間 目前登錄用戶數(shù) 系統(tǒng)負(fù)載 1分鐘內(nèi)系統(tǒng)負(fù) 5分鐘內(nèi)系統(tǒng)負(fù)載 15分鐘內(nèi)系統(tǒng)負(fù)載
USERTTYFROMLOGIN@IDLEJCPUPCPUWHAT 登錄的用戶 登錄的終端,tty1是本地登錄,pts/0是遠(yuǎn)程終端登錄 登錄來(lái)源(網(wǎng)絡(luò)遠(yuǎn)程登錄就是ip) 用戶登錄的時(shí)間節(jié)點(diǎn) 空閑了多久 JCPU使用的時(shí)間 PCPU使用的時(shí)間 使用的命令
[root@zyshanlinux-01 ~]# cat /proc/cpuinfo ##查看系統(tǒng)有多少個(gè)邏輯CPU
processor : 0 ##數(shù)字0代表有1顆邏輯CPU,數(shù)字1代表2顆邏輯CPU。
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
stepping : 3
microcode : 0x22
cpu MHz : 2393.631
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm epb fsgsbase smep xsaveopt dtherm ida arat pln pts
bogomips : 4788.92
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
[root@zyshanlinux-01 ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b ? swpd ? free ? buff cache ? si ? so ? bi ? bo ? in ? cs us sy id wa st2 0 ? ? 0 1580752 ? 2076 163592 ? 0 ? 0 1232 ? 50 301 608 3 7 82 9 0
[root@zyshanlinux-01 ~]# vmstat 1 ##動(dòng)態(tài)每秒顯示一次
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b ? swpd ? free ? buff cache ? si ? so ? bi ? bo ? in ? cs us sy id wa st2 0 ? ? 0 1580768 ? 2076 163664 ? 0 ? 0 1094 ? 45 281 555 2 6 84 8 00 0 ? ? 0 1580752 ? 2076 163664 ? 0 ? 0 ? ? 0 ? ? 0 111 130 0 0 100 0 00 0 ? ? 0 1580752 ? 2076 163664 ? 0 ? 0 ? ? 0 ? ? 0 100 123 0 0 100 0 00 0 ? ? 0 1580752 ? 2076 163664 ? 0 ? 0 ? ? 0 ? ? 0 ? 80 107 0 1 99 0 0
關(guān)鍵的幾列: r , b , swpd , si , so , bi , bo , us , wa
參數(shù)解析:
注:系統(tǒng)負(fù)載很高,us%可以很低或0(可能在等待或者不運(yùn)行);us%很高,系統(tǒng)負(fù)載肯定會(huì)很高。
[root@zyshanlinux-01 ~]# top
top - 17:07:16 up 5:43, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 88 total, ? 2 running, 86 sleeping, ? 0 stopped, ? 0 zombie
%Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st ##st被偷走的CPU
KiB Mem : 1875480 total, 1542804 free, ? 145232 used, ? 187444 buff/cache
KiB Swap: 2097148 total, 2097148 free, ? ? ? 0 used. 1545540 avail Mem
?PID USER ? ? PR NI ? VIRT ? RES ? SHR S %CPU %MEM ? ? TIME+ COMMAND ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1 root ? ? 20 ? 0 128208 ? 6844 ? 4084 S 0.0 0.4 ? 0:01.77 systemd ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2 root ? ? 20 ? 0 ? ? ? 0 ? ? 0 ? ? 0 S 0.0 0.0 ? 0:00.00 kthreadd ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3 root ? ? 20 ? 0 ? ? ? 0 ? ? 0 ? ? 0 S 0.0 0.0 ? 0:00.24 ksoftirqd/0 ? ? ? ? ? ? ? ? ? ? ? ? ? ?5 root ? ? ? 0 -20 ? ? ? 0 ? ? 0 ? ? 0 S 0.0 0.0 ? 0:00.00 kworker/0:0H ? ? ? ? ? ? ? ? ? ? ? ? ? 6 root ? ? 20 ? 0 ? ? ? 0 ? ? 0 ? ? 0 S 0.0 0.0 ? 0:02.64 kworker/u128:0
PID號(hào)可以通過(guò)命令來(lái)殺死對(duì)應(yīng)PID號(hào)的進(jìn)程。
參數(shù)解析:
TASKSTOTALRUNNINGSLEEPINGSTOPPEDZOMBIE ? 共多少進(jìn)程 正在運(yùn)行的進(jìn)程 休眠的進(jìn)程數(shù) 停止進(jìn)程 僵尸進(jìn)程,由于主進(jìn)程意外終止,遺留下的子進(jìn)程沒(méi)人管,自生自滅
?
監(jiān)控網(wǎng)卡流量
[root@zyshanlinux-01 ~]# sar ##沒(méi)有這個(gè)命令,就需要安裝一個(gè)包
-bash: sar: 未找到命令
[root@zyshanlinux-01 ~]# yum install -y sysstat
已加載插件:fastestmirror
base ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.6 kB 00:00:00
[root@zyshanlinux-01 ~]# sar ##sar不加具體的選項(xiàng)或參數(shù),它就會(huì)去調(diào)用它的歷史文件
無(wú)法打開(kāi) /var/log/sa/sa10: 沒(méi)有那個(gè)文件或目錄 ##sar特性,每次正點(diǎn)10分鐘去抓取系統(tǒng)狀態(tài)保存在該目錄的文件里
[root@zyshanlinux-01 ~]# sar -n DEV 2 3 ##每隔2秒顯示一次,僅顯示3次
Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 2018年06月10日 _x86_64_ (1 CPU)
##時(shí)間 ? ? ? ? 網(wǎng)卡名字 接收數(shù)據(jù)包 發(fā)送數(shù)據(jù)包 接收數(shù)據(jù)量 發(fā)送數(shù)據(jù)量
17時(shí)45分33秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時(shí)45分35秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時(shí)45分35秒 ? ? ens33 ? ? 0.50 ? ? 0.50 ? ? 0.03 ? ? 0.10 ? ? 0.00 ? ? 0.00 ? ? 0.00
?
17時(shí)45分35秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時(shí)45分37秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時(shí)45分37秒 ? ? ens33 ? ? 0.51 ? ? 0.51 ? ? 0.03 ? ? 0.20 ? ? 0.00 ? ? 0.00 ? ? 0.00
?
17時(shí)45分37秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時(shí)45分39秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時(shí)45分39秒 ? ? ens33 ? ? 0.51 ? ? 0.51 ? ? 0.03 ? ? 0.20 ? ? 0.00 ? ? 0.00 ? ? 0.00
?
平均時(shí)間: ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
平均時(shí)間: ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
平均時(shí)間: ? ? ens33 ? ? 0.50 ? ? 0.50 ? ? 0.03 ? ? 0.17 ? ? 0.00 ? ? 0.00 ? ? 0.00
注:接收數(shù)據(jù)包幾千算是正常,上萬(wàn)或幾十萬(wàn)的話就不正常,被攻擊了。可以通過(guò)抓包工具驗(yàn)證是否被攻擊。
[root@zyshanlinux-01 ~]# sar
Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 2018年06月10日 _x86_64_ (1 CPU)
?
17時(shí)40分01秒 ? ? CPU ? ? %user ? ? %nice ? %system ? %iowait ? %steal ? ? %idle
17時(shí)50分01秒 ? ? all ? ? 0.03 ? ? 0.00 ? ? 0.11 ? ? 0.00 ? ? 0.00 ? ? 99.86
18時(shí)00分01秒 ? ? all ? ? 0.03 ? ? 0.00 ? ? 0.10 ? ? 0.00 ? ? 0.00 ? ? 99.86
18時(shí)10分01秒 ? ? all ? ? 0.04 ? ? 0.00 ? ? 0.13 ? ? 0.00 ? ? 0.00 ? ? 99.82
[root@zyshanlinux-01 ~]# ls /var/log/sa/
sa10
?
[root@zyshanlinux-01 ~]# sar -n DEV -f /var/log/sa/sa10
Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 2018年06月10日 _x86_64_ (1 CPU)
?
17時(shí)40分01秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時(shí)50分01秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時(shí)50分01秒 ? ? ens33 ? ? 0.22 ? ? 0.04 ? ? 0.01 ? ? 0.01 ? ? 0.00 ? ? 0.00 ? ? 0.00
注:當(dāng)天/var/log/sa/里面不僅有一個(gè)sa10的文件還有sar10的文件,但只有到明天這個(gè)文件才會(huì)出現(xiàn),兩者有什么區(qū)別呢,sa10是二進(jìn)制文件不能用cat直接看只能用sar -n DEV查看,sar10可以用cat直接查看。
[root@zyshanlinux-01 ~]# sar -q 1 3 ##每秒顯示1次,僅顯示3次
Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 2018年06月10日 _x86_64_ (1 CPU)
?
23時(shí)17分11秒 ? runq-sz plist-sz ? ldavg-1 ? ldavg-5 ldavg-15 ? blocked
23時(shí)17分12秒 ? ? ? ? 0 ? ? ? 105 ? ? 0.02 ? ? 0.07 ? ? 0.05 ? ? ? ? 0
23時(shí)17分13秒 ? ? ? ? 0 ? ? ? 105 ? ? 0.02 ? ? 0.07 ? ? 0.05 ? ? ? ? 0
23時(shí)17分14秒 ? ? ? ? 0 ? ? ? 105 ? ? 0.02 ? ? 0.07 ? ? 0.05 ? ? ? ? 0
平均時(shí)間: ? ? ? ? 0 ? ? ? 105 ? ? 0.02 ? ? 0.07 ? ? 0.05 ? ? ? ? 0
[root@zyshanlinux-01 ~]# sar -b 1 3 ##每秒顯示1次,僅顯示3次
Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 2018年06月10日 _x86_64_ (1 CPU)
?
23時(shí)18分37秒 ? ? ? tps ? ? rtps ? ? wtps ? bread/s ? bwrtn/s
23時(shí)18分38秒 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
23時(shí)18分39秒 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
23時(shí)18分40秒 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
平均時(shí)間: ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
第一次用這個(gè)命令,會(huì)出現(xiàn)沒(méi)有命令的錯(cuò)誤,需要安裝2個(gè)包才可以執(zhí)行這個(gè)命令
[root@zyshanlinux-01 ~]# nload
?
Device ens33 [192.168.106.128] (1/2):
===========================================================================================================
Incoming: ##進(jìn)來(lái)的流量,被攻擊的話,這個(gè)流量就會(huì)變得很大
?
?
?
?
?
?Curr: 944.00 Bit/sAvg: 1.05 kBit/sMin: 944.00 Bit/sMax: 1.87 kBit/sTtl: 7.73 MByte
Outgoing: ##出去的流量,買(mǎi)了100的帶寬跑到70多了還是正常,跑滿的就證明帶寬不夠了
?
?
?
?
?Curr: 8.29 kBit/sAvg: 8.30 kBit/sMin: 4.27 kBit/sMax: 8.78 kBit/sTtl: 3.33 MByte
?
監(jiān)控IO性能
iostat和sar是同一個(gè)安裝包的,都是sysstat,安裝了這個(gè)包后,2個(gè)命令都可以用了。
[root@zyshanlinux-01 ~]# iostat -x 1 1 ##每秒顯示1次,僅顯示1次
Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 2018年06月10日 _x86_64_ (1 CPU)
?
avg-cpu: %user ? %nice %system %iowait %steal ? %idle0.08 ? 0.00 ? 0.18 ? 0.06 ? 0.00 ? 99.67
?
Device: ? ? ? ? rrqm/s ? wrqm/s ? ? r/s ? ? w/s ? rkB/s ? wkB/s avgrq-sz avgqu-sz ? await r_await w_await svctm %util ##%util重點(diǎn)參數(shù),CPU等待IO硬盤(pán)時(shí)間的百分比,越大硬盤(pán)越差,硬盤(pán)太慢。這個(gè)參數(shù)和硬盤(pán)的讀寫(xiě)參數(shù)是相關(guān)聯(lián)的,這個(gè)百分比大讀寫(xiě)數(shù)據(jù)也大,如果讀寫(xiě)幾乎為0,這個(gè)百分比仍然很大,硬盤(pán)異常
sdb ? ? ? ? ? ? ? 0.00 ? ? 0.00 ? 0.01 ? 0.00 ? ? 0.10 ? ? 0.00 ? 28.99 ? ? 0.00 ? 2.75 ? 2.75 ? 0.00 ? 2.05 ? 0.00
sda ? ? ? ? ? ? ? 0.00 ? ? 0.01 ? 0.16 ? 0.09 ? ? 6.86 ? ? 3.25 ? 80.63 ? ? 0.02 ? 74.62 ? 14.22 177.01 11.07 ? 0.28
scd0 ? ? ? ? ? ? 0.00 ? ? 0.00 ? 0.00 ? 0.00 ? ? 0.03 ? ? 0.00 ? 114.22 ? ? 0.00 ? 0.83 ? 0.83 ? 0.00 ? 0.72 ? 0.00
dm-0 ? ? ? ? ? ? 0.00 ? ? 0.00 ? 0.00 ? 0.00 ? ? 0.03 ? ? 0.00 ? 48.19 ? ? 0.00 ? 6.42 ? 6.42 ? 0.00 ? 5.63 ? 0.00
[root@zyshanlinux-01 ~]# iotop ##命令沒(méi)有,需要安裝下面的包才可以執(zhí)行這個(gè)命令
-bash: iotop: 未找到命令
[root@zyshanlinux-01 ~]# yum install -y iotop
?
[root@zyshanlinux-01 ~]# iotop
?
Total DISK READ : 0.00 B/s | Total DISK WRITE : ? ? ? 0.00 B/s
Actual DISK READ: 0.00 B/s | Actual DISK WRITE: ? ? ? 0.00 B/sTID PRIO USER ? ? DISK READ DISK WRITE SWAPIN ? ? IO> ? COMMAND ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % systemd --switched-root~system --deserialize 212 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kthreadd]3 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0]5 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kworker/0:0H]7 rt/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [migration/0]8 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [rcu_bh]9 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [rcu_sched]10 rt/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [watchdog/0]12 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kdevtmpfs]13 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [netns]14 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [khungtaskd]15 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [writeback]16 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kintegrityd]17 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [bioset]18 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kblockd]19 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [md]25 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kswapd0]26 be/5 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [ksmd]27 be/7 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [khugepaged]28 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [crypto]547 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % systemd-logind36 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kthrotld]549 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % VGAuthService -s550 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % vmtoolsd39 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kpsmoused]41 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [ipv6_addrconf]557 be/4 chrony ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % chronyd564 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % rsyslogd -n [in:imjournal]565 be/4 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % rsyslogd -n [rs:main Q:Reg]566 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [kdmflush]567 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [bioset]60 be/0 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % [deferwq]522 be/3 root ? ? ? 0.00 B/s ? 0.00 B/s 0.00 % 0.00 % auditd
[root@zyshanlinux-01 ~]# freetotal ? ? ? used ? ? ? free ? ? shared buff/cache ? available
Mem: ? ? ? 1875480 ? ? 145684 ? ? 1363624 ? ? ? 8800 ? ? 366172 ? ? 1537304
Swap: ? ? ? 2097148 ? ? ? ? ? 0 ? ? 2097148
[root@zyshanlinux-01 ~]# free -mtotal ? ? ? used ? ? ? free ? ? shared buff/cache ? available
Mem: ? ? ? ? ? 1831 ? ? ? ? 142 ? ? ? 1331 ? ? ? ? ? 8 ? ? ? ? 357 ? ? ? 1501
Swap: ? ? ? ? 2047 ? ? ? ? ? 0 ? ? ? 2047
[root@zyshanlinux-01 ~]# free -htotal ? ? ? used ? ? ? free ? ? shared buff/cache ? available
Mem: ? ? ? ? ? 1.8G ? ? ? 142M ? ? ? 1.3G ? ? ? 8.6M ? ? ? 357M ? ? ? 1.5G
Swap: ? ? ? ? 2.0G ? ? ? ? 0B ? ? ? 2.0G
[root@zyshanlinux-01 ~]# free -gtotal ? ? ? used ? ? ? free ? ? shared buff/cache ? available
Mem: ? ? ? ? ? ? 1 ? ? ? ? ? 0 ? ? ? ? ? 1 ? ? ? ? ? 0 ? ? ? ? ? 0 ? ? ? ? ? 1
Swap: ? ? ? ? ? ? 1 ? ? ? ? ? 0 ? ? ? ? ? 1
緩沖/緩存,cpu運(yùn)算速度快,磁盤(pán)很慢,所以需要內(nèi)存進(jìn)行緩沖,以下就是數(shù)據(jù)不同流向的區(qū)別
[root@zyshanlinux-01 ~]# 0000(磁盤(pán))-->內(nèi)存(cache)-->cpu ? ? ? ^C
[root@zyshanlinux-01 ~]# cpu(00000) -->內(nèi)存(buffer)--> 磁盤(pán) ? ? ^C
?
查看系統(tǒng)進(jìn)程
把你當(dāng)前進(jìn)程的快照打印出來(lái),ps是一次性靜態(tài)的把系統(tǒng)進(jìn)程列出來(lái),top則是實(shí)時(shí)動(dòng)態(tài)的。
[root@zyshanlinux-01 ~]# ps aux
USER ? ? ? PID %CPU %MEM ? VSZ ? RSS TTY ? ? STAT START ? TIME COMMAND
root ? ? ? ? 1 0.1 0.3 128208 6844 ? ? ? ? Ss ? 23:08 ? 0:01 /usr/lib/systemd/systemd --switched-root -
root ? ? ? ? 2 0.0 0.0 ? ? 0 ? ? 0 ? ? ? ? S ? 23:08 ? 0:00 [kthreadd]
root ? ? ? ? 3 0.0 0.0 ? ? 0 ? ? 0 ? ? ? ? S ? 23:08 ? 0:00 [ksoftirqd/0]
root ? ? ? ? 4 0.2 0.0 ? ? 0 ? ? 0 ? ? ? ? S ? 23:08 ? 0:01 [kworker/0:0]
root ? ? ? ? 5 0.0 0.0 ? ? 0 ? ? 0 ? ? ? ? S< ? 23:08 ? 0:00 [kworker/0:0H]
root ? ? ? ? 6 0.0 0.0 ? ? 0 ? ? 0 ? ? ? ? S ? 23:08 ? 0:00 [kworker/u128:0]
root ? ? ? ? 7 0.0 0.0 ? ? 0 ? ? 0 ? ? ? ? S ? 23:08 ? 0:00 [migration/0]
?
[root@zyshanlinux-01 ~]# ps -elf
F S UID ? ? ? PID PPID C PRI NI ADDR SZ WCHAN STIME TTY ? ? ? ? TIME CMD
4 S root ? ? ? ? 1 ? ? 0 0 80 ? 0 - 32052 ep_pol 23:08 ? ? ? ? 00:00:01 /usr/lib/systemd/systemd --switc
1 S root ? ? ? ? 2 ? ? 0 0 80 ? 0 - ? ? 0 kthrea 23:08 ? ? ? ? 00:00:00 [kthreadd]
1 S root ? ? ? ? 3 ? ? 2 0 80 ? 0 - ? ? 0 smpboo 23:08 ? ? ? ? 00:00:00 [ksoftirqd/0]
1 S root ? ? ? ? 4 ? ? 2 0 80 ? 0 - ? ? 0 worker 23:08 ? ? ? ? 00:00:01 [kworker/0:0]
1 S root ? ? ? ? 5 ? ? 2 0 60 -20 - ? ? 0 worker 23:08 ? ? ? ? 00:00:00 [kworker/0:0H]
[root@zyshanlinux-01 ~]# ps aux |grep mysql ##查看該進(jìn)程是否在運(yùn)行
root ? ? 1298 0.0 0.0 112720 ? 972 pts/0 ? R+ ? 23:22 ? 0:00 grep --color=auto mysql
[root@zyshanlinux-01 ~]# kill 1132 ##用PID號(hào)可以殺死該進(jìn)程
[root@zyshanlinux-01 ~]# ps aux |grep qmgr ##確認(rèn)該進(jìn)程確實(shí)是被殺死
postfix ? 1157 0.0 0.2 89756 4048 ? ? ? ? S ? 23:08 ? 0:00 qmgr -l -t unix -u
root ? ? 1300 0.0 0.0 112720 ? 972 pts/0 ? R+ ? 23:23 ? 0:00 grep --color=auto qmgr
[root@zyshanlinux-01 ~]# ls -l /proc/521/ ##proc加上數(shù)字的文件夾就是進(jìn)程的PID號(hào)
總用量 0
dr-xr-xr-x. 2 root root 0 6月 10 23:08 attr
-rw-r--r--. 1 root root 0 6月 10 23:23 autogroup
-r--------. 1 root root 0 6月 10 23:23 auxv
STAT部分說(shuō)明
D 不能中斷的進(jìn)程
R run狀態(tài)的進(jìn)程
S sleep狀態(tài)的進(jìn)程
[root@zyshanlinux-01 ~]# ps aux |grep vmstat
root ? ? 1307 0.0 0.0 148356 1352 pts/0 ? S+ ? 23:27 ? 0:00 vmstat 1
root ? ? 1309 0.0 0.0 112720 ? 972 pts/1 ? R+ ? 23:27 ? 0:00 grep --color=auto vmstat
[root@zyshanlinux-01 ~]# ps aux |grep vmstat
root ? ? 1307 0.0 0.0 148356 1352 pts/0 ? T ? 23:27 ? 0:00 vmstat 1
root ? ? 1311 0.0 0.0 112720 ? 968 pts/1 ? R+ ? 23:27 ? 0:00 grep --color=auto vmstat
數(shù)量較少,有就用命令殺死它。
[root@zyshanlinux-01 ~]# ps aux |grep vmstat
root ? ? 1307 0.0 0.0 148356 1352 pts/0 ? S+ ? 23:27 ? 0:00 vmstat 1
root ? ? 1313 0.0 0.0 112720 ? 968 pts/1 ? R+ ? 23:28 ? 0:00 grep --color=auto vmstat
?
查看網(wǎng)絡(luò)狀態(tài)
[root@zyshanlinux-01 ~]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address ? ? ? ? ? Foreign Address ? ? ? ? State ? ? ? PID/Program name ? ?
tcp ? ? ? 0 ? ? 0 0.0.0.0:22 ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? 912/sshd ? ? ? ? ? ?
tcp ? ? ? 0 ? ? 0 127.0.0.1:25 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? 1130/master ? ? ? ?
tcp6 ? ? ? 0 ? ? 0 :::22 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ? 912/sshd ? ? ? ? ? ?
tcp6 ? ? ? 0 ? ? 0 ::1:25 ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ? 1130/master ? ? ? ?
udp ? ? ? 0 ? ? 0 127.0.0.1:323 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? ? ? ? ? 557/chronyd ? ? ? ?
udp6 ? ? ? 0 ? ? 0 ::1:323 ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 557/chronyd ? ? ? ?
raw6 ? ? ? 0 ? ? 0 :::58 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? 7 ? ? ? ? ? 610/NetworkManager ?
Active UNIX domain sockets (only servers)
Proto RefCnt Flags ? ? ? Type ? ? ? State ? ? ? ? I-Node ? PID/Program name ? ? Path
[root@zyshanlinux-01 ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address ? ? ? ? ? Foreign Address ? ? ? ? State ? ? ?
tcp ? ? ? 0 ? ? 0 0.0.0.0:22 ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ?
tcp ? ? ? 0 ? ? 0 127.0.0.1:25 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ?
tcp ? ? ? 0 ? ? 52 192.168.106.128:22 ? ? 192.168.106.1:14605 ? ? ESTABLISHED
tcp6 ? ? ? 0 ? ? 0 :::22 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ?
tcp6 ? ? ? 0 ? ? 0 ::1:25 ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ?
udp ? ? ? 0 ? ? 0 127.0.0.1:323 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? ? ? ? ?
udp6 ? ? ? 0 ? ? 0 ::1:323 ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
raw6 ? ? ? 0 ? ? 0 :::58 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? 7 ? ? ? ? ?
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags ? ? ? Type ? ? ? State ? ? ? ? I-Node ? Path
unix 2 ? ? [ ACC ] ? ? STREAM ? ? LISTENING ? ? 15871 ? /var/run/vmware/guestServicePipe
unix 2 ? ? [ ACC ] ? ? STREAM ? ? LISTENING ? ? 18867 ? private/proxymap
unix 2 ? ? [ ACC ] ? ? STREAM ? ? LISTENING ? ? 11901 ? 1/systemd ? ? ? ? ? /run/lvm/lvmpolld.socket
unix 2 ? ? [ ACC ] ? ? STREAM ? ? LISTENING ? ? 11915 ? 1/systemd ? ? ? ? ? /run/lvm/lvmetad.socket
[root@zyshanlinux-01 ~]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address ? ? ? ? ? Foreign Address ? ? ? ? State ? ? ? PID/Program name ? ?
tcp ? ? ? 0 ? ? 0 0.0.0.0:22 ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? 912/sshd ? ? ? ? ? ?
tcp ? ? ? 0 ? ? 0 127.0.0.1:25 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? 1130/master ? ? ? ?
tcp6 ? ? ? 0 ? ? 0 :::22 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ? 912/sshd ? ? ? ? ? ?
tcp6 ? ? ? 0 ? ? 0 ::1:25 ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ? 1130/master ? ? ? ?
[root@zyshanlinux-01 ~]# netstat -ltunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address ? ? ? ? ? Foreign Address ? ? ? ? State ? ? ? PID/Program name ? ?
tcp ? ? ? 0 ? ? 0 0.0.0.0:22 ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? 912/sshd ? ? ? ? ? ?
tcp ? ? ? 0 ? ? 0 127.0.0.1:25 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? 1130/master ? ? ? ?
tcp6 ? ? ? 0 ? ? 0 :::22 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ? 912/sshd ? ? ? ? ? ?
tcp6 ? ? ? 0 ? ? 0 ::1:25 ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? LISTEN ? ? 1130/master ? ? ? ?
udp ? ? ? 0 ? ? 0 127.0.0.1:323 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? ? ? ? ? 557/chronyd ? ? ? ?
udp6 ? ? ? 0 ? ? 0 ::1:323 ? ? ? ? ? ? ? ? :::*
ss -an 和nestat 異曲同工,不足是不會(huì)顯示進(jìn)程的名字
[root@zyshanlinux-01 ~]# ss -an |grep -i listen
u_str LISTEN ? ? 0 ? ? 32 ? ? /var/run/vmware/guestServicePipe 15871 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/proxymap 18867 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/proxywrite 18870 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_seq LISTEN ? ? 0 ? ? 128 ? /run/udev/control 12110 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 128 ? /run/systemd/private 11855 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 128 ? /var/run/dbus/system_bus_socket 14716 ? ? ? ? ? ? ? ? * 0
u_str LISTEN ? ? 0 ? ? 128 ? /run/lvm/lvmpolld.socket 11901 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 128 ? /run/lvm/lvmetad.socket 11915 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? public/pickup 18835 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? public/cleanup 18839 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? public/qmgr 18842 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? public/flush 18864 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? public/showq 18879 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/smtp 18873 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/tlsmgr 18846 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/rewrite 18849 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/bounce 18852 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/defer 18855 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/trace 18858 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/verify 18861 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/relay 18876 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/error 18882 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/retry 18885 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/discard 18888 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/local 18891 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/virtual 18894 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/lmtp 18897 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/anvil 18900 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 100 ? private/scache 18903 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
u_str LISTEN ? ? 0 ? ? 128 ? /run/systemd/journal/stdout 7665 ? ? ? ? ? ? ? ? * 0 ? ? ? ? ? ? ? ? ?
tcp ? LISTEN ? ? 0 ? ? 128 ? ? ? *:22 ? ? ? ? ? ? ? ? ? *:* ? ? ? ? ? ? ? ? ?
tcp ? LISTEN ? ? 0 ? ? 100 ? 127.0.0.1:25 ? ? ? ? ? ? ? ? ? *:* ? ? ? ? ? ? ? ? ?
tcp ? LISTEN ? ? 0 ? ? 128 ? ? :::22 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ?
tcp ? LISTEN ? ? 0 ? ? 100 ? ? ::1:25 ? ? ? ? ? ? ? ? ? :::* ? ? ? ?
一個(gè)小技巧:直接查看以下數(shù)據(jù)的并發(fā)量。
[root@zyshanlinux-01 ~]# netstat -an |awk '/^tcp/{++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'
LISTEN 4
ESTABLISHED 1
?
Linux下抓包
[root@zyshanlinux-01 ~]# yum install -y tcpdump ##第一次運(yùn)行這個(gè)命令要安裝這個(gè)包
用法:tcpdump -nn
tcpdump -nn -i ens33
[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 ##特殊的設(shè)備需要加上網(wǎng)卡名
08:41:31.158670 IP 192.168.106.1.1512 > 192.168.106.128.22: Flags [.], ack 802176, win 2048, length 0
08:41:31.158683 IP 192.168.106.128.22 > 192.168.106.1.1512: Flags [P.], seq 802356:802536, ack 157, win 251, length 180
##得出的結(jié)果都是數(shù)據(jù)包的流向,成對(duì)出現(xiàn),還要關(guān)注一個(gè)重要參數(shù)length 180,長(zhǎng)度參數(shù)。有種攻擊是DDos,即udp flood洪水攻擊,可以發(fā)出幾百G流量攻擊,只能用防攻擊的設(shè)備或服務(wù)。
[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 port 22 ##指定22端口的
[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 not port 22 ##排除22端口的
[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 not port 22 and host 192.168.106.1 ##排除22端口,只要192.168.106.1 ip的
[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 -c 10 ##只抓前10條
?
[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 -c 10 -w /tmp/1.cap ##抓10個(gè)包寫(xiě)入1.cap里面,單開(kāi)一個(gè)終端時(shí)這條命令可能會(huì)卡住,因?yàn)闆](méi)有數(shù)據(jù)流動(dòng),所以沒(méi)產(chǎn)生包,命令就卡住,可以重新開(kāi)個(gè)終端運(yùn)行寫(xiě)top或vmstat 1的命令產(chǎn)生些包,這條命令就會(huì)很快完成抓包任務(wù)。
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
10 packets captured
10 packets received by filter
0 packets dropped by kerne
?
[root@zyshanlinux-01 ~]# file /tmp/1.cap ##可以用file查看
/tmp/1.cap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144)
[root@zyshanlinux-01 ~]# cat /tmp/1.cap ##因?yàn)槭亲サ臄?shù)據(jù)包,包的內(nèi)容,cat你是看不懂得
?
[root@zyshanlinux-01 ~]# tcpdump -r /tmp/1.cap ##可以用-r來(lái)看,就是讀數(shù)據(jù)流;但實(shí)際上1.cap中是真真正正得寫(xiě)入數(shù)據(jù)包
reading from file /tmp/1.cap, link-type EN10MB (Ethernet)
08:59:45.166244 IP zyshanlinux-01.ssh > 192.168.106.1.wins: Flags [P.], seq 3728788926:3728789074, ack 2081729664, win 251, length 148
08:59:45.166661 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [.], ack 148, win 2047, length 0
08:59:51.222568 IP 192.168.106.1.49249 > 239.255.255.250.ssdp: UDP, length 129
08:59:51.323252 IP 192.168.106.1.49249 > 239.255.255.250.ssdp: UDP, length 129
08:59:52.388207 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [P.], seq 1:53, ack 148, win 2047, length 52
08:59:52.388769 IP zyshanlinux-01.ssh > 192.168.106.1.wins: Flags [P.], seq 148:200, ack 53, win 251, length 52
08:59:52.430645 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [.], ack 200, win 2053, length 0
08:59:52.508157 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [P.], seq 53:105, ack 200, win 2053, length 52
08:59:52.508666 IP zyshanlinux-01.ssh > 192.168.106.1.wins: Flags [P.], seq 200:252, ack 105, win 251, length 52
08:59:52.549433 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [.], ack 252, win 2052, length 0
[root@zyshanlinux-01 ~]# yum install -y wireshark ##第1次運(yùn)行該命令需要安裝
[root@zyshanlinux-01 ~]# tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri" ##需要線上的系統(tǒng)才能抓到,
tshark: -R without -2 is deprecated. For single-pass filtering use -Y.
Running as user "root" and group "root". This could be dangerous.
Capturing on 'nflog'
^C0 packets captured
?
Linux網(wǎng)絡(luò)相關(guān)
[root@zyshanlinux-01 ~]# ifconfig -a ##加-a選項(xiàng),如果網(wǎng)卡宕機(jī)或者沒(méi)有ip的時(shí)候是不顯示的。
如果你的機(jī)房在國(guó)外,你單獨(dú)執(zhí)行關(guān)閉網(wǎng)卡命令,你就要去國(guó)外重啟網(wǎng)卡;這時(shí)你就應(yīng)該關(guān)閉和重啟服務(wù)一起執(zhí)行。
[root@zyshanlinux-01 ~]# ifdown ens33 && ifup ens33
成功斷開(kāi)設(shè)備 'ens33'。
連接已成功激活(D-Bus 活動(dòng)路徑:/org/freedesktop/NetworkManager/ActiveConnection/4)
[root@zyshanlinux-01 ~]# ifdown ens33;ifup ens33
成功斷開(kāi)設(shè)備 'ens33'。
連接已成功激活(D-Bus 活動(dòng)路徑:/org/freedesktop/NetworkManager/ActiveConnection/5)
[root@zyshanlinux-01 ~]# cd /etc/sysconfig/network-scripts/
[root@zyshanlinux-01 network-scripts]# ls
ifcfg-ens33 ifdown-ippp ifdown-routes ? ifup ? ? ? ? ifup-ipv6 ? ifup-ppp ? ? ? ifup-tunnel
ifcfg-lo ? ? ifdown-ipv6 ifdown-sit ? ? ? ifup-aliases ifup-isdn ? ifup-routes ? ifup-wireless
ifdown ? ? ? ifdown-isdn ifdown-Team ? ? ifup-bnep ? ? ifup-plip ? ifup-sit ? ? ? init.ipv6-global
ifdown-bnep ifdown-post ifdown-TeamPort ifup-eth ? ? ifup-plusb ifup-Team ? ? network-functions
ifdown-eth ? ifdown-ppp ? ifdown-tunnel ? ifup-ippp ? ? ifup-post ? ifup-TeamPort network-functions-ipv6
[root@zyshanlinux-01 network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:0
[root@zyshanlinux-01 network-scripts]# vi !$
vi ifcfg-ens33\:0
[root@zyshanlinux-01 network-scripts]# ifdown ens33;ifup ens33
成功斷開(kāi)設(shè)備 'ens33'。
連接已成功激活(D-Bus 活動(dòng)路徑:/org/freedesktop/NetworkManager/ActiveConnection/8)
[root@zyshanlinux-01 network-scripts]# ifconfig ##多出新的虛擬網(wǎng)卡ens33:0:
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.106.128 netmask 255.255.255.0 broadcast 192.168.106.255inet6 fe80::8fc3:bbdf:ba89:22a7 prefixlen 64 scopeid 0x20<link>ether 00:0c:29:a1:d4:eb txqueuelen 1000 (Ethernet)RX packets 54409 bytes 25525816 (24.3 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 209646 bytes 52121081 (49.7 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
?
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.106.150 netmask 255.255.255.0 broadcast 192.168.106.255ether 00:0c:29:a1:d4:eb txqueuelen 1000 (Ethernet)
?
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1 (Local Loopback)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@zyshanlinux-01 network-scripts]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok ##ok正常連接網(wǎng)線
[root@zyshanlinux-01 network-scripts]# ethtool ens33
Settings for ens33:Supported ports: [ TP ]Supported link modes: ? 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: NoSupports auto-negotiation: YesAdvertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: NoAdvertised auto-negotiation: YesSpeed: 1000Mb/sDuplex: FullPort: Twisted PairPHYAD: 0Transceiver: internalAuto-negotiation: onMDI-X: off (auto)Supports Wake-on: dWake-on: dCurrent message level: 0x00000007 (7)drv probe linkLink detected: yes ##yes正常連接網(wǎng)線
[root@zyshanlinux-01 ~]# hostnamectl set-hostname zyshanlinux-001 ?
[root@zyshanlinux-01 ~]# hostname ##更改主機(jī)名需要退出再重新登錄,或者用hostname命令查看
zyshanlinux-001
[root@zyshanlinux-01 ~]# bash ##用子shell也可查看
[root@zyshanlinux-001 ~]# exit
exit
[root@zyshanlinux-01 ~]# cat /etc/hostname ##主機(jī)名的配置文件
zyshanlinux-001
[root@zyshanlinux-01 ~]# cat /etc/resolv.conf ##查看DNS
# Generated by NetworkManager
nameserver 119.29.29.29
[root@zyshanlinux-01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 ##網(wǎng)卡的配置文件
##增加谷歌的DNS2=8.8.8.8
[root@zyshanlinux-01 ~]# ifdown ens33;ifup ens33
成功斷開(kāi)設(shè)備 'ens33'。
連接已成功激活(D-Bus 活動(dòng)路徑:/org/freedesktop/NetworkManager/ActiveConnection/9)
[root@zyshanlinux-01 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 119.29.29.29
nameserver 8.8.8.8 ##可以看到新增的DNS
[root@zyshanlinux-01 ~]# vim /etc/resolv.conf ##可以臨時(shí)更改DNS,但重啟后會(huì)被網(wǎng)卡的DNS配置文件覆蓋
[root@zyshanlinux-01 ~]# cat /etc/hosts ##查看配置文件
127.0.0.1 ? localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 ? ? ? ? localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@zyshanlinux-01 ~]# ping www.qq123.com ##公網(wǎng)IP
PING www.qq.com (140.206.160.207) 56(84) bytes of data.
64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=1 ttl=128 time=54.0 ms
64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=2 ttl=128 time=115 ms
64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=3 ttl=128 time=109 ms
64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=4 ttl=128 time=51.3 ms
^C
--- www.qq.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 51.387/82.591/115.483/29.951 ms
[root@zyshanlinux-01 ~]# vi /etc/hosts ##可以指定自定義IP,多個(gè)域名指向一個(gè)IP空格隔開(kāi),多個(gè)IP指向一個(gè)域名只執(zhí)行最后一個(gè)IP,以行為單位,不能換行。
127.0.0.1 ? localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 ? ? ? ? localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.106.150 www.qq123.com www.19.com www.zyshan.com
127.0.0.1 www.19.com
?
[root@zyshanlinux-01 ~]# ping www.qq123.com
PING www.qq123.com (192.168.106.150) 56(84) bytes of data.
64 bytes from www.qq123.com (192.168.106.150): icmp_seq=1 ttl=64 time=0.084 ms
64 bytes from www.qq123.com (192.168.106.150): icmp_seq=2 ttl=64 time=0.102 ms
64 bytes from www.qq123.com (192.168.106.150): icmp_seq=3 ttl=64 time=0.105 ms
64 bytes from www.qq123.com (192.168.106.150): icmp_seq=4 ttl=64 time=0.104 ms
64 bytes from www.qq123.com (192.168.106.150): icmp_seq=5 ttl=64 time=0.102 ms
^C
--- www.qq123.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.084/0.099/0.105/0.011 ms
[root@zyshanlinux-01 ~]# ping www.19.com ##只執(zhí)行最后一個(gè)IP
PING www.qq123.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.044 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.098 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.097 ms
^C
--- www.qq123.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.044/0.079/0.098/0.027 ms
在window下不生效,只在linux本機(jī)下才能生效
C:\Users\zhengyushan>ping www.qq123.com
?
正在 Ping www.qq123.com [211.155.235.108] 具有 32 字節(jié)的數(shù)據(jù):
來(lái)自 211.155.235.108 的回復(fù): 字節(jié)=32 時(shí)間=49ms TTL=226
來(lái)自 211.155.235.108 的回復(fù): 字節(jié)=32 時(shí)間=57ms TTL=226
來(lái)自 211.155.235.108 的回復(fù): 字節(jié)=32 時(shí)間=55ms TTL=226
來(lái)自 211.155.235.108 的回復(fù): 字節(jié)=32 時(shí)間=54ms TTL=226
?
211.155.235.108 的 Ping 統(tǒng)計(jì)信息:數(shù)據(jù)包: 已發(fā)送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計(jì)時(shí)間(以毫秒為單位):最短 = 49ms,最長(zhǎng) = 57ms,平均 = 53ms
?
C:\Users\zhengyushan>www.19.com
'www.19.com' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序
或批處理文件。
?
拓展閱讀:
tcp三次握手四次揮手(重點(diǎn)) http://www.doc88.com/p-9913773324388.html
tshark幾個(gè)用法 http://ask.apelearn.com/question/995
延伸閱讀 :
TCP 三次握手和四次揮手https://blog.csdn.net/qq_25677349/article/details/80468409
TCP 之三次握手和四次揮手http://baijiahao.baidu.com/s?id=1600656878316112806&wfr=spider&for=pc
TCP、UDP以及HTTP的簡(jiǎn)單講解https://www.cnblogs.com/xiohao/p/4439164.html
認(rèn)識(shí)cpu、核、進(jìn)程與線程——備忘篇https://blog.csdn.net/zhengyshan/article/details/80641770
總結(jié)
以上是生活随笔 為你收集整理的Linux日常运维管理技巧(一)监控系统状态、监控网卡流量、监控IO性能、查看系统进程、查看网络状态、Linux下抓包tcpdump、Linux网络相关、DNS配置 的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔 網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔 推薦給好友。