LVM、网络协议和管理

LVM、网络协议和管理

1.创建逻辑卷

创建物理卷
pvcreate /dev/sd{b1,c}
创建卷组名
vgcreate vg0 /dev/sd{b1,c} -s 4G
创建逻辑卷
lvcreate -n mysql -L 8G vg0
创建文件系统
mkfs.xfs /dev/vg0/mysql
挂载
mount /dev/vg0/mysql /mnt/mysql/
扩展文件系统
lvextend -l +1534 /dev/vg0/mysql
同步XFS文件系统
xfs_growfs /mnt/mysql/
扩展逻辑卷VG0的大小
vgextend vg0 /dev/sdd
同步EXT系列的文件系统
resize2fs /dev/vg0/binlog
可以扩展的同时直接同步文件系统,一条命令完成。
[root@centos7 ~]#lvextend -r -l +500 /dev/vg0/mysql
缩减逻辑分区的大小,缩减只能缩减EXT系列的。先取消挂载。
[root@centos7 ~]#umount /mnt/biglog/
检查文件的完整性
e2fsck -f /dev/vg0/binlog
缩减文件系统大小到10G
resize2fs /dev/vg0/binlog 10G
缩减逻辑卷大小到10G,有风险,可能丢失数据
[root@centos7 ~]#lvreduce -L 10G /dev/vg0/binlog
然后在挂载上,就可以完成缩减
[root@centos7 ~]#mount /dev/vg0/binlog /mnt/biglog/

2.迁移逻辑卷,先取消挂载

先禁用,
[root@centos7 ~]#vgchange -an vg0
查看状态
[root@centos7 ~]#lvdisplay
导出状态
[root@centos7 ~]#vgexport vg0
就可以拔出硬盘了。插到新的机子上
然后导入
[root@centos7 ~]#vgimport vg0
启用,
[root@centos7 ~]#vgchange -ay vg0
然后挂载就可以使用了。

3.移出逻辑卷的硬盘

增加物理卷
[root@centos7 ~]#pvcreate /dev/sdb4
加到VG0里
[root@centos7 ~]#vgextend vg0 /dev/sdb4
把sdc上的迁移到其他地方
[root@centos7 ~]#pvmove /dev/sdc
把sdc移出VG0
[root@centos7 ~]#vgreduce vg0 /dev/sdc
把上面的物理卷标识去掉,现在就是一块普通硬盘了
[root@centos7 ~]#pvremove /dev/sdc

4.删除逻辑卷

[root@centos7 ~]#umount /mnt/mysql/
[root@centos7 ~]#lvremove /dev/vg0/mysql 
[root@centos7 ~]#vgremove vg0
[root@centos7 ~]#pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb1     lvm2 ---   4.00g  4.00g
  /dev/sdb3     lvm2 ---   2.00g  2.00g
  /dev/sdb4     lvm2 ---   5.00g  5.00g
  /dev/sdd      lvm2 ---  20.00g 20.00g
[root@centos7 ~]#pvremove /dev/sdd

5.创建逻辑卷快照和使用。xfs文件系统的。

-n 名字  -s 逻辑卷标志 -L 逻辑卷大小 -p r 只读属性 最后指定是谁的快照。只读不可以挂载,和原来的UUID一样。强行挂载要不是只读模式, -o nouuid 不检查UUID
[root@centos7 ~]#lvcreate -n mysql_snapshot -s -L 1G -p r /dev/vg0/mysql
[root@centos7 ~]#mount -o nouuid /dev/vg0/mysql_snapshot2 /mnt/snap/

还原快照。逻辑卷快照消失,只能使用一次。
[root@centos7 ~]#umount /mut/snap/
[root@centos7 ~]#umount /mnt/mysql
[root@centos7 ~]#lvconvert --merge /dev/vg0/mysql_sanpshot

ext系列不存在UUID重复的情况,快照也可以只读

6.创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

