模拟网络设备和 netflow

文章目录

使用 snmpsim 模拟网络设备

登录到对应的模拟服务器上新建 Python 虚拟环境安装 snmpsim

virtualenv snmp
. snmp/bin/activate
pip install snmpsim

在虚拟环境目录下的 snmpsim/data/ 文件夹里配置新的 community(如果需要自定义 -c 参数的话),可以先按照 public 复制一份新配置的 community 命名的数据

cp public jq-netmanager -r
cp public.snmprec jq-netmanager.snmprec

启动 snmpsimd 服务:

snmpsimd.py  --process-user=user_00 --process-group=root --agent-udpv4-endpoint=IP  --data-dir=./data

不能使用 root 用户启动,指定 process-user 时需要同时指定 process-group ,endpoint 默认绑定 161 端口,使用 host:port 形式可以指定其他端口

使用 snmpwalk 查看网络设备信息

yum install net-snmp-utils -y
snmpwalk -v 2c -c jq-netmanager IP

至此,网络设备模拟完成。

模拟 netflow

使用 NetFlow-Generator 模拟生成 netflow v5 数据并发送到指定的 collector

克隆 NetFlow-Generator 后,在其目录执行 make 即可生成一个 flowgen 可执行文件

./flowgen -h
Usage: flowgen [options] [flowrec-options] <collector>
    options:
    -n, --count <num>
    -p, --port <num>
    -V, --version <version>
    -f, --flowrec <# of flow records in packet>
    -d, --debug <debug level>
    -N, --nosend
    -h, --help
    flowrec-options:
    -w, --wait <wait time>
    -i, --interval <interval>
    --enginetype <engine type>
    --engineid <engine id>
    --srcaddr <src ip address>
    --dstaddr <dst ip address>
    --nexthop <nexthop ip address>
    --inputif <input IfIndex>
    --outputif <output IfIndex>
    --packets <# of packets>
    --octets <# of octets>
    --firstseen <first seen>
    --lastseen <last seen>
    --srcport <src port>
    --dstport <dst port>
    --tcpflags <tcp flags>
    --protocol <protocol number>
    --tos <tos value>
    --srcas <src AS#>
    --dstas <dst AS#>
    --srcmask <src subnet mask length>
    --dstmask <dst subnet mask length>

    Numbers can be expressed using the following meta characters:
111      (static)
111-222  (sequential)
111:222  (random)
100@70,200@20,300@10   (probabilistic)

启动 flowgen 产生 netflow 数据并上报的指定地址

./flowgen -i 5 -w 1000 -p 2055 IP

解析 netflow 数据

使用 nfdump 接收并解析 netflow 上报的数据

安装nfdump

yum install nfdump

运行接收上报数据的 nfcapd 进程

nfcapd -w -l . -p 2055

运行一段时间后会在 . 目录生成 nfcapd.201803052035 类似的文件

使用 nfdump 解析该文件:

nfdump -r nfcapd.201803061430 -c 2 'src ip 10.0.0.205'
nfdump -r nfcapd.201803061430 'ip 20.0.0.205 and proto tcp'
nfdump -r nfcapd.201803061430 -o extended -s srcip -s ip/flows -s dstport/pps/packets/bytes -s record/bytes

也可以看看


全国大流量卡免费领

19元月租ㆍ超值优惠ㆍ长期套餐ㆍ免费包邮ㆍ官方正品