目錄
?
監控系統狀態
?
監控網卡流量
?
監控IO性能
?
查看系統進程
?
查看網絡狀態
Linux下抓包
Linux網絡相關
監控系統狀態
[root@zyshanlinux-01 ~]# w
##當前系統時間,啟動至今時間,目前登錄用戶數,系統負載:1分鐘,5分鐘,15分鐘內系統負載是多少(單位時間內cpu使用的活動進程有多少個,不一定是整數,平均值)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 ##遠程登錄的用戶
##登錄的是誰,登錄的終端(從網絡遠程登錄來的就是pts/0,從本地登錄就是tty1),從哪里登錄來的(遠程就是ip),用戶登錄的時間點,空閑了多少時間,使用CPU的時間,命令。
[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
?
##當系統中只有一個邏輯CPU的時候,load average: 0.00, 0.01, 0.05中在1分鐘的時候數值為1是最理想的,不閑也沒壓力,即每個邏輯CPU有一個進程在占用它。第2、3個數值分別體現在5分鐘和15分鐘內邏輯CPU中進程占有量;1分鐘的是最能體現當前系統的負載量的參數。
12:08:10UP 44 MIN2 USERSLOAD AVERAGE0.060.040.05 當前系統時間 啟動至今時間 目前登錄用戶數 系統負載 1分鐘內系統負 5分鐘內系統負載 15分鐘內系統負載
USERTTYFROMLOGIN@IDLEJCPUPCPUWHAT 登錄的用戶 登錄的終端,tty1是本地登錄,pts/0是遠程終端登錄 登錄來源(網絡遠程登錄就是ip) 用戶登錄的時間節點 空閑了多久 JCPU使用的時間 PCPU使用的時間 使用的命令
[root@zyshanlinux-01 ~]# cat /proc/cpuinfo ##查看系統有多少個邏輯CPU
processor : 0 ##數字0代表有1顆邏輯CPU,數字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 ##動態每秒顯示一次
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
關鍵的幾列: r , b , swpd , si , so , bi , bo , us , wa
參數解析:
注:系統負載很高,us%可以很低或0(可能在等待或者不運行);us%很高,系統負載肯定會很高。
[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號可以通過命令來殺死對應PID號的進程。
參數解析:
TASKSTOTALRUNNINGSLEEPINGSTOPPEDZOMBIE ? 共多少進程 正在運行的進程 休眠的進程數 停止進程 僵尸進程,由于主進程意外終止,遺留下的子進程沒人管,自生自滅
?
監控網卡流量
[root@zyshanlinux-01 ~]# sar ##沒有這個命令,就需要安裝一個包
-bash: sar: 未找到命令
[root@zyshanlinux-01 ~]# yum install -y sysstat
已加載插件:fastestmirror
base ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.6 kB 00:00:00
[root@zyshanlinux-01 ~]# sar ##sar不加具體的選項或參數,它就會去調用它的歷史文件
無法打開 /var/log/sa/sa10: 沒有那個文件或目錄 ##sar特性,每次正點10分鐘去抓取系統狀態保存在該目錄的文件里
[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)
##時間 ? ? ? ? 網卡名字 接收數據包 發送數據包 接收數據量 發送數據量
17時45分33秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時45分35秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時45分35秒 ? ? ens33 ? ? 0.50 ? ? 0.50 ? ? 0.03 ? ? 0.10 ? ? 0.00 ? ? 0.00 ? ? 0.00
?
17時45分35秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時45分37秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時45分37秒 ? ? ens33 ? ? 0.51 ? ? 0.51 ? ? 0.03 ? ? 0.20 ? ? 0.00 ? ? 0.00 ? ? 0.00
?
17時45分37秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時45分39秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時45分39秒 ? ? ens33 ? ? 0.51 ? ? 0.51 ? ? 0.03 ? ? 0.20 ? ? 0.00 ? ? 0.00 ? ? 0.00
?
平均時間: ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
平均時間: ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
平均時間: ? ? ens33 ? ? 0.50 ? ? 0.50 ? ? 0.03 ? ? 0.17 ? ? 0.00 ? ? 0.00 ? ? 0.00
注:接收數據包幾千算是正常,上萬或幾十萬的話就不正常,被攻擊了。可以通過抓包工具驗證是否被攻擊。
[root@zyshanlinux-01 ~]# sar
Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 2018年06月10日 _x86_64_ (1 CPU)
?
17時40分01秒 ? ? CPU ? ? %user ? ? %nice ? %system ? %iowait ? %steal ? ? %idle
17時50分01秒 ? ? all ? ? 0.03 ? ? 0.00 ? ? 0.11 ? ? 0.00 ? ? 0.00 ? ? 99.86
18時00分01秒 ? ? all ? ? 0.03 ? ? 0.00 ? ? 0.10 ? ? 0.00 ? ? 0.00 ? ? 99.86
18時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時40分01秒 ? ? IFACE ? rxpck/s ? txpck/s ? rxkB/s ? txkB/s ? rxcmp/s ? txcmp/s rxmcst/s
17時50分01秒 ? ? ? lo ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
17時50分01秒 ? ? ens33 ? ? 0.22 ? ? 0.04 ? ? 0.01 ? ? 0.01 ? ? 0.00 ? ? 0.00 ? ? 0.00
注:當天/var/log/sa/里面不僅有一個sa10的文件還有sar10的文件,但只有到明天這個文件才會出現,兩者有什么區別呢,sa10是二進制文件不能用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時17分11秒 ? runq-sz plist-sz ? ldavg-1 ? ldavg-5 ldavg-15 ? blocked
23時17分12秒 ? ? ? ? 0 ? ? ? 105 ? ? 0.02 ? ? 0.07 ? ? 0.05 ? ? ? ? 0
23時17分13秒 ? ? ? ? 0 ? ? ? 105 ? ? 0.02 ? ? 0.07 ? ? 0.05 ? ? ? ? 0
23時17分14秒 ? ? ? ? 0 ? ? ? 105 ? ? 0.02 ? ? 0.07 ? ? 0.05 ? ? ? ? 0
平均時間: ? ? ? ? 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時18分37秒 ? ? ? tps ? ? rtps ? ? wtps ? bread/s ? bwrtn/s
23時18分38秒 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
23時18分39秒 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
23時18分40秒 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
平均時間: ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00 ? ? 0.00
第一次用這個命令,會出現沒有命令的錯誤,需要安裝2個包才可以執行這個命令
[root@zyshanlinux-01 ~]# nload
?
Device ens33 [192.168.106.128] (1/2):
===========================================================================================================
Incoming: ##進來的流量,被攻擊的話,這個流量就會變得很大
?
?
?
?
?
?Curr: 944.00 Bit/sAvg: 1.05 kBit/sMin: 944.00 Bit/sMax: 1.87 kBit/sTtl: 7.73 MByte
Outgoing: ##出去的流量,買了100的帶寬跑到70多了還是正常,跑滿的就證明帶寬不夠了
?
?
?
?
?Curr: 8.29 kBit/sAvg: 8.30 kBit/sMin: 4.27 kBit/sMax: 8.78 kBit/sTtl: 3.33 MByte
?
監控IO性能
iostat和sar是同一個安裝包的,都是sysstat,安裝了這個包后,2個命令都可以用了。
[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重點參數,CPU等待IO硬盤時間的百分比,越大硬盤越差,硬盤太慢。這個參數和硬盤的讀寫參數是相關聯的,這個百分比大讀寫數據也大,如果讀寫幾乎為0,這個百分比仍然很大,硬盤異常
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 ##命令沒有,需要安裝下面的包才可以執行這個命令
-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運算速度快,磁盤很慢,所以需要內存進行緩沖,以下就是數據不同流向的區別
[root@zyshanlinux-01 ~]# 0000(磁盤)-->內存(cache)-->cpu ? ? ? ^C
[root@zyshanlinux-01 ~]# cpu(00000) -->內存(buffer)--> 磁盤 ? ? ^C
?
查看系統進程
把你當前進程的快照打印出來,ps是一次性靜態的把系統進程列出來,top則是實時動態的。
[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 ##查看該進程是否在運行
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號可以殺死該進程
[root@zyshanlinux-01 ~]# ps aux |grep qmgr ##確認該進程確實是被殺死
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加上數字的文件夾就是進程的PID號
總用量 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部分說明
D 不能中斷的進程
R run狀態的進程
S sleep狀態的進程
[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
數量較少,有就用命令殺死它。
< 高優先級進程
N 低優先級進程
L 內存中被鎖了內存分頁
s主進程
l 多線程進程
+ 前臺進程,都是在終端中顯示
[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
?
查看網絡狀態
netstat 查看網絡狀態
netstat -lnp 查看監聽端口
[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 異曲同工,不足是不會顯示進程的名字
[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 ? ? ? ? ? ? ? ? ? :::* ? ? ? ?
一個小技巧:直接查看以下數據的并發量。
[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 ##第一次運行這個命令要安裝這個包
用法:tcpdump -nn
tcpdump -nn -i ens33
[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 ##特殊的設備需要加上網卡名
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
##得出的結果都是數據包的流向,成對出現,還要關注一個重要參數length 180,長度參數。有種攻擊是DDos,即udp flood洪水攻擊,可以發出幾百G流量攻擊,只能用防攻擊的設備或服務。
[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個包寫入1.cap里面,單開一個終端時這條命令可能會卡住,因為沒有數據流動,所以沒產生包,命令就卡住,可以重新開個終端運行寫top或vmstat 1的命令產生些包,這條命令就會很快完成抓包任務。
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 ##因為是抓的數據包,包的內容,cat你是看不懂得
?
[root@zyshanlinux-01 ~]# tcpdump -r /tmp/1.cap ##可以用-r來看,就是讀數據流;但實際上1.cap中是真真正正得寫入數據包
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次運行該命令需要安裝
[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" ##需要線上的系統才能抓到,
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網絡相關
[root@zyshanlinux-01 ~]# ifconfig -a ##加-a選項,如果網卡宕機或者沒有ip的時候是不顯示的。
如果你的機房在國外,你單獨執行關閉網卡命令,你就要去國外重啟網卡;這時你就應該關閉和重啟服務一起執行。
[root@zyshanlinux-01 ~]# ifdown ens33 && ifup ens33
成功斷開設備 'ens33'。
連接已成功激活(D-Bus 活動路徑:/org/freedesktop/NetworkManager/ActiveConnection/4)
[root@zyshanlinux-01 ~]# ifdown ens33;ifup ens33
成功斷開設備 'ens33'。
連接已成功激活(D-Bus 活動路徑:/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
成功斷開設備 'ens33'。
連接已成功激活(D-Bus 活動路徑:/org/freedesktop/NetworkManager/ActiveConnection/8)
[root@zyshanlinux-01 network-scripts]# ifconfig ##多出新的虛擬網卡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正常連接網線
[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正常連接網線
[root@zyshanlinux-01 ~]# hostnamectl set-hostname zyshanlinux-001 ?
[root@zyshanlinux-01 ~]# hostname ##更改主機名需要退出再重新登錄,或者用hostname命令查看
zyshanlinux-001
[root@zyshanlinux-01 ~]# bash ##用子shell也可查看
[root@zyshanlinux-001 ~]# exit
exit
[root@zyshanlinux-01 ~]# cat /etc/hostname ##主機名的配置文件
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 ##網卡的配置文件
##增加谷歌的DNS2=8.8.8.8
[root@zyshanlinux-01 ~]# ifdown ens33;ifup ens33
成功斷開設備 'ens33'。
連接已成功激活(D-Bus 活動路徑:/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 ##可以臨時更改DNS,但重啟后會被網卡的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 ##公網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,多個域名指向一個IP空格隔開,多個IP指向一個域名只執行最后一個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 ##只執行最后一個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本機下才能生效
C:\Users\zhengyushan>ping www.qq123.com
?
正在 Ping www.qq123.com [211.155.235.108] 具有 32 字節的數據:
來自 211.155.235.108 的回復: 字節=32 時間=49ms TTL=226
來自 211.155.235.108 的回復: 字節=32 時間=57ms TTL=226
來自 211.155.235.108 的回復: 字節=32 時間=55ms TTL=226
來自 211.155.235.108 的回復: 字節=32 時間=54ms TTL=226
?
211.155.235.108 的 Ping 統計信息:數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):最短 = 49ms,最長 = 57ms,平均 = 53ms
?
C:\Users\zhengyushan>www.19.com
'www.19.com' 不是內部或外部命令,也不是可運行的程序
或批處理文件。
?
拓展閱讀:
tcp三次握手四次揮手(重點) http://www.doc88.com/p-9913773324388.html
tshark幾個用法 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的簡單講解https://www.cnblogs.com/xiohao/p/4439164.html
認識cpu、核、進程與線程——備忘篇https://blog.csdn.net/zhengyshan/article/details/80641770
總結
以上是生活随笔 為你收集整理的Linux日常运维管理技巧(一)监控系统状态、监控网卡流量、监控IO性能、查看系统进程、查看网络状态、Linux下抓包tcpdump、Linux网络相关、DNS配置 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。