[root@centos7 ~]#pvcreate /dev/sd{c,d1}
[root@centos7 ~]#pvdisplay 
  "/dev/sdd1" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd1
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               NYoBim-Wdxw-Bhak-hOiN-1WpU-2oOJ-2uzmPT

  "/dev/sdc" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               dIJhEo-YoxY-PGwh-Y1NS-17w2-UWcB-D25ABX
  [root@centos7 ~]#vgcreate testvg /dev/sd{c,d1} -s 16MB
  Volume group "testvg" successfully created
[root@centos7 ~]#vgdisplay 
  --- Volume group ---
  VG Name               testvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <19.97 GiB
  PE Size               16.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / <19.97 GiB
  VG UUID               Gy8wH6-XidI-D69o-pMiy-i8OX-P03i-HtjH72
[root@centos7 ~]#lvcreate -n testlv -L 5G testvg 
WARNING: xfs signature detected on /dev/testvg/testlv at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/testvg/testlv.
  Logical volume "testlv" created.
[root@centos7 ~]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                wkn8n8-B2GI-Aqf4-gTWz-tg8E-4bF5-YkAF01
  LV Write Access        read/write
  LV Creation host, time centos7.5.localdomain, 2019-08-11 22:00:57 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@centos7 ~]#mkfs.ext4 /dev/testvg/testlv 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 
[root@centos7 ~]#mount /dev/testvg/testlv /users

7.新建用户archlinux,要求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录

[archlinux@centos7 ~]$cp -r /etc/pam.d/ ./
[archlinux@centos7 ~]$ll
total 4
drwxr-xr-x 2 archlinux archlinux 4096 Aug 11 22:09 pam.d
[archlinux@centos7 ~]$pwd
/users/archlinux

8.扩展testlv至7G,要求archlinux用户的文件不能丢失

[root@centos7 ~]#lvextend -r  -L +2G /dev/testvg/testlv 
  Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).
  Logical volume testvg/testlv successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/testvg-testlv is mounted on /users; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/testvg-testlv is now 1835008 blocks long.

[root@centos7 ~]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                wkn8n8-B2GI-Aqf4-gTWz-tg8E-4bF5-YkAF01
  LV Write Access        read/write
  LV Creation host, time centos7.5.localdomain, 2019-08-11 22:00:57 +0800
  LV Status              available
  # open                 1
  LV Size                7.00 GiB
  Current LE             448
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

9.收缩testlv至3G,要求archlinux用户的文件不能丢失

[root@centos7 ~]#umount /users
[root@centos7 ~]#resize2fs /dev/testvg/testlv 3G
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/testvg/testlv' first.

[root@centos7 ~]#e2fsck -f /dev/testvg/testlv
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 70/458752 files (0.0% non-contiguous), 67380/1835008 blocks
[root@centos7 ~]#resize2fs /dev/testvg/testlv 3G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 786432 blocks long.

[root@centos7 ~]#lvreduce -L 3G /dev/testvg/testlv 
  WARNING: Reducing active logical volume to 3.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/testlv? [y/n]: y
  Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).
  Logical volume testvg/testlv successfully resized.
[root@centos7 ~]#mount /dev/testvg/testlv /users

10.对testlv创建快照,并尝试基于快照备份数据,验证快照的功能

      -p r 设置只读模式,忘记添加了
[root@centos7 ~]#lvcreate -L 1G -s -n snap1 /dev/testvg/testlv
[root@centos7 ~]#umount /users
[root@centos7 ~]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                wkn8n8-B2GI-Aqf4-gTWz-tg8E-4bF5-YkAF01
  LV Write Access        read/write
  LV Creation host, time centos7.5.localdomain, 2019-08-11 22:00:57 +0800
  LV snapshot status     source of
                         snap1 [active]
  LV Status              available
  # open                 0
  LV Size                3.00 GiB
  Current LE             192
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/testvg/snap1
  LV Name                snap1
  VG Name                testvg
  LV UUID                KdGZPM-BqYW-GxDz-bOor-fmNE-Isdh-T7hsHo
  LV Write Access        read/write
  LV Creation host, time centos7.5.localdomain, 2019-08-11 22:23:36 +0800
  LV snapshot status     active destination for testlv
  LV Status              available
  # open                 0
  LV Size                3.00 GiB
  Current LE             192
  COW-table size         1.00 GiB
  COW-table LE           64
  Allocated to snapshot  0.01%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
