平常運維

監控系統狀態

  • w命令/uptime

load average: 0.00, 0.01, 0.05html

上面這條顯示的就是系統負載。後面有三段數字linux

[root@localhost ~]# w
 21:33:04 up 41 min,  1 user,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.245.1    20:53    0.00s  0.10s  0.02s w
[root@localhost ~]#

第一個數值表示一分鐘內系統的平均負載值,第二個數值表示5分鐘內系統的平均負載值,第三個數值表示15分鐘內系統的平均值。ios

主要着重看第一個值,值越大說明服務器的壓力越大。通常狀況下這個值只要不超過服務器的cpu數量就沒有關係。nginx

查看系統有幾個cpu : cat /proc/cpuinfoshell

看processor的值是多少,0就表示有1個邏輯cpu。10就表示有11個邏輯cpuapi

[root@localhost ~]# cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 61
model name	: Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
stepping	: 4
microcode	: 0x22
cpu MHz		: 2294.250
cache size	: 3072 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 20
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 tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ida arat epb pln pts dtherm fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt
bogomips	: 4589.38
clflush size	: 64
cache_alignment	: 64
address sizes	: 42 bits physical, 48 bits virtual
power management:

[root@localhost ~]#

vmstat

當咱們發現系統的負載偏高的時候,能夠用vmstat來查看都有哪些緣由致使配置不夠用了。緩存

[root@localhost ~]# vmstat
                  內存                虛擬內存   磁盤     系統進程
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 715284    892 169560    0    0    30     3   35   63  0  0 99  0  0
[root@localhost ~]#

通常用vmstat 1 來查看系統負載。這條命令的意思是每一秒鐘進行動態顯示bash

