Changes between Version 1 and Version 2 of NspwUprouse/Agenda/netflow


Ignore:
Timestamp:
Sep 12, 2021, 9:10:43 PM (3 years ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NspwUprouse/Agenda/netflow

    v1 v2  
    88{{{
    99$ sudo apt-get install build-essential autoconf
    10 $ sudo apt-get install rrdtool mrtg librrds-perl librrdp-perl librrd-dev \
    11        libmailtools-perl bison flex
     10$ sudo apt-get install rrdtool mrtg librrds-perl librrdp-perl librrd-dev libmailtools-perl bison flex libbz2-dev libclang-dev
    1211}}}
    1312
     
    1615Now proceed to download and build. Note that only the last step (make install) has to be done as root.
    1716{{{
    18 $ cd
    19 $ wget http://192.248.4.49/NetMon/nfdump-1.6.13.tar.gz
    20 $ tar xvzf nfdump-1.6.13.tar.gz
    21 $ cd nfdump-1.6.13
    22 $ ./configure --help      # optional, shows the build settings available
     17$ cd ~
     18$ git clone https://github.com/phaag/nfdump.git
     19$ cd nfdump
     20$ ./autogen.sh
    2321$ ./configure --enable-nfprofile --enable-nftrack --enable-sflow
    2422$ make
    2523$ sudo make install
     24$ sudo ldconfig
    2625}}}
    2726
    2827== Router Configuration ==
    2928
    30 '''Note: This part is already done for you.'''
     29
    3130
    3231=== Cisco Router ===
     
    127126Process the file(s) with nfdump:
    128127{{{
    129 nfdump -r /tmp/nfcap-test/nfcapd.201Ywwxxyyzz | less
    130 nfdump -r /tmp/nfcap-test/nfcapd.201Ywwxxyyzz -s srcip/bytes
     128nfdump -r /tmp/nfcap-test/nfcapd.202Ywwxxyyzz | less
     129nfdump -r /tmp/nfcap-test/nfcapd.202Ywwxxyyzz -s srcip/bytes
    131130}}}
    132131w,x,y,z indicate year, month, day and time.
     
    150149
    151150{{{
    152 nfdump -r /tmp/sfcap-test/nfcapd.201Ywwxxyyzz | less
    153 nfdump -r /tmp/sfcap-test/nfcapd.201Ywwxxyyzz -s srcip/bytes
     151nfdump -r /tmp/sfcap-test/nfcapd.202Ywwxxyyzz | less
     152nfdump -r /tmp/sfcap-test/nfcapd.202Ywwxxyyzz -s srcip/bytes
    154153}}}
    155154w,x,y,z indicate year, month, day and time.
    156155
     156== Set up folders and nfcapd ==
     157
     158Following commands are executed as root. You may use `sudo su` to become root.
     159
     160
     161Create folders per device.
     162{{{
     163mkdir -p /var/nfdump/profiles-data/live/source1/
     164mkdir -p /var/nfdump/profiles-data/live/source2/
     165}}}
     166In the above, a device has been named as a source.
     167
     168Provide access to the apache2 user:
     169
     170{{{
     171chown -R www-data:www-data /var/nfdump/profiles-data
     172}}}
     173
     174Assuming device source1 is a netflow device and device source2 is a sflow device, run the following to start the flow collectors.
     175
     176{{{
     177/usr/local/bin/nfcapd -w -D -p 9995 -u www-data -g www-data -B 200000 -S 1 -z -I source1 -l /var/nfdump/profiles-data/live/source1/
     178/usr/local/bin/sfcapd -w -D -p 9996 -u www-data -g www-data -B 200000 -S 1 -z -I source2 -l /var/nfdump/profiles-data/live/source2/
     179}}}
     180
     181You can check whether the services are running by observing `netstat -nlp` for open udp port numbers. If they are not working, tail the `/var/log/syslog` for possible errors.
     182
    157183== Installing and setting up NfSen ==
    158184
    159185Download and compile nfsen.
    160186{{{
    161 $ cd
    162 $ wget http://wget http://192.248.4.49/NetMon/nfsen-1.3.6p1.tar.gz
    163 $ tar xvzf nfsen-1.3.6p1.tar.gz
    164 $ cd nfsen-1.3.6p1
    165 $ perl -MCPAN -e 'install Socket6'
    166 Would you like to configure as much as possible automatically? [yes]
    167 What approach do you want? (Choose local::lib, sudo or manual)
    168 [local::lib]
    169 $ cd etc
    170 $ cp nfsen-dist.conf nfsen.conf
    171 $ vi nfsen.conf
    172 }}}
    173 
    174 Set the $BASEDIR variable
    175 {{{
    176 $BASEDIR = "/var/nfsen";
    177 }}}
    178 
    179 Set the users appropriately so that Apache can access files:
    180 {{{
    181 $WWWUSER = 'www-data';
    182 $WWWGROUP = 'www-data';
    183 }}}
    184 
    185 Set the buffer size to something small, so that we see data quickly. You would not do this on a production system.
    186 
    187 # Receive buffer size for nfcapd - see man page nfcapd(1)
    188 {{{
    189 $BUFFLEN = 2000;
    190 }}}
    191 
    192 Find the %sources definition, and change it to:
    193 
    194 '''For a netflow router'''
    195 {{{
    196 %sources=(
    197 'accessrtr' => {'port'=>'9001','col'=>'#0000ff','type'=>'netflow'},
    198  );               
    199 }}}
    200 
    201 '''For a sflow router'''
    202 {{{
    203 %sources=(
    204 'accessrtr' => {'port'=>'9001','col'=>'#0000ff','type'=>'sflow'},
    205  );               
    206 }}}
    207 
    208 (substitute your group's router for accessrtr, and either remove or comment out the existing sample sources).
    209 
    210 Change the HTMLDIR from /var/www/nfsen/ to /var/www/html/nfsen/
    211 {{{
    212 $HTMLDIR    = "/var/www/html/nfsen/";
    213 }}}
    214 Now save and exit from the file.
    215 
    216 The default rrd tool version for nfsen is 1.5 but the latest version 1.6 therefore a slight configuration is needed
    217 {{{
    218 cd
    219 vi nfsen-1.3.6p1/libexec/NfSenRRD.pm
    220 }}}
    221 
    222 Find the following line'
    223 {{{
    224 if ( $rrd_version >= 1.2 && $rrd_version < 1.5 )
    225 }}}
    226 
    227 change it to,
    228 {{{
    229 if ( $rrd_version >= 1.2 && $rrd_version < 1.6 )
    230 }}}
    231 
    232 Create the netflow user on the system
    233 {{{
    234 $ sudo useradd -d /var/nfsen -G www-data -m -s /bin/false netflow
    235 }}}
    236 
    237 Install NfSen and start it
    238 
    239 Change directory back to just inside the source directory:
    240 {{{
    241 $ cd
    242 $ cd nfsen-1.3.6p1
    243 }}}
    244 
    245 Now, finally, we install:
    246 {{{
    247 $ sudo perl install.pl etc/nfsen.conf
    248 }}}
    249 
    250 Press ENTER when prompted for the path to Perl.
    251 
    252 Install init script
    253 
    254 In order to have nfsen start and stop automatically when the system starts, add a link to the init.d directory pointing to the nfsen startup script:
    255 {{{
    256 $ sudo ln -s /var/nfsen/bin/nfsen /etc/init.d/nfsen
    257 $ sudo update-rc.d nfsen defaults 20
    258 }}}
    259 
    260 Start NfSen
    261 {{{
    262 $ sudo service nfsen start
    263 }}}
     187# run following commands as root
     188# install packages
     189apt install apache2 git nfdump pkg-config php7.4 php7.4-dev libapache2-mod-php7.4 rrdtool librrd-dev
     190# enable apache modules
     191a2enmod rewrite deflate headers expires
     192# install rrd library for php
     193pecl install rrd
     194# create rrd library mod entry for php
     195echo "extension=rrd.so" > /etc/php/7.4/mods-available/rrd.ini
     196# enable php mod
     197phpenmod rrd
     198# configure virtual host to read .htaccess files
     199vi /etc/apache2/apache2.conf # set AllowOverride All for /var/www
     200# restart apache web server
     201systemctl restart apache2
     202# install nfsen-ng
     203cd /var/www/html # or wherever
     204git clone https://github.com/mbolli/nfsen-ng
     205chown -R www-data:www-data .
     206chmod +x nfsen-ng/backend/cli.php
     207# next step: configuration
     208}}}
     209
     210Create the settings file for nfsen-ng
     211
     212{{{
     213cp /var/www/html/nfsen-ng/backend/settings/settings.php.dist /var/www/html/nfsen-ng/backend/settings/settings.php
     214}}}
     215
     216Edit the settings.php file and include the device names by '''editing''' the following lines.
     217
     218For the sources:
     219{{{
     220        'sources' => array(
     221            'source1', 'source2',
     222}}}
     223
     224For the nfdump:
     225{{{
     226    'nfdump' => array(
     227        'binary' => '/usr/bin/nfdump',
     228        'profiles-data' => '/var/nfdump/profiles-data',
     229        'profile' => 'live',
     230        'max-processes' => 1, // maximum number of concurrently running nfdump processes
     231    ),
     232}}}
     233
     234Next, import existing data:
     235{{{
     236/var/www/html/nfsen-ng/backend/cli.php  import
     237}}}
     238
     239Now we can start the nfsen-ng daemon:
     240{{{
     241/var/www/html/nfsen-ng/backend/cli.php  start
     242}}}
     243
    264244
    265245View flows via the web:
    266246
    267 You can find the nfsen page here:
    268 
    269 '''http://<your IP address>/nfsen/nfsen.php
    270 
    271 You may see a message such as:
    272 
    273 '''Frontend - Backend version mismatch!'''
    274 
    275 This will go away if you reload the page, it's not a problem.
    276 
    277 == Using NfSen to identify top talkers ==
    278 
    279 Now let's use NfSen to explore the traffic flows in the network, with the aim of finding out who was been downloading the most data. Look carefully at the output generated at each step - ask an instructor to explain if you don't understand what you see.
    280 
    281  - Navigate to the Detail page
    282 
    283  - Select the time window. to do that change from "Single Timeslot" to '''Time Window''. Once you have done this, the vertical selector arrow and line in the graph window can be split.
    284 
    285 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/netmon2017netflow/ns1.png)]]
    286 
    287  - Pull the left half of the arrow to the left and the right half to the right, to select the time period of interest. Then you should see some summary statistics appear in the table below the graph, for the time period you have selected
    288 
    289 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/netmon2017netflow/ns2.png)]]
    290 
    291  - List individual flows by Selecting "List Flows", make sure none of the "Aggregate" boxes are checked, and then click process. This will display some flows at the beginning of the time period. Click '''process'''. You will see the top flows below.
    292 
    293 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/netmon2017netflow/ns3.png)]]
    294 
    295  - By selecting "bi-directional" you can get NfSen to associate the inbound and outbound flows into a single line
    296 
    297  - If we know which host we want to examine, we can apply a filter to show only those flows to and from that host. Do this by entering "host x.x.x.x" in the filter box, and then pressing the process again. (Replace x.x.x.x with the address of one of the host PC)
    298 
    299 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/netmon2017netflow/ns4.png)]]
    300 
    301  - The next thing we can do is to get NfSen to sort the flows by a number of bytes. Remove any filter from the Filter box; select "Stat TopN", stat "Flow Records", order by "Bytes". Ensure all the aggregate boxes are unchecked, then press the process
    302 
    303 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/netmon2017netflow/ns5.png)]]
    304  
    305  - NFsen can show you inbound traffic grouped by receiver IP address. which means showing the total amount of traffic delivered to that host. To do this, Stat "DST IP Address", order by "bytes". Then apply a filter that shows only traffic to your group's network: "dst net 192.248.6.0/24". You can do the same with a single host.
    306 
    307 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/netmon2017netflow/ns6.png)]]
    308 
    309  - By clicking on an IP address, you will get some information from reverse DNS and whois.
     247You can find the nfsen-ng page here:
     248
     249'''http://<your IP address>/nfsen-ng/frontend/'''
     250
     251In case of server restart, you need to re-run,
     252
     253{{{
     254/usr/local/bin/nfcapd -w -D -p 9995 -u www-data -g www-data -B 200000 -S 1 -z -I source1 -l /var/nfdump/profiles-data/live/source1/
     255/usr/local/bin/sfcapd -w -D -p 9996 -u www-data -g www-data -B 200000 -S 1 -z -I source2 -l /var/nfdump/profiles-data/live/source2/
     256/var/www/html/nfsen-ng/backend/cli.php  start
     257}}}
     258
     259You may also automate that by keeping a bash script to run on every reboot via cron jobs.
     260
     261
     262== References: ===
     263
     2641. https://github.com/mbolli/nfsen-ng
     2652. https://github.com/phaag/nfdump
     2663. https://www.systutorials.com/docs/linux/man/1-nfcapd/
     267