[root@centos7 ~]#lvconvert --merge /dev/testvg/snap1 
  Merging of volume testvg/snap1 started.
  testvg/testlv: Merged: 100.00%

11.Ethernet II以太网帧格式:

目标MAC 源MAC 类型 数据 FCS
6字节 6字节 2字节 46-1500字节 4字节
所以最小6+6+2+46+4 = 64,最大6+6+2+1500+4 = 1518。
(注:ISL封装后可达1548字节,802.1Q封装后可达1522字节)

12.⽤正则表达式匹配邮件地址和⽹站?

egrep "[[:alnum:] ]+@[[:alnum:]]+\.com"
egrep "^([a-zA-Z0-9_-\.]([a-zA-Z0-9_-]{0,61}[a-zA-Z0-9_-])?\.)+[a-zA-Z]{1,6}$"

13.查看端口被那几个应用占用

[root@centos7 ~]#ss -ntlp |grep 22
LISTEN     0      5      192.168.122.1:53                       *:*                   users:(("dnsmasq",pid=7269,fd=6))
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=6780,fd=3))
LISTEN     0      128         :::22                      :::*                   users:(("sshd",pid=6780,fd=4))
[root@centos7 ~]#lsof -i :22
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd     6780 root    3u  IPv4  43799      0t0  TCP *:ssh (LISTEN)
sshd     6780 root    4u  IPv6  43801      0t0  TCP *:ssh (LISTEN)
sshd    11386 root    3u  IPv4  97622      0t0  TCP 192.168.38.103:ssh->192.168.38.1:61967 (ESTABLISHED)
sshd    15611 root    3u  IPv4 149223      0t0  TCP 192.168.38.103:ssh->192.168.38.1:64099 (ESTABLISHED)
sshd    16049 root    3u  IPv4 152899      0t0  TCP 192.168.38.103:ssh->192.168.38.1:64967 (ESTABLISHED)
sshd    16283 root    3u  IPv4 155757      0t0  TCP centos7.6.localdomain:ssh->172.18.1.77:65180 (ESTABLISHED)

14.用户改名

修改文件
[root@7 ~]#vim /etc/sysconfig/network
HOSTNAME=7.6centos.localdomain 
[root@7 ~]#hostname 7.6centos.localdomain
[root@7 ~]#exit
在这个地方添加新的名字,防止自己ping不通自己
[root@7 ~]#vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 7.6centos.localdomain
[root@7 ~]#ping 7.6centos.localdomain

15.配置eth1⽹卡地址为1.1.1.1/24

直接就改了
[root@centos7 ~]#ifconfig eth1 172.18.7.7/24 up
[root@centos7 ~]#ifconfig eth1 1.1.1.1 netmask 255.255.255.0

16.激活eth1⽹卡,关闭网卡

[root@centos7 ~]#ifconfig eth1 down
[root@centos7 ~]#ifconfig eth1 up

17.配置eth1的⽹卡别名为eth1:0,ip为10.0.0.100

[root@centos7 ~]#ifconfig eth1:0 10.0.0.100/24 up
[root@centos7 ~]#ifconfig eth1:0
eth1:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.100  netmask 255.255.255.0  broadcast 10.0.0.255
        ether 00:0c:29:a3:3e:ce  txqueuelen 1000  (Ethernet)
[root@centos7 ~]#ifconfig eth1:0 10.0.0.100/24 down

17.添加到1.1.1.1的主机路由,下⼀跳为172.18.0.1

[root@centos7 ~]#route add -host 1.1.1.1 gw 172.18.0.1
[root@centos7 ~]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.18.0.1      0.0.0.0         UG    100    0        0 eth0
0.0.0.0         172.18.0.1      0.0.0.0         UG    101    0        0 eth1
1.1.1.1         172.18.0.1      255.255.255.255 UGH   0      0        0 eth0
172.18.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eth0
172.18.0.0      0.0.0.0         255.255.0.0     U     101    0        0 eth1
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

18.删除主机路由1.1.1.1