[root@localhost ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 715440    892 169592    0    0    29     3   35   62  0  0 100  0  0
 0  0      0 715424    892 169592    0    0     0     0   45   60  0  1 99  0  0
 0  0      0 715424    892 169592    0    0     0     0   24   34  0  0 100  0  0
 0  0      0 715424    892 169592    0    0     0     0   33   41  1  0 99  0  0
 0  0      0 715424    892 169592    0    0     0     0   38   42  0  1 99  0  0
 0  0      0 715424    892 169592    0    0     0     0   36   49  0  0 100  0  0
^C
[root@localhost ~]#

後面再加上一個數字就是指定顯示幾行後結束服務器

[root@localhost ~]# vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 715440    892 169592    0    0    26     3   34   60  0  0 100  0  0
 0  0      0 715424    892 169592    0    0     0     0   28   42  0  0 100  0  0
 0  0      0 715424    892 169592    0    0     0     0   28   34  0  0 100  0  0
[root@localhost ~]#

其中r(run)的意思:表示運行或者等待的時間的進程數。由於某一個時刻只有一個進程在用一個cpu,若是有十個進程,就會一個進程在某一個時間運行,到時間了,就運行下一個進程。進行輪流運行,其餘進程在排隊。網絡

b:(block) : 等待資源的進程數。好比進程在進行完成以後要寫入磁盤,這時候若是硬盤的負載很高,讀寫速度慢,或者網速太慢了。致使進程出現等待的狀況。

swpd :表示切換到交換分區中的內存數量,單位爲KB。

free : 表示當前空閒的內存數量,單位爲KB。

buff : 表示(即將寫入磁盤的)緩衝大小,單位爲KB。

cache : 表示(從硬盤中讀取的)緩存大小,單位爲KB。

si : 表示由交換區寫入內存的數據量,單位爲KB.

so : 表示由內存寫入交換分區的數據量,單位爲KB.

bi : 表示從塊設備讀取數據的量(讀磁盤),單位爲KB.

bo :寫磁盤 ,單位爲KB。

in : 表示某一時間間隔內觀測到的每秒設備的中斷次數。

cs : 表示每秒產生的上下文切換次數。

us : 顯示用戶下所花費CPU的資源的百分比。

sy :顯示系統花費CPU的資源的百分比。

id : 表示cpu處於空閒狀態的資源百分比。

wa : 表示I/O等待所佔用CPU的時間百分比。

st : 表示被偷走的cpu所佔百分比,(好比虛擬機會偷走物理機的cpu)通常都是0,不用關注。

top 查看進程使用資源狀況

top - 22:47:23 up  1:55,  1 user,  load average: 0.00, 0.01, 0.05
Tasks:  94 total,   1 running,  93 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.3 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   999936 total,   714648 free,   114544 used,   170744 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.   707696 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                        
   543 root      20   0  302636   6168   4788 S  0.3  0.6   0:15.07 vmtoolsd                                                                       
  2108 root      20   0  143096   5152   3876 S  0.3  0.5   0:00.77 sshd                                                                           
     1 root      20   0  128092   6704   3952 S  0.0  0.7   0:01.91 systemd                                                                        
     2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd                                                                       
     3 root      20   0       0      0      0 S  0.0  0.0   0:00.27 ksoftirqd/0                                                                    
     6 root      20   0       0      0      0 S  0.0  0.0   0:00.34 kworker/u256:0                                                                 
     7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0                                                                    
     8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh                                                                         
     9 root      20   0       0      0      0 S  0.0  0.0   0:00.56 rcu_sched                                                                      
    10 root      rt   0       0      0      0 S  0.0  0.0   0:00.09 watchdog/0                                                                     
    12 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 khelper                                                                        
    13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs                                                                      
    14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns                                                                          
    15 root      20   0       0      0      0 S  0.0  0.0   0:00.00 khungtaskd                                                                     
    16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback                                                                      
    17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd                                                                    
    18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset                                                                         
    19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd                                                                        
    20 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 md                                                                             
    26 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kswapd0                                                                        
    27 root      25   5       0      0      0 S  0.0  0.0   0:00.00 ksmd                                                                           
    28 root      39  19       0      0      0 S  0.0  0.0   0:00.06 khugepaged                                                                     
    29 root      20   0       0      0      0 S  0.0  0.0   0:00.00 fsnotify_mark                                                                  
    30 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 crypto                                                                         
    38 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kthrotld                                                                       
    39 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kworker/u256:1                                                                 
    40 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kmpath_rdacd                                                                   
    41 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kpsmoused                                                                      
    43 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 ipv6_addrconf

默認按照cpu百分比進行排列

數字單位是k字節。

按大寫字母M是之內存排序

按大寫P,是以cpu排序

按數字1,能夠列出全部核cpu的使用狀況。

按q退出。

top -bn1 :表示非動態打印系統資源的使用狀況,能夠用在shell腳本中。

sar命令

幾乎能夠監控系統的全部資源狀態。俗稱linux系統的瑞士軍刀。

首先須要安裝這個命令。

[root@localhost ~]# sar
-bash: sar: 未找到命令
[root@localhost ~]# yum install -y sysstat

sar -n DEV 1 3 每一秒顯示三次

[root@localhost ~]# sar -n DEV  1 3
Linux 3.10.0-514.el7.x86_64 (localhost.localdomain) 	2017年09月11日 	_x86_64_	(1 CPU)

23時15分34秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
23時15分35秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
23時15分35秒     ens33      1.01      1.01      0.06      0.20      0.00      0.00      0.00

23時15分35秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
23時15分36秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
23時15分36秒     ens33      1.00      1.00      0.06      0.40      0.00      0.00      0.00

23時15分36秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
23時15分37秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
23時15分37秒     ens33      0.99      0.99      0.06      0.40      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      1.00      1.00      0.06      0.33      0.00      0.00      0.00
[root@localhost ~]#

rxpck/s 表示每秒進入收取包的數量。txpck/s 表示每秒發送出去包的量。rxkb/s 表示每秒收取的量單位爲kb,txkb/s表示每秒發送的數據量。

數據包幾千是正常的,若是數據包上萬或者幾十萬,就頗有可能被攻擊了。能夠進行抓包查看。

sar -q 查看歷史負載

sar -n DEV -f /var/log/sa/sa17 查看某一天的網卡流量歷史,sa17每10分鐘生成一次,二進制文件,不能直接cat

sar -n DEV -f /var/log/sa/sar17 sar17是天天生成一次,能夠直接cat查看

sar -b 查看磁盤。

nload命令

首先須要安裝yum install epel-release

而後安裝yum install -y nload

很是直觀的查看網卡,按方向鍵切換網卡,按q退出

Device ens33 [192.168.245.128] (1/2):
====================================================================================================================================================
Incoming:











                                                                                                    Curr: 944.00 Bit/s
                                                                                                    Avg: 1.26 kBit/s
                                                                                                    Min: 944.00 Bit/s
                                                                                                    Max: 2.76 kBit/s
                                                                                                    Ttl: 6.86 MByte
Outgoing:











                                                                                                    Curr: 9.05 kBit/s
                                                                                                    Avg: 8.91 kBit/s
                                                                                                    Min: 4.23 kBit/s
                                                                                                    Max: 9.49 kBit/s
                                                                                                    Ttl: 3.48 MByte

監控io性能

[root@localhost ~]# iostat
Linux 3.10.0-514.el7.x86_64 (localhost.localdomain) 	2017年09月12日 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.11    0.00    0.23    0.01    0.00   99.66

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               1.61        19.24         1.76     124103      11353
sdb               0.07         0.53         0.00       3407          4
scd0              0.00         0.01         0.00         44          0
dm-0              0.01         0.07         0.00        456          0

[root@localhost ~]#
  • iostat -x

[root@localhost ~]# iostat -x
Linux 3.10.0-514.el7.x86_64 (localhost.localdomain) 	2017年09月12日 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.10    0.00    0.23    0.01    0.00   99.66

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.02    1.11    0.42    18.29     1.68    26.04     0.00    0.37    0.34    0.44   0.27   0.04
sdb               0.00     0.00    0.07    0.00     0.50     0.00    14.30     0.00    0.09    0.09    1.00   0.08   0.00
scd0              0.00     0.00    0.00    0.00     0.01     0.00     8.00     0.00    0.45    0.45    0.00   0.45   0.00
dm-0              0.00     0.00    0.01    0.00     0.07     0.00    15.20     0.00    0.08    0.08    0.00   0.07   0.00

[root@localhost ~]#

着重看%util列,若是數值很大,說明讀寫很忙。若是讀寫不大,說明硬盤有問題。

  • iotop 來查看佔用IO高的進程

沒有安裝過:yum install -y 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/s
   TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                                                                             
  2434 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.03 % [kworker/0:2]
     1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % systemd --switched-root --system --deserialize 21
     2 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]
     6 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u256:0]
     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/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [khelper]
    13 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kdevtmpfs]
    14 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [netns]
    15 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [khungtaskd]
    16 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [writeback]
    17 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kintegrityd]
    18 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [bioset]
    19 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kblockd]
    20 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [md]
   533 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % vmtoolsd
   534 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % systemd-logind
    26 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kswapd0]
    27 be/5 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksmd]
    28 be/7 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [khugepaged]
    29 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [fsnotify_mark]
    30 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [crypto]
   545 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % agetty --noclear tty1 linux
   548 be/4 polkitd     0.00 B/s    0.00 B/s  0.00 %  0.00 % polkitd --no-debug [gmain]
    38 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthrotld]
    39 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u256:1]
    40 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kmpath_rdacd]
    41 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kpsmoused]

