Skip to main content
版本:2.6.2

模拟网络故障

本文主要介绍如何使用 Chaosd 模拟网络故障场景。该功能通过使用 iptables、ipsets、tc 等工具修改网络路由、流量控制来模拟网络故障。

注意

请确保 Linux 内核中有 NET_SCH_NETEM 模块。对于 CentOS,可以通过 kernel-modules-extra 包安装该模块,大部分其他发行版默认已安装相应模块。

使用命令行模式创建网络故障实验

本节介绍如何在命令行模式创建网络故障实验。

在创建网络故障实验前,可以运行以下命令查看 Chaosd 支持的网络故障类型:

chaosd attack network --help

输出结果如下所示:

Network attack related commands

Usage:
chaosd attack network [command]

Available Commands:
bandwidth limit network bandwidth
corrupt corrupt network packet
delay delay network
dns attack DNS server or map specified host to specified IP
duplicate duplicate network packet
loss loss network packet
partition partition
port attack network port

Flags:
-h, --help help for network

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

Use "chaosd attack network [command] --help" for more information about a command.

目前 Chaosd 支持模拟网络包错误(corrupt)、延迟(delay)、重复(duplicate)、丢失(loss)四种实验场景。

使用命令行模式模拟网络包错误

通过运行网络包错误命令,可以查看模拟网络包错误场景支持的配置。

网络包错误命令

具体命令如下所示:

chaosd attack network corrupt --help

输出结果如下所示:

corrupt network packet

Usage:
chaosd attack network corrupt [flags]

Flags:
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for corrupt
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
--percent string percentage of packets to corrupt (10 is 10%) (default "1")
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
-s, --source-port string only impact egress traffic from these source ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

网络包错误相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
correlationc表示包错误发生的概率与前一次是否发生的相关性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
deviced影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-porte仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostnameH只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ipi只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
protocolp只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-ports仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
percent网络包错误的比例string 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 1

网络包错误示例

运行以下命令,模拟网络包错误:

chaosd attack network corrupt -d eth0 -i 172.16.4.4 --percent 50

运行成功时,会输出以下结果:

Attack network successfully, uid: 4eab1e62-8d60-45cb-ac85-3c17b8ac4825

使用命令行模式模拟网络包延迟

通过运行网络包延迟命令,查看模拟网络延迟场景支持的配置。

网络包延迟命令

具体命令如下所示:

chaosd attack network delay --help

输出结果如下所示:

delay network

Usage:
chaosd attack network delay [flags]

Flags:
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for delay
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
-j, --jitter string jitter time, time units: ns, us (or µs), ms, s, m, h.
-l, --latency string delay egress time, time units: ns, us (or µs), ms, s, m, h.
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
-s, --source-port string only impact egress traffic from these source ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

网络包延迟相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
correlationc表示延迟时间的时间长度与前一次延迟时长的相关性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
deviced影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-porte仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostnameH只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ipi只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
jitterj延迟时间的变化范围string 类型,可使用的时间单位包括:ns、us (µs)、ms、s、m、h,如 "1ms"
latencyl表示延迟的时间长度string 类型,可使用的时间单位包括:ns、us (µs)、ms、s、m、h,如 "1ms"
protocolp只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-ports仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"

网络包延迟示例

运行以下命令,模拟网络包延迟:

chaosd attack network delay -d eth0 -i 172.16.4.4 -l 10ms

运行成功时,会输出以下结果:

Attack network successfully, uid: 4b23a0b5-e193-4b27-90a7-3e04235f32ab

使用命令行模式模拟网络包重复

可以运行网络包重复命令,查看模拟网络包重复场景支持的配置:

网络包重复命令

具体命令如下所示:

chaosd attack network duplicate --help

输出结果如下所示:

duplicate network packet

Usage:
chaosd attack network duplicate [flags]

Flags:
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for duplicate
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
--percent string percentage of packets to duplicate (10 is 10%) (default "1")
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
-s, --source-port string only impact egress traffic from these source ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

网络包重复相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
correlationc表示包重复发生的概率与前一次是否发生的相关性性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
deviced影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-porte仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostnameH只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ipi只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
percent网络包重复的比例int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 1
protocolp只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-ports仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"

网络包重复示例

运行以下命令,模拟网络包重复:

chaosd attack network duplicate -d eth0 -i 172.16.4.4 --percent 50