[root@centos7 ~]#route del -host 1.1.1.1
[root@centos7 ~]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.18.0.1      0.0.0.0         UG    100    0        0 eth0
0.0.0.0         172.18.0.1      0.0.0.0         UG    101    0        0 eth1
172.18.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eth0
172.18.0.0      0.0.0.0         255.255.0.0     U     101    0        0 eth1
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

19.添加到1.1.1.0/24的⽹络路由,下⼀跳为172.18.0.1

[root@centos7 ~]#route add -net 1.1.1.0/24 gw 172.18.0.1 dev eth0
[root@centos7 ~]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.18.0.1      0.0.0.0         UG    100    0        0 eth0
0.0.0.0         172.18.0.1      0.0.0.0         UG    101    0        0 eth1
1.1.1.0         172.18.0.1      255.255.255.0   UG    0      0        0 eth0
172.18.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eth0
172.18.0.0      0.0.0.0         255.255.0.0     U     101    0        0 eth1
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

20.添加到1.1.1.0/24的⽹络路由,下⼀跳为172.18.0.1

[root@centos7 ~]#route add -net 1.1.1.0 netmask 255.255.255.0 gw 172.18.0.1 dev eth1

21.添加默认路由

[root@centos7 ~]#route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.18.0.1
[root@centos7 ~]#route add default gw 172.18.0.1

22.禁⽤ens38⽹卡

[root@centos7 ~]#ip link set dev eth1 down

23.查看eth1⽹卡的状态

[root@centos7 ~]#ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:a3:3e:ce brd ff:ff:ff:ff:ff:ff

24.启⽤eth1⽹卡

[root@centos7 ~]#ip link set dev eth1 up
[root@centos7 ~]#ip link show
[root@centos7 ~]#ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:a3:3e:ce brd ff:ff:ff:ff:ff:ff

25.删除网卡地址和添加网卡地址

[root@centos7 ~]#ip addr del 172.18.7.7 dev eth1
Warning: Executing wildcard deletion to stay compatible with old scripts.
         Explicitly specify the prefix length (172.18.7.7/32) to avoid this warning.
         This special behaviour is likely to disappear in further releases,
         fix your scripts!
[root@centos7 ~]#ip addr add 172.18.7.7/24 dev eth1 

26.配置eth1⽹卡别名为ens38:0,地址为4.4.4.4/24和删除

[root@centos7 ~]#ip addr add 4.4.4.4 dev eth1 label eth1:0
eth1:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 4.4.4.4  netmask 255.255.255.255  broadcast 0.0.0.0
        ether 00:0c:29:a3:3e:ce  txqueuelen 1000  (Ethernet)
[root@centos7 data]#ifconfig eth1:1 1.1.1.1/24
[root@centos7 ~]#ip add flush dev eth1 label eth1:0

27.删除eth1⽹卡上的使⽤ip地址和增加

[root@centos7 ~]#ip addr flush dev eth1
[root@centos7 ~]#ip addr add  172.18.7.7 dev eth1

28.查看路由表

[root@centos7 data]#ip route show
default via 172.18.0.1 dev eth0 
default via 172.18.0.1 dev eth0 proto static metric 100 
1.1.1.0/24 via 172.18.0.1 dev eth0 
172.18.0.0/16 dev eth0 proto kernel scope link src 172.18.7.127 metric 100 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 
[root@centos7 data]#ip route list
default via 172.18.0.1 dev eth0 
default via 172.18.0.1 dev eth0 proto static metric 100 
1.1.1.0/24 via 172.18.0.1 dev eth0 
172.18.0.0/16 dev eth0 proto kernel scope link src 172.18.7.127 metric 100 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1

29.添加⽹络路由192.168.0.0/24

[root@centos7 data]#ip route add 192.168.0.0/24 via 172.18.0.1

30.添加默认⽹关和删除

[root@centos7 data]#ip route add default via 172.18.0.1
[root@centos7 data]#route add default gw 172.18.0.1
指定端口
ip route add default via 172.18.0.1 dev eth0
[root@centos7 data]#ip route del default via 172.18.0.1
[root@centos7 data]#route del default gw 172.18.0.1 dev eth0

31.配置dns⽂件,地址为172.18.0.1,重启永久⽣效