free命令

直接查看內存使用的命令

[root@localhost ~]# free
              total        used        free      shared  buff/cache   available
Mem:         999936      121540      581256        6844      297140      693540
Swap:       2097148           0     2097148
[root@localhost ~]#
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           976M        118M        567M        6.7M        290M        677M
Swap:          2.0G          0B        2.0G
[root@localhost ~]#

buff/cache緩衝/緩存,緩存,是cpu向硬盤讀取數據的時候,緩存(cache)在內存裏。緩衝是:cpu處理完的數據寫入磁盤,緩衝(buff)在內存裏面。

公式:total=used + free + buff/cache

avaliable包含free和buffer/cache剩餘部分。

ps命令

  • ps aux

靜態顯示全部的進程

  • ps aux |grep nginx

查看某一個進程

[root@localhost ~]# ps aux |grep nginx
root       2757  0.0  0.0 112664   968 pts/0    R+   20:57   0:00 grep --color=auto nginx
[root@localhost ~]#

PID :進程ID,用於殺掉一個進程,kill 2757

查看一個進程:ls -l /proc/505/

  • ps aux 後關注STAT列

D不能中斷的進程

R run狀態的進程

S sleep狀態的進程

T 暫停的進程

Z 殭屍進程

< 高優先級進程

N 低優先級進程

L 內存中被鎖了內存分頁

s 主進程

l 多線程進程

+ 前臺進程

  • ps -elf

和ps aux 差很少。

netstat 查看網絡狀態

  • netstat -lnp 查看監聽端口

[root@localhost ~]# 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      887/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1494/master         
tcp6       0      0 :::22                   :::*                    LISTEN      887/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1494/master         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           542/chronyd         
udp6       0      0 ::1:323                 :::*                                542/chronyd         
raw6       0      0 :::58                   :::*                    7           581/NetworkManager  
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ACC ]     STREAM     LISTENING     12552    1/systemd            /run/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     12561    1/systemd            /run/lvm/lvmpolld.socket
unix  2      [ ACC ]     STREAM     LISTENING     19948    1494/master          private/bounce
unix  2      [ ACC ]     STREAM     LISTENING     19951    1494/master          private/defer
  • netstat -an

  • netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'

