Cloudflare Magic Network Monitoring
いわゆるフロー監視の仕組みになります。フローの閾値を超えると、プレフィックス広告をおこない、オンデマンドに DDoS 保護を有効にする連携が可能です。
Magic Network Monitoringは、お客様のルーターから送信されるネットワークフローデータを分析することで、ネットワークトラフィックの可視性を提供します。Magic Network Monitoringは、NetFlow v5、NetFlow v9、IPFIX、およびsFlowをサポートします。
エンタープライズ企業のお客様は、Magic Network Monitoring with Magic Transit on-demandを使用してネットワークを監視し、ボリュームのあるDDoS攻撃を特定し、Magic Transit on-demandを起動してこれらの攻撃を軽減できます。
Magic Network Monitoring 初期設定
フローを送信するルータのパブリック IP アドレスを設定する必要があります。
デフォルトサンプリングレートも設定可能です。
VyOS Flow Accounting
以下の機能により、VyOS で NetFlow / sFlow を使ってフローを外部に送ることができます。
ただ、VyOS Flow Accounting の設定だけでは動かない部分が多くあったので、直接設定ファイルに書き込むことが必要でした。
VyOSは、IPv4とIPv6の両方のトラフィックのフローアカウンティングをサポートしています。システムはフローエクスポーターとして機能し、互換性のあるコレクターと自由に使用することができます。
フローは、2つの異なるプロトコルを介してエクスポートすることができます: NetFlow(バージョン5、9、10/IPFIX)およびsFlowです。さらに、ルーター内部でフローをインメモリテーブルに保存することもできます。
NetFlow 設定
VyOS では、まず最低限の設定を実施します。
set system flow-accounting interface eth0
set system flow-accounting netflow engine-id 0
set system flow-accounting netflow version 9
set system flow-accounting netflow server 162.159.65.1 port 2055
その後、/etc/pmacct/uacctd.conf
を編集します。
aggregate
は、以下の Flow Record Template を参考に設定します。
timestamps_secs: true
の設定行も入れておきます。
sudo vi /etc/pmacct/uacctd.conf
# Genereated from VyOS configuration
daemonize: true
promisc: false
pidfile: /var/run/uacctd.pid
uacctd_group: 2
uacctd_nl_size: 2097152
snaplen: 128
aggregate: proto,src_host,dst_host,src_port,dst_port,in_iface,tcpflags,timestamp_start,timestamp_end
plugin_pipe_size: 10485760
plugin_buffer_size: 10485
imt_path: /tmp/uacctd.pipe
imt_mem_pools_number: 169
plugins: nfprobe[nf_162-159-65-1],memory
nfprobe_receiver[nf_162-159-65-1]: 162.159.65.1:2055
nfprobe_version[nf_162-159-65-1]: 9
nfprobe_engine[nf_162-159-65-1]: 0
timestamps_secs: true
設定ファイルを編集したら、uacctd
サービスを再起動して設定を反映させます。
sudo systemctl restart uacctd
$ sudo systemctl status uacctd
● uacctd.service - ulog accounting daemon
Loaded: loaded (/lib/systemd/system/uacctd.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2023-06-20 16:52:27 UTC; 26s ago
Process: 15562 ExecStart=/usr/sbin/uacctd -f ${UACCTD_CONF} $DAEMON_OPTS (code=exited, status=0/SUCCESS)
Main PID: 15564 (uacctd)
Tasks: 3 (limit: 4394)
Memory: 34.6M
CGroup: /system.slice/uacctd.service
├─15564 uacctd: Core Process [default]
├─15565 uacctd: Netflow Probe Plugin [nf_162-159-65-1]
└─15566 uacctd: IMT Plugin [default_memory]
Jun 20 16:52:27 kyouhei-osaka-vyos systemd[1]: Starting ulog accounting daemon...
Jun 20 16:52:27 kyouhei-osaka-vyos systemd[1]: Started ulog accounting daemon.
以下のコマンドで実際にメモリ内で保持されているテーブルが確認できます。
$ pmacct -p /tmp/uacctd.pipe -s -T packets | head
IN_IFACE SRC_IP DST_IP SRC_PORT DST_PORT TCP_FLAGS PROTOCOL TIMESTAMP_START TIMESTAMP_END PACKETS BYTES
2 162.159.66.145 10.202.0.4 0 0 0 ipv6-crypt 2023-06-21T07:36:12.000000Z 1970-01-01T00:00:00.000000Z 4061 462308
2 162.159.66.145 10.202.0.4 0 0 0 ipv6-crypt 2023-06-21T07:16:31.000000Z 1970-01-01T00:00:00.000000Z 12 1680
2 xxx.xx.xx.xxx 10.202.0.4 62791 22 24 tcp 2023-06-21T12:04:41.000000Z 1970-01-01T00:00:00.000000Z 12 840
2 172.217.25.170 10.202.0.4 443 57874 26 tcp 2023-06-21T11:23:46.000000Z 1970-01-01T00:00:00.000000Z 10 5700
2 142.250.76.138 10.202.0.4 443 60718 26 tcp 2023-06-21T07:21:46.000000Z 1970-01-01T00:00:00.000000Z 10 5702
2 142.250.206.202 10.202.0.4 443 45004 26 tcp 2023-06-21T09:22:46.000000Z 1970-01-01T00:00:00.000000Z 10 5701
2 142.250.206.202 10.202.0.4 443 40600 25 tcp 2023-06-21T07:21:18.000000Z 1970-01-01T00:00:00.000000Z 9 763
2 142.250.76.138 10.202.0.4 443 54738 25 tcp 2023-06-21T09:22:18.000000Z 1970-01-01T00:00:00.000000Z 9 762
tcpdump
では定期的に送信されている様子が確認できます。
$ sudo tcpdump -n -i any host 162.159.65.1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
12:04:01.878767 IP 10.202.0.4.46200 > 162.159.65.1.2055: UDP, length 120
12:04:01.878805 IP 10.202.0.4.46200 > 162.159.65.1.2055: UDP, length 276
12:04:01.878767 IP 10.202.0.4.46200 > 162.159.65.1.2055: UDP, length 120
12:04:01.878805 IP 10.202.0.4.46200 > 162.159.65.1.2055: UDP, length 276
12:04:01.878767 IP 10.202.0.4.46200 > 162.159.65.1.2055: UDP, length 120
12:04:01.878805 IP 10.202.0.4.46200 > 162.159.65.1.2055: UDP, length 276
しばらくフローを流した結果、Cloudflare Magic Network Monitoring では以下のような画面を確認できました。
参考:Flow Record Template
- Cisco IOS Flexible NetFlow Command Reference - match interface (Flexible NetFlow) through ttl (Flexible NetFlow) [Support] - Cisco
- Cisco IOS Flexible NetFlow Command Reference - cache (Flexible NetFlow) through match flow [Support] - Cisco
- vyos/pmacct: Vyatta version of pmacct
NetFlow Template | pmacct | Description |
---|---|---|
match ipv4 protocol |
proto |
Configures the IPv4 protocol as a key field. |
match ipv4 source address |
src_host |
Configures the IPv4 source address as a key field. |
match ipv4 destination address |
dst_host |
Configures the IPv4 destination address as a key field. |
match transport source-port |
src_port |
Configures the transport source port as a key field. |
match transport destination-port |
dst_port |
Configures the transport destination port as a key field. |
match interface input |
in_iface |
Configures the input interface as a key field. |
collect transport tcp flag |
tcpflags |
Configures one or more of the TCP flags as a key field. If you configure the flags keyword you must also configure at least one of the optional keywords for the flags keyword. |
collect counter packets long |
(Default included) | Number of packets that have been counted. |
collect counter bytes long |
(Default included) | Number of bytes that have been counted. |
collect flow sampler |
N/A | Configures the flow sampler ID as a nonkey field and enables the collection of the ID of the sampler that is assigned to the flow monitor. |
collect timestamp sys-uptime first |
timestamp_start |
Configures the system uptime for the time the first packet was seen from the flows as a nonkey field and enables collecting time stamps based on the system uptime for the time the first packet was seen from the flows. |
collect timestamp sys-uptime last |
timestamp_end |
Configures the system uptime for the time the last packet was seen from the flows as a nonkey field and enables collecting time stamps based on the system uptime for the time the most recent packet was seen from the flows. |
sFlow 設定
VyOS のコマンドでは以下の簡単なコマンドを入れます。
set system flow-accounting interface eth0
set system flow-accounting sflow server 162.159.65.1 port 6343
set system flow-accounting sflow agent-address 10.200.0.3
その後、以下のファイルを詳細に設定します。
[sf_162-159-65-1]
のものは、バグで無視されてしまうため、その行間に [sf_162.159.65.1]
として反映したい内容を設定します。
sudo vi /etc/pmacct/uacctd.conf
# Genereated from VyOS configuration
daemonize: true
promisc: false
pidfile: /var/run/uacctd.pid
uacctd_group: 2
uacctd_nl_size: 2097152
snaplen: 128
aggregate: proto,src_host,dst_host,src_port,dst_port,in_iface,tcpflags,timestamp_start,timestamp_end
plugin_pipe_size: 10485760
plugin_buffer_size: 10485
imt_path: /tmp/uacctd.pipe
imt_mem_pools_number: 169
plugins: sfprobe[sf_162.159.65.1],memory
sfprobe_receiver[sf_162-159-65-1]: 162.159.65.1:6343 # バグでこの設定は無視される
sfprobe_receiver[sf_162.159.65.1]: 162.159.65.1:6343 # 有効な設定を追記
sfprobe_agentip[sf_162.159.65.1]: ROUTER_PUBLIC_IP # 有効な設定を追記
sfprobe_agentip[sf_162-159-65-1]: 10.200.0.3 # バグでこの設定は無視される
timestamps_secs: true
設定ファイルを編集したら、uacctd
サービスを再起動して設定を反映させます。
sudo systemctl restart uacctd
$ sudo systemctl status uacctd
● uacctd.service - ulog accounting daemon
Loaded: loaded (/lib/systemd/system/uacctd.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2023-06-20 01:17:06 UTC; 6s ago
Process: 13307 ExecStart=/usr/sbin/uacctd -f ${UACCTD_CONF} $DAEMON_OPTS (code=exited, status=0/SUCCESS)
Main PID: 13308 (uacctd)
Tasks: 3 (limit: 4394)
Memory: 34.6M
CGroup: /system.slice/uacctd.service
├─13308 uacctd: Core Process [default]
├─13309 uacctd: sFlow Probe Plugin [sf_162.159.65.1]
└─13310 uacctd: IMT Plugin [default_memory]
Jun 20 01:17:06 kyouhei-tokyo-vyos systemd[1]: Starting ulog accounting daemon...
Jun 20 01:17:06 kyouhei-tokyo-vyos uacctd[13307]: WARN: [/etc/pmacct/uacctd.conf:15] Unknown symbol 'sf_162-159-65-1'. Ignored.
Jun 20 01:17:06 kyouhei-tokyo-vyos uacctd[13307]: WARN: [/etc/pmacct/uacctd.conf:18] Unknown symbol 'sf_162-159-65-1'. Ignored.
Jun 20 01:17:06 kyouhei-tokyo-vyos systemd[1]: Started ulog accounting daemon.
tcpdump
では以下の通信が確認できます。
$ sudo tcpdump -n -i any port 6343
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
01:06:03.839021 IP 10.200.0.3.58669 > 162.159.65.1.6343: sFlowv5, IPv4 agent ROUTER_PUBLIC_IP, agent-id 0, length 1232
01:06:03.839036 IP 10.200.0.3.58669 > 162.159.65.1.6343: sFlowv5, IPv4 agent ROUTER_PUBLIC_IP, agent-id 0, length 1248
01:06:03.839044 IP 10.200.0.3.58669 > 162.159.65.1.6343: sFlowv5, IPv4 agent ROUTER_PUBLIC_IP, agent-id 0, length 1324
01:06:03.839053 IP 10.200.0.3.58669 > 162.159.65.1.6343: sFlowv5, IPv4 agent ROUTER_PUBLIC_IP, agent-id 0, length 1248
しばらくフローを流した結果、Cloudflare Magic Network Monitoring では以下のような画面を確認できました。
まとめ
フローデータを Cloudflare に送るだけで簡単に可視化できて便利です。
GraphQL API から集計データを取り出したり、アラート機能とも連携できるため、活用の幅も広がります。
Cloudflare の画面は、直感的に操作しやすいので、ルータをお持ちの方はこの際にフローデータを流してみてはいかがでしょうか