运行成功时,会输出以下结果:

Attack network successfully, uid: 7bcb74ee-9101-4ae4-82f0-e44c8a7f113c

使用命令行模式模拟网络包丢失

可以运行网络包丢失命令,查看模拟网络包丢失场景支持的配置:

使用命令行模式模拟网络包丢失命令

具体命令如下所示:

chaosd attack network loss --help

输出结果如下所示:

loss network packet

Usage:
chaosd attack network loss [flags]

Flags:
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for loss
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
--percent string percentage of packets to drop (10 is 10%) (default "1")
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
-s, --source-port string only impact egress traffic from these source ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

网络包丢失相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
correlationc表示丢包发生的概率与前一次是否发生的相关性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
deviced影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-porte仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostnameH只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ipi只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
percent网络丢包的比例int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 1
protocolp只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-ports仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"

网络包丢失示例

运行以下命令,模拟网络包丢失:

chaosd attack network loss -d eth0 -i 172.16.4.4 --percent 50

运行成功时,会输出以下结果:

Attack network successfully, uid: 1e818adf-3942-4de4-949b-c8499f120265

使用命令行模式模拟网络分区

可以运行网络分区命令,查看模拟网络分区场景支持的配置。

网络分区命令

具体命令如下所示:

chaosd attack network partition --help

输出结果如下所示:

partition

Usage:
chaosd attack network partition [flags]

Flags:
--accept-tcp-flags string only the packet which match the tcp flag can be accepted, others will be dropped. only set when the protocol is tcp.
-d, --device string the network interface to impact
--direction string specifies the partition direction, values can be 'from', 'to'. 'from' means packets coming from the 'IPAddress' or 'Hostname' and going to your server, 'to' means packets originating from your server and going to the 'IPAddress' or 'Hostname'.
-h, --help help for partition
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

网络分区相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
accept-tcp-flags表示接收包含指定标志的的 tcp 数据包,其他的则丢弃。具体配置规则参考 iptables 的 tcp-flags。仅当 protocol 为 tcp 时可以配置。string 类型,例如:"SYN,ACK SYN,ACK"
deviced影响的网卡设备名称string 类型,例如 "eth0",必须要设置
direction指定分区的方向,对来自/发送到 hostname 指定的主机或者 ip 指定的地址的数据包进行分区string 类型,可选值为 "from" 或者 "to"
hostnameH只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ipi只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
protocolp只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、udp、icmp、all(表示影响所有网络协议)

网络分区命令示例

./chaosd attack network partition -i 172.16.4.4 -d eth0 --direction from

使用命令行模式模拟 DNS 故障

可以运行 DNS 故障命令,查看模拟 DNS 故障场景支持的配置。

DNS 故障命令

具体命令如下所示:

chaosd attack network dns --help

输出结果如下所示:

attack DNS server or map specified host to specified IP

Usage:
chaosd attack network dns [flags]

Flags:
-d, --dns-domain-name string map this host to specified IP
-i, --dns-ip string map specified host to this IP address
--dns-server string update the DNS server in /etc/resolv.conf with this value (default "123.123.123.123")
-h, --help help for dns

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

DNS 故障相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
dns-domain-nameH表示影响的域名。string 类型,例如:"chaos-mesh.org"
dns-ipi表示将影响的域名映射到该地址。string 类型,例如 "123.123.123.123"
dns-server指定 DNS 服务地址。string 类型,默认值为 "123.123.123.123"

DNS 故障示例

通过映射指定的主机名和 IP 地址从而模拟 DNS 故障,运行命令如下所示:

./chaosd attack network dns --dns-ip 123.123.123.123 --dns-domain-name chaos-mesh.org

配置错误的 DNS 服务地址从而模拟 DNS 故障,运行命令如下所示:

chaosd attack network dns --dns-server 123.123.123.123

使用命令行模式限制网络带宽

可以运行限制网络带宽命令,查看该场景支持的配置。

限制网络带宽命令

具体命令如下所示:

chaosd attack network bandwidth --help

输出结果如下所示:

limit network bandwidth

Usage:
chaosd attack network bandwidth [flags]