[root@localhost ~]# netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'
LISTEN 	 4
ESTABLISHED 	 1

主要看ESTABLISHED,這個數字大,說明系統忙。網站併發鏈接數,就是同一時刻有多少個客戶端連着。

linux 下抓包

  • 抓包工具tcpdump

沒有這個命令須要安裝一下:yum install -y tcpdump

指定網卡名字 tcpdump -nn -i ens33

運行完上面命令後會出現密密麻麻的一堆字符串,在按Ctrl+c 以前,這些字符串一直在刷屏,刷屏越快說明網卡上的數據包越多。咱們只須要關注第3列和第4列,它們顯示的信息爲哪個ip+端口號在鏈接哪個ip+端口號。

-nn選項的做用是讓第3列和第4列顯示成"ip+端口號"的形式,若是不加-nn選項則顯示「主機名+服務名稱」 -i 選項後面跟設備名稱。

tcpdump -nn -i ens33 port 22 指定只抓22端口的包

tcpdump -nn -i ens33 tcp and not port 22 指定抓tcp的包,可是不要22端口的

tcpdump -nn -i ens33 port 22 and port 53 只抓22和53 端口的包。

tcpdump -nn -i ens33 -c 100 只抓100條

tcpdump -nn -i ens33 -c 100 -w /tmp/1.cap 抓100條而後保存到/tmp/1.cap

tcpdump -r /tmp/1.cap 查看這個抓取的數據包。

  • 抓包工具 wireshark

yum install -y wireshark

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"

  • ifconfig 查看網卡及ip,子網,網關,mac地址

yum install net-tools

  • 重啓指定網卡 ifdown 網卡名字 && ifup 網卡名字

  • 添加虛擬網卡

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens33  ifdown-ib    ifdown-ppp       ifdown-tunnel  ifup-ib    ifup-plusb   ifup-Team         network-functions
ifcfg-lo     ifdown-ippp  ifdown-routes    ifup           ifup-ippp  ifup-post    ifup-TeamPort     network-functions-ipv6
ifdown       ifdown-ipv6  ifdown-sit       ifup-aliases   ifup-ipv6  ifup-ppp     ifup-tunnel
ifdown-bnep  ifdown-isdn  ifdown-Team      ifup-bnep      ifup-isdn  ifup-routes  ifup-wireless
ifdown-eth   ifdown-post  ifdown-TeamPort  ifup-eth       ifup-plip  ifup-sit     init.ipv6-global
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:0
[root@localhost network-scripts]# vi !$
vi ifcfg-ens33\:0
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=c6ff01b6-78d5-462c-b288-7acfafa4f5b5
DEVICE=ens33:
ONBOOT=yes
IPADDR=192.168.245.130
NETMASK=255.255.255.0
~
[root@localhost network-scripts]# ifdown ens33 && ifup ens33
成功斷開設備 'ens33'。
成功激活的鏈接(D-Bus 激活路徑:/org/freedesktop/NetworkManager/ActiveConnection/1)
[root@localhost network-scripts]#
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.245.128  netmask 255.255.255.0  broadcast 192.168.245.255
        inet6 fe80::dbd:48aa:6994:bf39  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d6:6f:fa  txqueuelen 1000  (Ethernet)
        RX packets 4396  bytes 330121 (322.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1291  bytes 122535 (119.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.245.130  netmask 255.255.255.0  broadcast 192.168.245.255
        ether 00:0c:29:d6:6f:fa  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 80  bytes 6940 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 80  bytes 6940 (6.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

虛擬網卡能ping通

  • 查看一個網卡的網線是否鏈接 mii-tool ens33

[root@localhost network-scripts]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok
[root@localhost network-scripts]#

link ok 表明鏈接,no link 表明未鏈接

或者使用ethtool ens33也能查看。

  • 更改計算機名

[root@localhost network-scripts]# hostnamectl set-hostname aminglinux-01
[root@localhost network-scripts]# hostname
aminglinux-01
[root@localhost network-scripts]# bash
[root@aminglinux-01 network-scripts]#
  • 查看DNS

[root@aminglinux-01 network-scripts]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 119.29.29.29
[root@aminglinux-01 network-scripts]#

擴展學習

tcp三次握手四次揮手(重點) http://www.doc88.com/p-9913773324388.html tshark幾個用法:http://www.aminglinux.com/bbs/thread-995-1-1.html

相關文章
相關標籤/搜索