[root@centos7 data]#vim /etc/resolv.conf 

32.查看tcp协议,⽤数⼦显⽰ip和端⼝,所有状态⽹络连接

[root@centos7 data]#netstat -tan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:6000            0.0.0.0:*               LISTEN     
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:37698           0.0.0.0:*               LISTEN     
tcp        0      0 172.18.7.7:22           172.18.1.77:56968       ESTABLISHED
tcp        0     52 172.18.7.127:22         172.18.1.77:51868       ESTABLISHED
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::6000                 :::*                    LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::46709                :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     

33.查看udp协议,⽤数⼦显⽰ip和端⼝,所有状态⽹络连接

[root@centos7 data]#netstat -uan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 0.0.0.0:967             0.0.0.0:*                          
udp        0      0 127.0.0.1:1005          0.0.0.0:*                          
udp        0      0 192.168.122.1:53        0.0.0.0:*                          
udp        0      0 0.0.0.0:67              0.0.0.0:*                          
udp        0      0 0.0.0.0:111             0.0.0.0:*                          
udp        0      0 0.0.0.0:5353            0.0.0.0:*                          
udp        0      0 0.0.0.0:50817           0.0.0.0:*                          
udp        0      0 0.0.0.0:52965           0.0.0.0:*                          
udp6       0      0 :::967                  :::*                               
udp6       0      0 :::111                  :::*                               
udp6       0      0 :::54851                :::* 

34.查看tcp协议,⽤数⼦显⽰ip和端⼝,所有处于监听状态⽹络连接

[root@centos7 data]#netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:6000            0.0.0.0:*               LISTEN     
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:37698           0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::6000                 :::*                    LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::46709                :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     

35.查看udp协议,⽤数⼦显⽰ip和端⼝,所有处于监听状态⽹络连接

[root@centos7 data]#netstat -unl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 0.0.0.0:967             0.0.0.0:*                          
udp        0      0 127.0.0.1:1005          0.0.0.0:*                          
udp        0      0 192.168.122.1:53        0.0.0.0:*                          
udp        0      0 0.0.0.0:67              0.0.0.0:*                          
udp        0      0 0.0.0.0:111             0.0.0.0:*                          
udp        0      0 0.0.0.0:5353            0.0.0.0:*                          
udp        0      0 0.0.0.0:50817           0.0.0.0:*                          
udp        0      0 0.0.0.0:52965           0.0.0.0:*                          
udp6       0      0 :::967                  :::*                               
udp6       0      0 :::111                  :::*                               
udp6       0      0 :::54851                :::*  

36.显⽰所有接⼝统计数据

[root@centos7 data]#netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1500    78298      0      0 0          6449      0      0      0 BMRU
eth1             1500    44702      0      0 0           314      0      0      0 BMRU
lo              65536      210      0      0 0           210      0      0      0 LRU
virbr0           1500        0      0      0 0             0      0      0      0 BMU

37.显⽰eth0接⼝是流量数据

[root@centos7 data]#netstat -I=eth0
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1500    78518      0      0 0          6478      0      0      0 BMRU
[root@centos7 data]#ifconfig -s eth0
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1500    78621      0      0 0          6502      0      0      0 BMRU

38.centos6重启⽹络服务和关闭NetworkManager服务

service network restart
service NetworkManager stop

39.查看具体路由信息

[root@centos7 data]#traceroute www.baidu.com
traceroute to www.baidu.com (61.135.169.121), 30 hops max, 60 byte packets
 1  gateway (172.18.0.1)  1.235 ms  1.118 ms  1.030 ms
 2  192.168.0.1 (192.168.0.1)  0.918 ms  0.813 ms  0.728 ms
 3  123.118.208.1 (123.118.208.1)  5.181 ms  5.068 ms  4.984 ms
 4  114.244.95.105 (114.244.95.105)  4.177 ms 61.148.163.181 (61.148.163.181)  7.078 ms 61.148.163.81 (61.148.163.81)  4.690 ms
 5  61.148.157.229 (61.148.157.229)  5.187 ms  3.714 ms  4.964 ms