Flags:
-b, --buffer uint32 the maximum amount of bytes that tokens can be available for instantaneously
-d, --device string the network interface to impact
-h, --help help for bandwidth
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
-l, --limit uint32 the number of bytes that can be queued waiting for tokens to become available
-m, --minburst uint32 specifies the size of the peakrate bucket
--peakrate uint the maximum depletion rate of the bucket
-r, --rate string the speed knob, allows bps, kbps, mbps, gbps, tbps unit. bps means bytes per second

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

限制网络带宽相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
bufferb能够瞬间发送的最大字节数uint32 类型,如:10000。必须要设置
deviced影响的网卡设备名称string 类型,如 "eth0",必须要设置
hostnameH只影响到指定的主机名string 类型,如 "chaos-mesh.org"hostnameip 不能同时为空。同时设置 hostnameip 时,配置项对指定的主机名和 IP 地址均产生影响
ip-addressi仅影响到指定的 IP 地址string 类型,如 "123.123.123.123"hostnameip 不能同时为空。同时设置 hostnameip 时,配置项对指定的主机名和 IP 地址均产生影响
limiti在队列中等待的字节数uint32 类型,如:10000。必须要设置
minburstmpeakrate bucket 的大小uint32 类型,如:10000
peakratebucket 的最大消耗率uint64 类型,如:10000
rater带宽限制的速率string 类型,如 "1mbps"。必须要设置

限制网络带宽示例

./chaosd attack network bandwidth --buffer 10000 --device eth0 --limit 10000 --rate 10mbps

使用命令行模式占用端口

可以运行占用端口命令,查看该场景支持的配置。

占用端口命令

具体命令如下所示:

chaosd attack network port --help

输出结果如下所示:

attack network port

Usage:
chaosd attack network port [flags]

Flags:
-h, --help help for port
-p, --port string this specified port is to occupied

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

占用端口相关配置说明

相关配置说明如下所示:

配置项配置缩写说明
portp占用的端口号int 类型,例如:8080。必须要设置

占用端口示例

./chaosd attack network port --port 8080

使用服务模式创建网络故障实验

要使用服务模式创建实验,请进行以下操作:

  1. 以服务模式运行 chaosd。
    chaosd server --port 31767
  2. 向 chaosd 服务的路径 /api/attack/network 发送 HTTP POTST 请求。 bash curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{fault-configuration}' 其中 fault-configuration 需要按照故障类型进行配置,对应的配置参数请参考下文中各个类型故障的相关参数说明和命令示例。 在运行实验时,请注意保存实验的 uid 信息,当要结束 uid 对应的实验时,需要向 chaosd 服务的路径 /api/attack/{uid} 发送 HTTP DELETE 请求。

使用服务模式模拟网络包错误

在使用服务模拟网络包错误时,请参考如下内容。

网络包错误相关参数说明

相关参数说明如下所示:

参数说明
action实验的行为设置为 "corrupt"
correlation表示包错误发生的概率与前一次是否发生的相关性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
device影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-port仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostname只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ip-address只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
ip-protocol只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-port仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
percent网络包错误的比例string 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 1

使用服务模式模拟网络包错误示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"corrupt","device":"eth0","ip-address":"172.16.4.4","percent":"50"}'

使用服务模式模拟网络包延迟

在使用服务模拟网络包延迟时,请参考如下内容。

网络包延迟相关参数说明

相关参数说明如下所示:

参数说明
action实验的行为设置为 "delay"
correlation表示延迟时间的时间长度与前一次延迟时长的相关性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
device影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-port仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostname只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ip-address只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
jitter延迟时间的变化范围string 类型,可使用的时间单位包括:ns、us (µs)、ms、s、m、h,如 "1ms"
latency表示延迟的时间长度string 类型,可使用的时间单位包括:ns、us (µs)、ms、s、m、h,如 "1ms"
ip-protocol只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-port仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"

使用服务模式模拟网络包延迟示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"delay","device":"eth0","ip-address":"172.16.4.4","latency":"10ms"}'

使用服务模式模拟网络包重复

在使用服务模拟网络包重复时,请参考如下内容。

网络包重复相关参数说明

相关参数说明如下所示:

参数说明
action实验的行为设置为 "duplicate"
correlation表示包重复发生的概率与前一次是否发生的相关性性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
device影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-port仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostname只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ip-address只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
percent网络包重复的比例int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 1
ip-protocol只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-port仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"

使用服务模式模拟网络包重复示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"duplicate","ip-address":"172.16.4.4","device":"eth0","percent":"50"}'

