Agenda: exercises-netflow-nfsen.txt

File exercises-netflow-nfsen.txt, 9.0 KB (added by admin, 7 years ago)
Line 
1Network Monitoring and Management
2
3Configure Your Router to Export Flows
4-------------------------------------
5
61. Export flows from a router
7
8This is a sample for doing this from the Group 1 router, rtr1.ws.nsrc.org to
9the PC named pc1.ws.nsrc.org or 10.10.1.1. In each of your groups 1 through 9
10you must choose one person to type in the commands to set up router for Netflow
11and one PC where the Netflow exports will go.  IOS can unfortunately not send
12Netflow messages to more than 1 or 2 devices, so we will use only 1 now.
13
14For example, if our router is rtr1, or 10.10.1.254 (Group 1 gateway):
15
16Log in on the router:
17
18   # ssh cisco@10.10.1.254
19   rtr1.ws.nsrc.org> enable
20
21Enter the enable password...
22
23Configure FastExthernet 0/0 to generate netflow:
24
25   rtr1.ws.nsrc.org# configure terminal
26   rtr1.ws.nsrc.org(config)# interface FastEthernet 0/0
27   rtr1.ws.nsrc.org(config-if)# ip flow ingress
28   rtr1.ws.nsrc.org(config-if)# ip flow egress
29   rtr1.ws.nsrc.org(config-if)# exit
30   rtr1.ws.nsrc.org(config)# ip flow-export destination 10.10.0.254 999X
31   rtr1.ws.nsrc.org(config)# ip flow-export version 5
32   rtr1.ws.nsrc.org(config)# ip flow-cache timeout active 5
33
34This breaks up long-lived flows into 5-minute fragments. You can
35choose any number of minutes between 1 and 60. If you leave it at
36the default of 30 minutes your traffic reports will have spikes.
37
38   rtr1.ws.nsrc.org(config)# snmp-server ifindex persist
39
40This enables ifIndex persistence globally. This ensures that the
41ifIndex values are persisted during router reboots.
42
43Now configure how you want the ip flow top-talkers to work:
44
45   rtr1.ws.nsrc.org(config)#ip flow-top-talkers
46   rtr1.ws.nsrc.org(config-flow-top-talkers)#top 20
47   rtr1.ws.nsrc.org(config-flow-top-talkers)#sort-by bytes
48   rtr1.ws.nsrc.org(config-flow-top-talkers)#end
49 
50Now we'll verify what we've done.
51
52   rtr1.ws.nsrc.org# show ip flow export
53   rtr1.ws.nsrc.org# show ip cache flow
54
55See your "top talkers" across your router interfaces
56
57   rtr1.ws.nsrc.org# show ip flow top-talkers
58
59If it all looks good then write your running-config to non-volatile
60RAM (i.e. the startup-config):
61
62   rtr1.ws.nsrc.org#wr mem
63   
64You can exit from the router now:
65
66   rtr1.ws.nsrc.org#exit
67   
68We are re-exporting NetFlow data from the gateway router to all the PCs in the classroom.
69You can verify that these flows are arriving by typing:
70
71        # tcpdump -v udp port 9009
72
73And this will show you the flows from the router in your group.
74
75
76Configure Your Collector
77------------------------
78
791. Install NFdump
80   NFdump is the Netflow flow collector
81
82   We install several additional packages that we will need a bit
83   later:
84
85Only install these if you did not already install mrtg and rrdtool:
86
87   # apt-get install rrdtool
88   # apt-get install librrds-perl
89   # apt-get install librrdp-perl
90   # apt-get install mrtg
91   # apt-get install libmailtools-perl
92
93If mrtg and rrdtool are already installed, then you just need these:
94 
95   # apt-get install librrd-dev
96   # apt-get install nfdump
97   # apt-get install libmailtools-perl
98
99Or, on a single line:
100
101   # apt-get install rrdtool mrtg librrds-perl librrdp-perl librrd-dev nfdump \
102                libmailtools-perl
103
104   This will install, among other things, nfcapd, nfdump, nfreplay,
105   nfexpire, nftest, nfgen
106
107
1082. Installing and Setting up NfSen (logged in as root)
109
110   # cd /usr/local/src
111   # wget http://noc.ws.nsrc.org/downloads/nfsen-1.3.5.tar.gz
112   # tar xvzf nfsen-1.3.5.tar.gz
113   # cd nfsen-1.3.5
114   # cd etc
115   # cp nfsen-dist.conf nfsen.conf
116   # editor nfsen.conf
117
118Set the $BASEDIR variable
119
120   $BASEDIR="/var/nfsen";
121
122Set the users appropriately so that Apache can access files:
123
124   $WWWUSER = 'www-data';
125   $WWWGROUP = 'www-data'   
126
127Adjust the tools path to where items actually reside:
128
129        # nfdump tools path
130        $PREFIX = '/usr/bin';
131
132Set the buffer size to something small, so that we see data quickly
133
134        # Receive buffer size for nfcapd - see man page nfcapd(1)
135        $BUFFLEN = 2000;
136
137Find the %sources definition, and change it to:
138
139   %sources=(
140   'rtrX'=>{'port'=>'9996','col'=>'#ff0000','type'=>'netflow'},
141     'gw'=>{'port'=>'9009','col'=>'#0000ff','type'=>'netflow'},
142   );                             
143
144Now save and exit from the file.
145
146
1473. Create the netflow user on the system
148
149   # useradd -d /var/netflow -G www-data -m -s /bin/false netflow
150
151
1524. Initiate NfSen. Any time you make changes to nfsen.conf you will
153   have to do this step again.
154
155Make sure we are in the right location:
156
157   # cd /usr/local/src/nfsen-1.3.5
158
159Now, finally, we install:
160
161   # perl install.pl etc/nfsen.conf
162
163Start NfSen
164
165cd /var/nfsen/bin
166./nfsen start
167
168
1695. View flows via the web:
170
171   This should not be necessary, but just in case:
172
173   # apt-get install php5
174   
175You can find the nfsen output here:
176
177   http://pcN.ws.nsrc.org/nfsen/nfsen.php
178
179(Below is only if there are problems)
180
181Note that in /usr/local/src/nfsen-1.3.5/etc/nfsen.conf there is a variable
182$HTMLDIR that you may need to configure. By default it is set like this:
183
184   $HTMLDIR="/var/www/nfsen/";
185
186In some cases you may need to either move the nfsen directory in your web
187structure, or update the $HTMLDIR variable for your installation.
188
189If you move items, then do:
190
191   # /etc/init.d/apache2 restart
192
193
1946. Verify that flows are arriving
195
196Assuming that you are exporting flows from a router, or routers, to
197your collector box on port 9009 you can check for arriving data using
198tcpdump:
199
200   # tcpdump -v udp port 9009
201   # tcpdump -v udp port 9996
202
203OPTIONAL
204
205
2067. Installing the PortTracker plugin (Optional or as reference)
207
208# apt-get install bison flex
209# cd /usr/local/src
210# wget http://noc.ws.nsrc.org/downloads/nfdump-1.6.3p1.tar.gz
211# tar xvzf nfdump-1.6.3p1.tar.gz
212# cd nfdump-1.6.3p1
213# ./configure
214# make
215
216
217
218- Go the PortTracker directory in the nfsen source distribution:
219
220   # cd /usr/local/src/nfsen-1.3.5/contrib/PortTracker
221
222   # editor do_compile
223
224      # path of nfdump sources
225      NFDUMP="/usr/local/src/nfdump-1.6.3p1"
226
227      # path of rrd include file rrd.h
228      RRDINCLUDE=/usr/include
229
230      # path of rrd library
231      LIBRRD=/usr/lib
232
233- Compile nftrack:
234
235   # ./do_compile
236
237...
238
239   # cp nftrack /usr/bin/
240
241- Make a directory for the nftrack data
242
243   # mkdir -p /var/log/netflow/porttracker
244   # chown www-data /var/log/netflow/porttracker
245
246- Set the nftrack data directory in the PortTracker.pm module:
247
248   # editor PortTracker.pm
249
250    Find the line:
251
252                my $PORTSDBDIR = "/data/ports-db";
253
254        and change it to:
255
256        my $PORTSDBDIR = "/var/log/netflow/porttracker";
257
258    ...
259
260- Install the plugins into the NFSen distribution
261
262   # cp PortTracker.pm /var/nfsen/plugins/
263   # cp PortTracker.php /var/www/nfsen/plugins/
264
265- Add the plugin definition to the nfsen.conf configuration
266
267   # cd /usr/local/src/nfsen-1.3.5
268   # editor etc/nfsen.conf
269
270    Find the plugins section and make it look like this:
271
272       @plugins = (
273           [ 'live',   'PortTracker'],
274       );
275
276    ...
277
278- Re-run the installation (answer questions)
279
280   # perl install.pl etc/nfsen.conf
281
282- Initialize portracker database files
283
284   # sudo -u www-data nftrack -I -d /var/log/netflow/porttracker
285
286    (This can take a LONG time! - 8 GB worth of files will be created)
287
288- Set the permissions so the netflow user running nfsen, and the www-data
289  user running the Web interface, can access the porttracker data:
290
291   # chown -R netflow:www-data /var/log/netflow/porttracker
292   # chmod -R 775 /var/log/netflow/porttracker
293
294- Reload:
295
296   # /var/nfsen/bin/nfsen reload
297
298- Check for success:
299
300   # grep -i 'porttracker.*success' /var/log/syslog
301Nov 27 02:46:13 noc nfsen[17312]: Loading plugin 'PortTracker': Success
302Nov 27 02:46:13 noc nfsen[17312]: Initializing plugin 'PortTracker': Success
303
304- Wait some minutes, and go the the nfsen GUI
305
306    http://pcN.ws.nsrc.org/nfsen/nfsen.php
307
308... and select the Plugins tab.
309
310If you get an error "Cannot Read Stats file", check the /var/log/netflow/porttracker directory for 2 additional files: portstat24.txt and portstat.txt like this:
311
312        # ls -l /var/log/netflow/porttracker/portstat*
313        -rw-r--r-- 1 netflow www-data     677 2011-11-17 14:30 /var/log/netflow/porttracker/portstat24.txt
314        -rwxrwxr-x 1 netflow www-data     638 2011-11-17 14:30 /var/log/netflow/porttracker/portstat.txt
315
316
317
3188. If you wanted to add more sources...
319
320Go back to where you extracted your nfsen distribution.
321
322   # cd /usr/local/src/nfsen-1.3.5
323   # editor etc/nfsen.conf
324
325Update your sources for new items that you might have.
326(Sample only!)
327
328        %sources = (
329        'rtr' => {'port' => '9000', 'col' => 'e4e4e4' },
330        'rtr2' => { 'port' => '9001', 'col' => '#0000ff' },
331        'rtr3' => { 'port' => '9002','col' => '#00cc00' },
332        'rtr4' => { 'port' => '9003','col' => '#000000' },
333        'rtr5' => { 'port' => '9004','col' => '#ff0000' },
334        'rtr6' => { 'port' => '9005','col' => '#ffff00' },
335        );
336
337Save and exit from the nfsend.conf file.
338
339Remember, you've updated nfsen.conf so you must re-run the install
340script:
341
342   # perl install.pl etc/nfsen.conf
343
344Now start and stop nfsen:
345
346   # /var/nfsen/bin/nfsen stop
347   # /var/nfsen/bin/nfsen start
348
349You can add the nfsen startup script to /etc/init.d/rc.local
350or somewhere similar to start it at bootup.)
351
352