qemu虚拟机,回放报文测试

启动qemu虚拟机
创建桥

$ cat virt/br0.sh 
#!/bin/bash

dev=enp2s0

ipaddr=`ip a s dev ${dev} |grep 'inet ' |awk '{print $2}'`
brctl addbr br0
brctl addif br0 ${dev}
brctl stp br0 on
ip a d $ipaddr dev ${dev}
ip a a $ipaddr dev br0
ip link set up br0

编辑 /etc/qemu/bridge.conf

$ cat /etc/qemu/bridge.conf 
allow br0

启动qemu虚拟机 单硬盘,双网卡配置。

qemu-system-x86_64 -cpu core2duo -M q35 -enable-kvm -boot dc,menu=on -display vnc=:1 -m 8G -smp 8 -drive file=sda.qcow2,id=d0,if=none -device ide-hd,drive=d0,bus=ide.0 -device e1000,netdev=mynet0,id=nic0 -device e1000,netdev=mynet1,id=nic1 -netdev tap,id=mynet0,helper=/usr/lib/qemu/qemu-bridge-helper -netdev tap,id=mynet1,helper=/usr/lib/qemu/qemu-bridge-helper 
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP mode DEFAULT group default qlen 1000
    link/ether c0:25:a5:c0:1e:77 brd ff:ff:ff:ff:ff:ff
3: wlx502b73dc6cda: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 50:2b:73:dc:6c:da brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:8d:c0:aa brd ff:ff:ff:ff:ff:ff
5: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 3e:e6:19:c7:82:b9 brd ff:ff:ff:ff:ff:ff
18: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:7a:91:22:8d:48 brd ff:ff:ff:ff:ff:ff
19: tap1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:25:86:5a:f3:04 brd ff:ff:ff:ff:ff:ff

tap0, tap1 是qemu-bridge-helper 创建的虚拟接口,绑定在桥接口br0
在宿主机上回放报文

生成cache:
./tcp_prep.sh client_ip pcap_file_name

$ cat /usr/bin/tcp_prep.sh 
#!/bin/bash

tcpprep -c $1 -i $2.pcap -o $2.cache

回放包。

$ cat /usr/bin/tcp_replay.sh
#!/bin/bash

tcpreplay  -i tap3 -I tap2 -M 1 -c $1.cache $1.pcap

速率控制 -M 1 表示每秒 1 Mbps.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值