[root@centos7 data]#tracepath 114.114.114.114
 1?: [LOCALHOST]                                         pmtu 1500
 1:  gateway                                               3.093ms 
 1:  gateway                                               1.891ms 
 2:  192.168.0.1                                           2.132ms 
 3:  192.168.0.1                                           2.609ms pmtu 1480
 3:  123.118.208.1                                        18.058ms 
 4:  114.244.95.61                                         3.921ms 
 5:  no reply
 6:  125.33.186.5                                         16.844ms 
 7:  219.158.4.230                                        13.296ms 
^C
[root@centos7 data]#mtr www.baidu.com

40.子网掩码不同,网络IP可能是会不一样的

A:192.168.38.100/25
B:192.168.38.200/24

A--->B
192.168.38.100与255.255.255.128=192.168.38.0
192.168.38.200与255.255.255.128=192.168.38.128
不相同
B--->A
192.168.38.100与255.255.255.0=192.168.38.0
192.168.38.200与255.255.255.0=192.168.38.0

41.高于DNS的名字解析,测试时用。改名字时最好后面也加一个。

[root@centos7 data]#vim /etc/hosts

42.抓包。-nn转化为数字形式

[root@centos7 network-scripts]#tcpdump -i eth0 -nn icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
16:33:22.816999 IP 172.25.0.111 > 192.168.66.111: ICMP echo request, id 6893, seq 55, length 64
16:33:22.817030 IP 192.168.66.111 > 172.25.0.111: ICMP echo reply, id 6893, seq 55, length 64

43.查看最新日志。

[root@centos7 data]#tail /var/log/messages
Aug 17 16:34:32 centos7 avahi-daemon[6307]: Invalid legacy unicast query packet.
Aug 17 16:34:32 centos7 avahi-daemon[6307]: Received response from host 172.18.144.184 with invalid source port 50556 on interface 'eth0.0'
Aug 17 16:34:32 centos7 avahi-daemon[6307]: Invalid legacy unicast query packet.
Aug 17 16:34:32 centos7 avahi-daemon[6307]: Received response from host 172.18.144.184 with invalid source port 50556 on interface 'eth0.0'
Aug 17 16:34:32 centos7 avahi-daemon[6307]: Invalid legacy unicast query packet.
Aug 17 16:34:32 centos7 avahi-daemon[6307]: Received response from host 172.18.144.184 with invalid source port 50556 on interface 'eth0.0'
Aug 17 16:34:33 centos7 avahi-daemon[6307]: Received response from host 172.18.144.184 with invalid source port 50556 on interface 'eth0.0'
Aug 17 16:34:34 centos7 avahi-daemon[6307]: Received response from host 172.18.144.184 with invalid source port 50556 on interface 'eth0.0'
Aug 17 16:34:34 centos7 avahi-daemon[6307]: Received response from host 172.18.144.184 with invalid source port 50556 on interface 'eth0.0'
Aug 17 16:34:36 centos7 avahi-daemon[6307]: Received response from host 172.18.144.184 with invalid source port 50556 on interface 'eth0.0'

44.ping -l 指定从哪个网卡访问。

[root@centos7 data]#ping -l 172.18.7.7 114.114.114.114
PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data.
64 bytes from 114.114.114.114: icmp_seq=1 ttl=86 time=12.6 ms
64 bytes from 114.114.114.114: icmp_seq=2 ttl=89 time=12.5 ms

45.-0.3秒查看一次网卡吞吐量 。-i必须和后面的连在一起,指定网卡

[root@centos7 data]#watch -n0.3 netstart -leth0

46.centos6上支持补全的包。。。。。退出重进生效

yum install bash-completion

46.显示IP和mcp地址对应的关系

[root@centos7 data]#arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
172.18.0.1               ether   14:6b:9c:bd:6b:cd   C                     eth0
172.18.1.77              ether   98:e7:f4:68:64:aa   C                     eth0
[root@centos7 data]#ip neigh 
172.18.0.1 dev eth0 lladdr 14:6b:9c:bd:6b:cd STALE
172.18.1.77 dev eth0 lladdr 98:e7:f4:68:64:aa REACHABLE

猜你喜欢

转载自blog.51cto.com/14451122/2430441