1 | % Monitoring Netflow with NFsen |
---|
2 | % |
---|
3 | % Network Monitoring and Management |
---|
4 | |
---|
5 | # Introduction |
---|
6 | |
---|
7 | ## Goals |
---|
8 | |
---|
9 | * Learn how to install the nfdump and NfSen tools |
---|
10 | |
---|
11 | ## Notes |
---|
12 | |
---|
13 | * Commands preceded with "$" imply that you should execute the command as |
---|
14 | a general user - not as root. |
---|
15 | * Commands preceded with "#" imply that you should be working as root. |
---|
16 | * Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") |
---|
17 | imply that you are executing commands on remote equipment, or within |
---|
18 | another program. |
---|
19 | |
---|
20 | ## Assumption |
---|
21 | |
---|
22 | This assumes you have already configured your router to export flows to a PC in |
---|
23 | your group and that your neighbor group has configured a router to export flows |
---|
24 | to the same PC. See exercise1-flow-export for additional details. |
---|
25 | |
---|
26 | # Configure Your Collector |
---|
27 | |
---|
28 | ## Install NFDump and associated software |
---|
29 | |
---|
30 | NFdump is the Netflow flow collector. We install several additional packages |
---|
31 | that we will need a bit later: |
---|
32 | |
---|
33 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
34 | $ sudo apt-get install rrdtool mrtg librrds-perl librrdp-perl librrd-dev \ |
---|
35 | libmailtools-perl php5 bison flex |
---|
36 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
37 | |
---|
38 | If prompted to "Make /etc/mrtg.cfg owned by and readable only by root?" select |
---|
39 | "<Yes>" and press ENTER to continue. |
---|
40 | |
---|
41 | ### Building and installing nfdump |
---|
42 | |
---|
43 | We are still missing some tools: |
---|
44 | |
---|
45 | nfcapd, nfdump, nfreplay, nfexpire, nftest, nfgen |
---|
46 | |
---|
47 | There is a package in Ubuntu, but it's too old - so we've built a newer one |
---|
48 | which is ready to download from the NOC: |
---|
49 | |
---|
50 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
51 | cd /tmp/ |
---|
52 | wget http://noc.ws.nsrc.org/downloads/nfdump_1.6.6-1_i386.deb |
---|
53 | wget http://noc.ws.nsrc.org/downloads/nfdump-flow-tools_1.6.6-1_i386.deb |
---|
54 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
55 | |
---|
56 | Installation: |
---|
57 | |
---|
58 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
59 | sudo dpkg --install nfdump_1.6.6-1_i386.deb |
---|
60 | sudo dpkg --install nfdump-flow-tools_1.6.6-1_i386.deb |
---|
61 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
62 | |
---|
63 | |
---|
64 | ### Testing nfcapd and nfdump |
---|
65 | |
---|
66 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
67 | mkdir /tmp/nfcap-test |
---|
68 | nfcapd -E -p 9001 -l /tmp/nfcap-test |
---|
69 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
70 | |
---|
71 | ... after a while, a series of flows should be dumped on your screen. |
---|
72 | |
---|
73 | Stop the tool with CTRL+C, then look at the contents of /tmp/nfcap-test |
---|
74 | |
---|
75 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
76 | $ ls -l /tmp/nfcap-test |
---|
77 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
78 | |
---|
79 | You should see one or more files called nfcapd.2013xxyyzz |
---|
80 | |
---|
81 | Process the file(s) with nfdump: |
---|
82 | |
---|
83 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
84 | nfdump -r nfcapd.2013xxyyzz | less |
---|
85 | nfdump -r nfcapd.2013xxyyzz -s srcip/bytes |
---|
86 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
87 | |
---|
88 | You should get some useful information :) |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | ## Installing and setting up NfSen |
---|
93 | |
---|
94 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
95 | cd /usr/local/src |
---|
96 | sudo wget http://noc.ws.nsrc.org/downloads/nfsen-1.3.6p1.tar.gz |
---|
97 | sudo tar xvzf nfsen-1.3.6p1.tar.gz |
---|
98 | cd nfsen-1.3.6p1 |
---|
99 | sudo wget http://noc.ws.nsrc.org/downloads/nfsen-socket6.patch |
---|
100 | sudo patch -p0 < nfsen-socket6.patch |
---|
101 | cd etc |
---|
102 | sudo cp nfsen-dist.conf nfsen.conf |
---|
103 | sudo editor nfsen.conf |
---|
104 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
105 | |
---|
106 | Set the $BASEDIR variable |
---|
107 | |
---|
108 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
109 | $BASEDIR="/var/nfsen"; |
---|
110 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
111 | |
---|
112 | Adjust the tools path to where items actually reside: |
---|
113 | |
---|
114 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
115 | # nfdump tools path |
---|
116 | $PREFIX = '/usr/bin'; |
---|
117 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
118 | |
---|
119 | Set the users appropriately so that Apache can access files: |
---|
120 | |
---|
121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
122 | $WWWUSER = 'www-data'; |
---|
123 | $WWWGROUP = 'www-data'; |
---|
124 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
125 | |
---|
126 | Set the buffer size to something small, so that we see data quickly |
---|
127 | |
---|
128 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
129 | # Receive buffer size for nfcapd - see man page nfcapd(1) |
---|
130 | $BUFFLEN = 2000; |
---|
131 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
132 | |
---|
133 | Find the %sources definition, and change it to: |
---|
134 | |
---|
135 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
136 | %sources=( |
---|
137 | 'rtr1' => {'port'=>'9001','col'=>'#0000ff','type'=>'netflow'}, |
---|
138 | 'rtr2' => {'port'=>'9002','col'=>'#00ff00','type'=>'netflow'}, |
---|
139 | ); |
---|
140 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
141 | |
---|
142 | Now save and exit from the file. |
---|
143 | |
---|
144 | |
---|
145 | ## Create the netflow user on the system |
---|
146 | |
---|
147 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
148 | $ sudo useradd -d /var/netflow -G www-data -m -s /bin/false netflow |
---|
149 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
150 | |
---|
151 | |
---|
152 | ## Install NfSen and start it |
---|
153 | |
---|
154 | Make sure we are in the right location: |
---|
155 | |
---|
156 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
157 | $ cd /usr/local/src/nfsen-1.3.6p1 |
---|
158 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
159 | |
---|
160 | Now, finally, we install: |
---|
161 | |
---|
162 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
163 | $ sudo perl install.pl etc/nfsen.conf |
---|
164 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
165 | |
---|
166 | Press ENTER when prompted for the path to Perl. |
---|
167 | |
---|
168 | ## Install init script |
---|
169 | |
---|
170 | In order to have nfsen start and stop automatically when the system starts, |
---|
171 | add a link to the init.d diretory pointing to the nfsen startup script: |
---|
172 | |
---|
173 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
174 | sudo ln -s /var/nfsen/bin/nfsen /etc/init.d/nfsen |
---|
175 | update-rc.d nfsen defaults 20 |
---|
176 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
177 | |
---|
178 | Start NfSen |
---|
179 | |
---|
180 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
181 | sudo service nfsen start |
---|
182 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
183 | |
---|
184 | |
---|
185 | ## View flows via the web: |
---|
186 | |
---|
187 | You can find the nfsen page here: |
---|
188 | |
---|
189 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
190 | http://pcX.ws.nsrc.org/nfsen/nfsen.php |
---|
191 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
192 | |
---|
193 | You may see a message such as: |
---|
194 | |
---|
195 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
196 | Frontend - Backend version missmatch! |
---|
197 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
198 | |
---|
199 | This will go away if you reload the page, it's not a problem. |
---|
200 | |
---|
201 | Done! Move on to the third lab, exercise3-NfSen-PortTracker |
---|
202 | |
---|
203 | * NOTES: |
---|
204 | |
---|
205 | ## Adding sources |
---|
206 | |
---|
207 | To add new sources to nfsen, the way to proceed is as follows: |
---|
208 | |
---|
209 | - edit /var/nfsen/etc/nfsen.conf, and add the source, for example: |
---|
210 | |
---|
211 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
212 | %sources = ( |
---|
213 | 'rtrX' => { 'port' => '900X', 'col' => '#0000ff', 'type' => 'netflow' }, |
---|
214 | 'rtrY' => { 'port' => '900Y', 'col' => '#00ff00', 'type' => 'netflow' }, |
---|
215 | 'rtr10' => { 'port' => '9010', 'col' => '#ff0000', 'type' => 'netflow' }, # <- new |
---|
216 | ); |
---|
217 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
218 | |
---|
219 | - Reconfigure NfSen. |
---|
220 | |
---|
221 | You will need to run this every time you modify /var/nfsen/etc/nfsen.conf: |
---|
222 | |
---|
223 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
224 | $ sudo /etc/init.d/nfsen reconfig |
---|
225 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
226 | |
---|
227 | You should see: |
---|
228 | |
---|
229 | New sources to configure : rtr10 |
---|
230 | Continue? [y/n] y |
---|
231 | |
---|
232 | Add source 'rtr10' |
---|
233 | |
---|
234 | Reconfig done! |
---|