1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
---
myst:
html_meta:
description: |
VyOS can group IPv4 and IPv6 traffic into flows and export a record
of each flow to one or more external collectors, using the NetFlow or
IPFIX protocol.
keywords: flow-accounting, netflow, ipfix, exporter, collector
---
(flow-accounting)=
# Flow accounting
A flow is a stream of packets that share key header fields, such as source and
destination IP addresses, ports, and protocol.
Flow accounting groups IPv4 and IPv6 traffic into flows and records how many
packets and bytes each flow carries. These records are then exported to one or
more external collectors, using the {abbr}`NetFlow (Cisco NetFlow)` or
{abbr}`IPFIX (IP Flow Information Export)` protocol.
Flow accounting is applied per interface. By default, only traffic entering an
interface (ingress) is accounted for. Traffic leaving an interface (egress) is
added with `enable-egress`.
The router also supports sFlow, a separate monitoring protocol. Instead of
grouping packets into flows, sFlow sends packet samples taken at a configurable
rate to a collector (see {ref}`sflow`).
## Configuration
### Monitored interfaces
```{cfgcmd} set system flow-accounting netflow interface \<interface\>
**Enable flow accounting on the specified interface.**
Repeat the command to enable flow accounting on multiple interfaces.
Enable flow accounting on at least one interface. Otherwise, the commit fails.
```
Example:
```none
set system flow-accounting netflow interface eth0
```
```{cfgcmd} set system flow-accounting enable-egress
**Enable flow accounting for traffic leaving the monitored interfaces.**
By default, only traffic entering the interfaces is accounted for.
```
Example:
```none
set system flow-accounting enable-egress
```
### Flow export
```{cfgcmd} set system flow-accounting netflow server \<address\>
**Configure the address of a collector that receives the exported records.**
Accepts an IPv4 or IPv6 address.
Repeat the command to export records to multiple collectors.
At least one collector must be configured. Otherwise, the commit fails.
```
Example:
```none
set system flow-accounting netflow server 192.0.2.10
set system flow-accounting netflow server 2001:db8::10
```
```{cfgcmd} set system flow-accounting netflow server \<address\> port \<1025-65535\>
**Configure the destination port on the collector.**
The default is 2055.
```
Example:
```none
set system flow-accounting netflow server 192.0.2.10 port 4739
```
```{cfgcmd} set system flow-accounting netflow server \<address\> source-address \<address\>
**Configure the source address the router uses to reach the collector.**
The address must already be assigned to a local interface. If flow accounting
is bound to a VRF, the address must be assigned within that VRF.
Set either `source-address` or `source-interface` for a collector, not both.
Configuring both for the same collector fails the commit.
```
Example:
```none
set system flow-accounting netflow server 192.0.2.10 source-address 192.0.2.1
```
```{cfgcmd} set system flow-accounting netflow server \<address\> source-interface \<interface\>
**Configure the interface the router uses to reach the collector.**
When flow accounting is bound to a VRF, the interface must belong to that VRF.
Set either source-address or source-interface for a collector, not both.
Configuring both for the same collector fails the commit.
```
Example:
```none
set system flow-accounting netflow server 192.0.2.10 source-interface eth0
```
```{cfgcmd} set system flow-accounting netflow version \<5 | 9 | 10\>
**Configure the export protocol version.**
Version 5 exports IPv4 flows only. Version 9 and version 10 (IPFIX) also
export IPv6 flows.
The default is 9.
```
Example:
```none
set system flow-accounting netflow version 10
```
```{cfgcmd} set system flow-accounting netflow engine-id \<id\>
**Configure the identifier the router places in the exported records to
distinguish this exporter's flow streams.**
For version 5, use two values in the form `<0-255>:<0-255>`. For versions 9
and 10, use a single value from 0 to 4294967295.
The value must be valid for the configured version. Otherwise, the commit
fails.
```
Example:
```none
set system flow-accounting netflow engine-id 100
```
```{cfgcmd} set system flow-accounting netflow sampling-rate \<0-4294967295\>
**Export one flow in every N instead of every flow.**
Flows are selected at random. Each exported flow carries the full packet and
byte counts collected for it. Sampling reduces the number of flows sent to
collectors. The router reports `N` to collectors so they can estimate the
total.
By default, no sampling is applied, and every flow is exported.
```
Example:
```none
set system flow-accounting netflow sampling-rate 1000
```
```{cfgcmd} set system flow-accounting netflow max-flows \<0-4294967295\>
**Configure the maximum number of flows accounted for at the same time.**
By default, no explicit maximum is set.
```
Example:
```none
set system flow-accounting netflow max-flows 2000000
```
```{cfgcmd} set system flow-accounting netflow inactive-timeout \<0-2147483647\>
**Configure the number of seconds without new packets after which a flow is
considered finished and exported.**
The default is 15.
```
Example:
```none
set system flow-accounting netflow inactive-timeout 15
```
```{cfgcmd} set system flow-accounting netflow active-timeout \<0-2147483647\>
**Configure the maximum number of seconds an active flow is accounted for
before it is exported.**
A flow still receiving packets is exported once this time is reached.
The default is 1800.
```
Example:
```none
set system flow-accounting netflow active-timeout 1800
```
```{cfgcmd} set system flow-accounting vrf \<name\>
**Export flow records within the specified
{abbr}`VRF (Virtual Routing and Forwarding)` instance.**
The router reaches collectors through that VRF.
A collector configured with `source-interface` receives export packets
from that interface, which must belong to the VRF.
The VRF must already be configured with `set vrf name <name>`.
```
Example:
```none
set system flow-accounting vrf mgmt
```
## Operation
```{opcmd} show flow-accounting
Show all flows the router is currently accounting for.
```
```{opcmd} show flow-accounting interface \<interface\>
Show accounted flows on the specified interface.
```
```{opcmd} show flow-accounting interface \<interface\> host \<address\>
Show accounted flows on the specified interface whose source or destination
address is the given IPv4 or IPv6 address.
```
```{opcmd} show flow-accounting interface \<interface\> port \<1-65535\>
Show accounted flows on the specified interface whose source or destination
port is the given port.
```
```{opcmd} show flow-accounting interface \<interface\> top \<1-100\>
Show accounted flows on the specified interface, limited to the first N
entries.
```
```{opcmd} restart flow-accounting
Restart flow accounting and reattach it to monitored interfaces.
If flow accounting is not configured and running, the command reports this and
exits without starting it.
```
## Example
The following example enables flow accounting on `eth0` and `eth1`, and exports
version 10 (IPFIX) records to the collector at `192.0.2.10` on port `4739`,
using `192.0.2.1` as the source address.
```none
set system flow-accounting netflow interface eth0
set system flow-accounting netflow interface eth1
set system flow-accounting netflow version 10
set system flow-accounting netflow server 192.0.2.10 port 4739
set system flow-accounting netflow server 192.0.2.10 source-address 192.0.2.1
```
|