1、简述osi七层模型和TCP/IP五层模型

osi七层模型分别是:应用层,表示层,会话层,传输层,网络层,数据链路层,物理层。

TCP/IP五层模型分别是:应用层,传输层,网络层,数据链路层,物理层
2、简述iproute家族命令

iproute家族命令:

  ip命令

ip [ OPTIONS ] OBJECT { COMMAND | help }
常用OBJECT:link,addr,route,netns
[root@node1 ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:13:ed:66 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:c3:d2:19 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:c3:d2:19 brd ff:ff:ff:ff:ff:ff
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 02:42:02:e2:a5:f6 brd ff:ff:ff:ff:ff:ff
6: cali40cf456027c@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether f2:f7:06:94:ac:85 brd ff:ff:ff:ff:ff:ff link-netnsid 0
7: cali8fa7d9c3670@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether 5a:8f:a7:bd:81:f9 brd ff:ff:ff:ff:ff:ff link-netnsid 1
8: calid8e3b96d922@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether f6:97:a7:a3:67:ca brd ff:ff:ff:ff:ff:ff link-netnsid 2
9: cali3d4a731ea47@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether de:68:44:6e:1e:ca brd ff:ff:ff:ff:ff:ff link-netnsid 3
10: cali97016535223@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether 6e:e9:65:75:67:ee brd ff:ff:ff:ff:ff:ff link-netnsid 4
11: calice66c2a01be@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether 7a:7c:68:91:07:70 brd ff:ff:ff:ff:ff:ff link-netnsid 5
12: cali37f2e720c07@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether 26:64:9b:da:9b:5e brd ff:ff:ff:ff:ff:ff link-netnsid 6
13: tunl0@NONE: <NOARP,UP,LOWER_UP> mtu 1440 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/ipip 0.0.0.0 brd 0.0.0.0
[root@node1 ~]# ip link set virbr0 down
[root@node1 ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:13:ed:66 brd ff:ff:ff:ff:ff:ff
3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:c3:d2:19 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:c3:d2:19 brd ff:ff:ff:ff:ff:ff
[root@node1 ~]# ip link set docker0 name dockerx
RTNETLINK answers: Device or resource busy
[root@node1 ~]# ip link set docker0 down
[root@node1 ~]# ip link set docker0 name dockerx
[root@node1 ~]# ip link show dev docker0
Device "docker0" does not exist.
[root@node1 ~]# ip link show dev dockerx
5: dockerx: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 02:42:02:e2:a5:f6 brd ff:ff:ff:ff:ff:ff
[root@node1 ~]# ip link show dev docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 02:42:02:e2:a5:f6 brd ff:ff:ff:ff:ff:ff
[root@node1 ~]# ip link set docker0 promisc on
[root@node1 ~]# ip link show dev docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,PROMISC,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 02:42:02:e2:a5:f6 brd ff:ff:ff:ff:ff:ff
ip addr {add|del} ADDRESS/NETMASK dev DEVICE

[root@node1 ~]# ip addr show docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,PROMISC,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:02:e2:a5:f6 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
[root@node1 ~]# ip addr add 133.133.0.1/16 dev docker0
[root@node1 ~]# ip addr show docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:d0:22:d4:d6 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
inet 133.133.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
[root@node1 ~]# ip addr del 133.133.0.1/16 dev docker0
[root@node1 ~]# ip addr show docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:d0:22:d4:d6 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
[root@node1 ~]# ip addr flush dev docker0
[root@node1 ~]# ip addr show docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:d0:22:d4:d6 brd ff:ff:ff:ff:ff:ff
[root@node1 ~]# ip route show
default via 192.168.198.2 dev ens33
blackhole 10.233.102.128/26 proto bird
10.233.102.163 dev cali97016535223 scope link
10.233.102.164 dev calid8e3b96d922 scope link
10.233.102.165 dev cali37f2e720c07 scope link
10.233.102.166 dev cali40cf456027c scope link
10.233.102.167 dev calice66c2a01be scope link
10.233.102.168 dev cali3d4a731ea47 scope link
10.233.102.169 dev cali8fa7d9c3670 scope link
169.254.0.0/16 dev ens33 scope link metric 1002
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
192.168.198.0/24 dev ens33 proto kernel scope link src 192.168.198.145
[root@node1 ~]# ip route list
default via 192.168.198.2 dev ens33
blackhole 10.233.102.128/26 proto bird
10.233.102.163 dev cali97016535223 scope link
10.233.102.164 dev calid8e3b96d922 scope link
10.233.102.165 dev cali37f2e720c07 scope link
10.233.102.166 dev cali40cf456027c scope link
10.233.102.167 dev calice66c2a01be scope link
10.233.102.168 dev cali3d4a731ea47 scope link
10.233.102.169 dev cali8fa7d9c3670 scope link
169.254.0.0/16 dev ens33 scope link metric 1002
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
192.168.198.0/24 dev ens33 proto kernel scope link src 192.168.198.145
[root@node1 ~]# ip route add 133.133.0.1 via 192.168.198.2 dev ens33
[root@node1 ~]# ip route list
default via 192.168.198.2 dev ens33
blackhole 10.233.102.128/26 proto bird
10.233.102.163 dev cali97016535223 scope link
10.233.102.164 dev calid8e3b96d922 scope link
10.233.102.165 dev cali37f2e720c07 scope link
10.233.102.166 dev cali40cf456027c scope link
10.233.102.167 dev calice66c2a01be scope link
10.233.102.168 dev cali3d4a731ea47 scope link
10.233.102.169 dev cali8fa7d9c3670 scope link
133.133.0.1 via 192.168.198.2 dev ens33
169.254.0.0/16 dev ens33 scope link metric 1002
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
192.168.198.0/24 dev ens33 proto kernel scope link src 192.168.198.145
[root@node1 ~]# ip route del 133.133.0.1
[root@node1 ~]# ip route list
default via 192.168.198.2 dev ens33
blackhole 10.233.102.128/26 proto bird
10.233.102.163 dev cali97016535223 scope link
10.233.102.164 dev calid8e3b96d922 scope link
10.233.102.165 dev cali37f2e720c07 scope link
10.233.102.166 dev cali40cf456027c scope link
10.233.102.167 dev calice66c2a01be scope link
10.233.102.168 dev cali3d4a731ea47 scope link
10.233.102.169 dev cali8fa7d9c3670 scope link
169.254.0.0/16 dev ens33 scope link metric 1002
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
192.168.198.0/24 dev ens33 proto kernel scope link src 192.168.198.145
  ss命令
• 格式: ss [OPTION]...[FILTER]
    选项:
         -t :tcp协议相关
-u :udp协议相关
-w :裸套接字相关
-x :unix sock相关
-l :listen状态的连接
-a :所有
-n :数字格式
-p :相关的程序及PID
-e :扩展的信息
-m:内存用量
-o:计时器信息         FILTER := [ state STATE-FILTER ] [ EXPRESSION ]
    常用组合:
      -tan,-tanl,-tanlp,-uan
[root@node1 ~]# ss -tan
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:34270 *:*
LISTEN 0 128 127.0.0.1:10248 *:*
LISTEN 0 128 127.0.0.1:10249 *:*
LISTEN 0 128 192.168.198.145:10250 *:*
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 192.168.198.145:2379 *:*
LISTEN 0 128 127.0.0.1:2379 *:*
LISTEN 0 128 192.168.198.145:2380 *:*
LISTEN 0 128 192.168.198.145:10255 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 127.0.0.1:8080 *:*
LISTEN 0 128 *:4369 *:*
LISTEN 0 8 *:179 *:*

 

3、详细说明进行管理工具htop、vmstat等相关命令,并举例 

htop:   top的升级版本
系统上没有自带 可以下载epel库
htop -l 选定一个进程所打开的所有文件
-s 进程发起的 系统调用
选项: -d 指定延迟时间间隔
-u username只显示指定用户的进程
-s colume:以指定字段进行排序
-t: 树状显示 层级关系
-a: 将选定的进程绑定到指定的CPU核心上
vmstat:报告虚拟内存的统计数据
vmstat 2 :2s 刷新一次
vmstat 2 3(显示3次)
结果分析:
procs: 进程
r:running 等待运行的进程个数 CPU上等待运行的任务队列长度 这个值是实时值
b:处于不可中断睡眠态进程的个数,被阻塞的任务队列的长度
memory 内存
swapd:交换内存的使用总量 对于服务器来说能不使用交换内存就不要使用
free:空闲的物理内存总量
buffer:用于缓冲的内存容量
cache:用户缓存的内存总量
swap
si:数据进入swap 中的数据速率 kb/s
so: 数据离开swap中的数据速率kb/s
io
bi: 从块设备读入数据到内存的速度kb/s
bo:从内存保存数据到硬盘
system
in:interrupts /s 中断速率 网络服务器会有很多io中断
cs:content switch 上下文切换

[root@node1 ~]# vmstat 2
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
4 0 0 109396 208 748912 0 0 1472 133 1479 4227 10 7 77 6 0
1 0 0 109044 208 748952 0 0 0 76 1353 3868 4 4 92 1 0
1 0 0 108872 208 749020 0 0 0 46 1408 4050 16 4 80 0 0
0 0 0 108844 208 749084 0 0 0 38 1370 3938 4 3 89 4 0
4、使用until和while分别实现192.168.0.0/24
网段内,地址是否能够ping通,弱ping通则输出"success!",若ping不通则输出"fail!"[root@node1 ~]# bash ping.sh
192.168.0.1 ping fail!
192.168.0.2 ping fail!
192.168.0.3 ping fail!#!/bin/bash
#declare -i i=1
until [ $i -gt 254 ]; do
if ping "192.168.0.$i" -c 1 &> /dev/null ; then
echo "192.168.0.$i ping success!"
else
echo "192.168.0.$i ping fail!"
fi
let i++
done

#!/bin/bash
#declare -i i=1
while [ $i -le 254 ]; do
if ping "192.168.0.$i" -c 1 &> /dev/null ; then
echo "192.168.0.$i ping success!"
else
echo "192.168.0.$i ping fail!"
fi
let i++
done