使用服务模式模拟网络包丢失

在使用服务模拟网络包丢失时,请参考如下内容。

网络包丢失相关参数说明

相关参数说明如下所示:

参数说明
action实验的行为设置为 "loss"
correlation表示丢包发生的概率与前一次是否发生的相关性int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 0
device影响的网卡设备名称string 类型,例如 "eth0",必须要设置
egress-port仅影响到指定目的端口的出口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"
hostname只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ip-address只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
percent网络丢包的比例int 类型,取值范围为 0 到 100,表示百分比(10 表示 10%),默认值为 1
ip-protocol只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、 udp、icmp、all(表示影响所有网络协议)
source-port仅影响到指定目的端口的入口流量,仅当 protocol 为 tcp 或 udp 时配置string 类型,使用 "," 分隔指定的端口或者端口范围,如 "80,8001:8010"

使用服务模式模拟网络包丢失示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"loss","ip-address":"172.16.4.4","device":"eth0","percent":"50"}'

使用服务模式模拟网络分区

在使用服务模式模拟网络分区时,请参考如下内容。

网络分区相关参数说明

相关参数说明如下所示:

参数说明
action实验的行为设置为 "partition"
accept-tcp-flags表示接收包含指定标志的的 tcp 数据包,其他的则丢弃。具体配置规则参考 iptables 的 tcp-flags。仅当 protocol 为 tcp 时可以配置。string 类型,例如:"SYN,ACK SYN,ACK"
device影响的网卡设备名称string 类型,例如 "eth0",必须要设置
direction指定分区的方向,对来自/发送到 hostname 指定的主机或者 ip 指定的地址的数据包进行分区string 类型,可选值为 "from" 或者 "to"
hostname只影响到指定的主机名string 类型,如 "chaos-mesh.org"
ip-address只影响到指定的 IP 地址string 类型,如 "123.123.123.123"
protocol只影响指定的 IP 协议string 类型,支持协议类型包括:tcp、udp、icmp、all(表示影响所有网络协议)

服务模式网络分区命令示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"partition","ip-address":"172.16.4.4","device":"eth0","direction":"from"}'

使用服务模式模拟 DNS 故障

在使用服务模拟 DNS 故障时,请参考如下内容。

DNS 故障相关参数说明

相关参数说明如下所示:

参数说明
action实验的行为设置为 "dns"
dns-domain-name表示影响的域名。string 类型,例如:"chaos-mesh.org"
dns-ip表示将影响的域名映射到该地址。string 类型,例如 "123.123.123.123"
dns-server指定 DNS 服务地址。string 类型,默认值为 "123.123.123.123"

使用服务模式模拟 DNS 故障示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"dns","dns-ip":"123.123.123.123","dns-domain-name":"chaos-mesh.org"}'

使用服务模式限制网络带宽

在使用服务模式限制网络带宽,请参考如下内容。

限制网络带宽相关参数说明

相关参数说明如下所示:

参数说明
buffer能够瞬间发送的最大字节数uint32 类型,如:10000。必须要设置
device影响的网卡设备名称string 类型,如 "eth0",必须要设置
hostname仅影响到指定的主机名string 类型,如 "chaos-mesh.org"hostnameip 不能同时为空;同时设置 hostnameip 时,配置项对指定的主机名和 IP 地址均产生影响
ip-address只影响到指定的 IP 地址string 类型,如 "123.123.123.123"hostnameip 不能都为空;同时设置 hostnameip 时,配置项对指定的主机名和 IP 地址均产生影响
limit在队列中等待的字节数uint32 类型,如:10000。必须要设置
minburstpeakrate bucket 的大小uint32 类型,如:10000
peakratebucket 的最大消耗率uint64 类型,如:10000
rate带宽限制的速率string 类型,如 "1mbps"。必须要设置

使用服务模式限制网络带宽示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"bandwidth","ip-address": "123.123.123.123", "buffer": 10000, "device": "eth0", "limit": 10000, "rate": "10mbps"}'

使用服务模式占用端口

在使用服务模式占用端口,请参考如下内容。

占用端口相关参数说明

相关配置说明如下所示:

配置项说明
port占用的端口号int 类型,例如:8080。必须要设置

使用服务模式占用端口示例

curl -X POST 172.16.112.130:31767/api/attack/network -H "Content-Type:application/json" -d '{"action":"port", "port": 8080}'