第六周

1、100.0.0.16/28 对应网段的网关地址、广播地址、可分配IP地址范围

IP地址转化为二进制:01100100 00000000 00000000 00010000

子网掩码:11111111 11111111 11111111 11110000

网络地址为: 01100100 00000000 00000000 00010000

IP范围:01100100 00000000 00000000 00010000-01100100 00000000 00000000 00011111

转化为十进制:100.0.0.16-100.0.0.31

网关地址:100.0.0.16

广播地址:100.0.0.31

IP地址范围:100.0.0.17-100.0.0.30

2、使用man手册学习tcpdump的使用

NAME
       tcpdump - dump traffic on a network   #抓取网络上的包
SYNOPSIS
       tcpdump [ -AbdDefhHIJKlLnNOpqStuUvxX# ] [ -B buffer_size ]
               [ -c count ]
               [ -C file_size ] [ -G rotate_seconds ] [ -F file ]
               [ -i interface ] [ -j tstamp_type ] [ -m module ] [ -M secret ]
               [ --number ] [ -Q|-P in|out|inout ]
               [ -r file ] [ -V file ] [ -s snaplen ] [ -T type ] [ -w file ]
               [ -W filecount ]
               [ -E spi@ipaddr algo:secret,...  ]
               [ -y datalinktype ] [ -z postrotate-command ] [ -Z user ]
               [ --time-stamp-precision=tstamp_precision ]
               [ --immediate-mode ] [ --version ]
               [ expression ]

常用选项:
-i:指定接口;
-c:指定抓包个数;
-n:关闭DNS查找,通过IP地址方式显示;
-nn:端口使用数字形式显示,不会对知名端口进行转换,如:80转换为http;
-vv:抓取数据时显示更多的信息,如:TTL、长度、选项、抓取到数据包个数等字段信息;
-w:将抓取到的数据包存入指定文件;

例:在ens35接口上抓取10个数据包,并通过ip地址及数字的方式显示

~]# tcpdump -nnvvi ens35 -c 10
tcpdump: listening on ens35, link-type EN10MB (Ethernet), capture size 262144 bytes
18:32:24.395028 IP (tos 0x0, ttl 128, id 19408, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.8.1.51238 > 192.168.8.7.80: Flags [S], cksum 0x58dc (correct), seq 1747605833, win 64240, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
18:32:24.395204 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.8.7.80 > 192.168.8.1.51238: Flags [S.], cksum 0x917f (incorrect -> 0x5d48), seq 1283405797, ack 1747605834, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
18:32:24.395561 IP (tos 0x0, ttl 128, id 19409, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.8.1.51238 > 192.168.8.7.80: Flags [.], cksum 0x0826 (correct), seq 1, ack 1, win 2053, length 0
18:32:24.397339 IP (tos 0x0, ttl 128, id 19410, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.8.1.51238 > 192.168.8.7.80: Flags [F.], cksum 0x0825 (correct), seq 1, ack 1, win 2053, length 0
18:32:24.397921 IP (tos 0x0, ttl 64, id 45483, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.8.7.80 > 192.168.8.1.51238: Flags [.], cksum 0x9173 (incorrect -> 0x0f45), seq 1, ack 2, win 229, length 0
18:32:24.398156 IP (tos 0x0, ttl 64, id 45484, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.8.7.80 > 192.168.8.1.51238: Flags [F.], cksum 0x9173 (incorrect -> 0x0f44), seq 1, ack 2, win 229, length 0
18:32:24.398947 IP (tos 0x0, ttl 128, id 19411, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.8.1.51238 > 192.168.8.7.80: Flags [.], cksum 0x0824 (correct), seq 2, ack 2, win 2053, length 0
18:32:26.406459 IP (tos 0x0, ttl 128, id 19412, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.8.1.51239 > 192.168.8.7.80: Flags [S], cksum 0xed8d (correct), seq 3910878117, win 64240, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
18:32:26.406575 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.8.7.80 > 192.168.8.1.51239: Flags [S.], cksum 0x917f (incorrect -> 0x804b), seq 1532009154, ack 3910878118, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
18:32:26.406890 IP (tos 0x0, ttl 128, id 19413, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.8.1.51239 > 192.168.8.7.80: Flags [.], cksum 0x2b29 (correct), seq 1, ack 1, win 2053, length 0
10 packets captured
10 packets received by filter
0 packets dropped by kernel

例:在ens35接口上抓取10个数据包,通过ip地址及数字的方式显示,并将输出内容存入/tmp/test.pcap文件中

~]# tcpdump -nnvvi ens35 -c 10 -w /tmp/test.pcap
[root@localhost ~]# tcpdump -nnvvi ens35 -c 10 -w /tmp/test.pcap
tcpdump: listening on ens35, link-type EN10MB (Ethernet), capture size 262144 bytes
10 packets captured
12 packets received by filter
0 packets dropped by kernel

3、详细叙述僵尸进程产生的原因以及危害

(1)什么是僵尸进程?

当子进程(child process)先于父进程(parent process)退出,但是父进程没有调用wait/waitpid回收子进程的资源,则子进程变成僵尸进程。

但是如果该进程的父进程已经结束,那该进程就不会变成僵尸进程,因为每个进程结束的时候,系统会扫描所有运行中的进程,看看有没有哪个进程是刚

刚结束的进程的子进程,如果有就由Init来接管他,成为他的父进程。

(2)危害?

如果父进程不调用wait/waitpid,则子进程的保留信息不会被释放,造成内核资源的无法回收,同时进程号会一直被占用,系统所能使用的进程号是

有限的,大量地产生僵尸进程将会导致系统不能产生新的进程。

(3)怎么避免僵尸进程?

防止的办法是当父进程fork一个子进程后,必须通过wait/waitpid等函数等待子进程结束,但这会导致父进程挂起,所以通常的做法是用signal函数为

SIGCHLD安装handler,在handler函数中调用wait/waitpid函数进行回收。

4、详细说明vmstat输出结果的含义

~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 1469696   2260 225956    0    0    57     3   76  136  1  2 98  0  0

procs:

  • r:处于等待运行的进程个数,CPU中等待运行的任务队列长度;
  • b:处于不可中断睡眠态的进程个数,被阻塞的任务队列长度;如果此队列长度较长,表明i/o能力较差;

memory:

  • swpd:交换内存的使用总量,0表示未启用交换内存,如果该值较大,表明物理内存过少;
  • free:空闲的物理内存总量;
  • buff:用于buffer的内存总量;
  • cache:用于cache的内存总量;

swap:

  • si:swap in,数据由物理内存进入swap中的数据速率(kb/s);
  • so:swap out,数据离开swap的数据速率(kb/s);
    io:
  • bi:block in,从块设备(如硬盘)加载数据到系统的速率(kb/s);
  • bo:block out,将数据保存至块设备的速率(kb/s);
    system:
  • in:interrupt,中断速率;
  • cs:context switch,上下文(进程)切换速率;该值越大表明运行的进程越多,并且CPU的处理能力无法满足当前需求;
    cpu:
  • us:user space
  • sy:system
  • id:idle
  • wa:wait
  • st: stolen
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值