Netflow和nfsen安裝過程

來源:互聯網
上載者:User
文章目錄
  • NfDump
Introduction

Netflow provides nearly real time traffic monitoring, smart flow filtration, aggregation and statistic evaluation, using source/destination IP addresses, protocols, etc. Web interface provides easy configuration of all components including Netflow collectors,
devices, units etc. The Netflow analyzer should be able to deal with suspicious network activities (security attacks, routing troubles etc).

Nfsen with nfdump are one of the tools to monitor flows from cisco routers. In this document, I have tried to approach the basic layout of nfsen installation. For more information regarding the installation of nfsen and nfdump, please visit the mailing list
of nfsen in sourceforge.net

Dependencies and InstallationApache, PHP and Perl

These three applications are usually installed by default. If they are not installed, then you can always install it using Yast (open Suse) or using apt-get (Debian or ubuntu). To install from Yast, go to Yast (need to be root user) – Software Management
and click on Search. Might be you have to Search each application to install. For more information visit

  • Apache: http://httpd.apache.org/
  • Php: http://www.php.net/
  • Perl: http://www.perl.org/
RRDTOOL

For more information on installing RRDTOOL, visit
http://oss.oetiker.ch/rrdtool/

Dependencies for RRDTOOLzlib

Download from
http://oss.oetiker.ch/rrdtool/pub/libs/zlib-LATESTVERSION.tar.gz More information onhttp://www.zlib.net/

libpng

Download from
http://oss.oetiker.ch/rrdtool/pub/libs/libpng-LATESTVERSION.tar.gz More information onhttp://www.libpng.org/pub/png/libpng.html

Cairo

Download from
http://oss.oetiker.ch/rrdtool/pub/libs/cairo-LATESTVERSION.tar.gz More information onhttp://www.cairographics.org/

Glib

Download from
http://oss.oetiker.ch/rrdtool/pub/libs/glib-LATESTVERSION.tar.gz More information onhttp://www.gtk.org/

Pango

Download from
http://oss.oetiker.ch/rrdtool/pub/libs/pango- LATESTVERSION.tar.gz More information onhttp://www.pango.org/

Installation

Download from: (download from
http://oss.oetiker.ch/rrdtool/pub/libs/rrdtool-LATESTVERSION.tar.gz )

  • $ tar zxvf rrdtool-LATESTVERSION.tar.gz
  • $ ./configure –prefix=/usr/local/rrdtool –disable-tcl
  • $ make
  • make install

If there is error, then its much likely going to be the dependencies which are not installed. Try to fix out the dependency which is/are not installed and try installing again. Some of the dependencies can be installed using YaST, but its always good to
install from a tar file, as you will be getting the latest version and good documentation about the dependencies.

NfDumpDownload Site

Download NfDump from
http://voxel.dl.sourceforge.net/sourceforge/nfdump/nfdump-1.5.7.tar.gz. Also download flow-tools fromftp://ftp.eng.oar.net/pub/flow-tools/flow-tools-0.68.tar.gz as
it is necessary while compiling NfDump.

Compiling flow-tools

Download from
ftp://ftp.eng.oar.net/pub/flow-tools/flow-tools-0.68.tar.gz. Make sure you have tcp_wrappers (ftp://ftp.porcupine.org/pub/security/tcp_wrappers_7.6.tar.gz) installed
in your system before compiling.

$ tar flow-tools-0.68.tar.gz $ ./configure $ make

Configure options

--prefix=/usr/local/nfdump

The directory where nfdump is going to be installed. If not given, the default will be installed in /usr/local.

--enable-nfprofile

Nfprofile is used by nfsen (frontend). By default it is not installed, so we have to enable it.

--with-rrdpath=Link

link to the rrdpath normally to the directory where rrd.h resides. Normally it is on include folder of RRDPATH. If you have gone through the installation technique as mentioned above, then the Link would be /usr/local/rrdtool/include

--with-ftpath=source

We need the flow-tool library for nfdump. The flow-tool source is the directory of the flow-tool source after it is compiled.

Installation

Download nfdump from
http://voxel.dl.sourceforge.net/sourceforge/nfdump/nfdump-1.5.7.tar.gz
$ tar zxvf nfdump-1.5.7.tar.gz
$ ./configure –enable-nfprofile –with-rrdpath=/usr/local/rrdtool/include –with-ftpath=source path$ make
$ make install

Confirming files installed

After installation make sure you have following files installed in your directory. In directory (if you have given prefix during installation, then it would be in /usr/local/nfdump/bin else it will be in /usr/local/bin) Nfdump, nfcapd, nfexpire, nfprofile
nftrack. There would be other files too, but the above files are the basic files which you will need.

Running nfcapd and nfdump

Before running nfdump commands, you must make sure that your router is sending the flows to your computer or not. To configure router go to section 4. I configured router to send flows on my system on port 9991 but it might be different for you based on
the configuration of the router.

Nfcapd

Nfcapd can be run from any user; it just depends upon the output directory. Make sure the output directory can be written by the user from whom you are running Nfcapd. I have my output directory on /var/netflow/data

$ nfcapd –z –W –t5 –p 9991 –l /var/netflow/data

Where -z => compress the files of the flows collected -W => creates new file each time after –t min -t => time interval -p => port number from where the flows is collected (for me its 9991) -l => the output directory where the file is to be written

There will be more options available. Just do

  • $ nfcapd --help for more options
Tcpdump

If you are not sure you are getting the flows on port 9991 or not, use tcpdump to check it. (root user)

  • tcpdump –v udp port 9991

POINT TO REMEMBER: the flows collected from router will be UDP packets.

NfDump

To view the captured data from nfcapd, use

  • $ nfdump –r /var/netflow/data/nfcapd.(timeslot)

For more information about the options to use with nfdump you can visit

  1. http://nfdump.sourceforge.net/ page, or you can use
  2. $ nfdump --help command.
Router

You have to configure the Cisco router to export the flows before running the nfdump. There would be several documentations available for different Cisco models, so I have tried to explain the basic technique involved to configure router to export flows.
Refer to Cisco router model description for more details.

To enable netflow in router
  • interface fastethernet 0/0
  • ip route-cache flow
Send netflow data
  • ip flow-export

    <ip-address>
    <udp-port>
  • ip flow-export version 5
  • ip flow-cache timeout active 5

Generally the timeout is given anytime between 1 and 60. But make sure that the timeout given in router is equal or less than the timeout provided in nfcapd. Usually by default both timeouts are 5 minutes.

Extra configuration for busy routers

If you feel your router is handling loads of data and is relatively busy, then you can add following configuration line in your router

  • mls aging fast time 4 threshold 2
  • mls aging normal 32
  • mls aging long 900
NfSen

NfSen is the frontend tool to visualize the flows collected using nfdump.

Download Site

Download from
http://internap.dl.sourceforge.net/sourceforge/nfsen/nfsen-1.3.tar.gz Usually the snapshot is also available for nfsen, but it is always good way to go out with stable version.

Creating user and having apache permission

A new user and group is created to allow the external commands run from the web interface. You have to be root user to run following commands

  • /usr/sbin/useradd -m nfsen
  • passwd nfsen
  • /usr/sbin/groupadd nfsen
  • /usr/sbin/usermod -G nfsen nfsen

Create a new group and adding it to apache user group.

  • /usr/sbin/groupadd nfsenadmin
  • /usr/sbin/usermod -a -G nfsenadmin nfsen (adding user nfsen to nfsenadmin user)
  • /usr/sbin/usermod -a -G nfsenadmin wwwrun (adding nfsenadmin to apache user group)
Creating HTML DIR

Before we install nfsen, we need to create HTML dir. The dir path should be same with the path given in nfsen.conf file.

  • mkdir –p /usr/local/nfsen/www/htdocs/nfsen

Change the permission to nfsen:nagcmd so that you wont have to suffer permission issue later.

  • chown –R nfsen:nagcmd /usr/local/nfsen
Configuration

Basically when you are installing nfsen, you have to configure the nfsen.conf file located inside etc directory of nfsen source.

  • $ tar nfsen-1.3.tar.gz
  • $ cd nfsen-1.3/etc

Edit nfsen.conf as follows: (Leave other options as it is)

  • $BASEDIR=”/usr/local/nfsen”
  • $HTMLDIR=”${BASEDIR}/www/htdocs/nfsen”
  • $PREFIX=”$/usr/local/bin” (nfdump path Or can be /usr/local/nfdump/bin depending upon your installtion)
  • $USER=”nfsen”

    Make sure you create a user called nfsen and assigned the wwwgroup permission to it. Creating the user and assigning permission is explained in section 3.5.3.

  • $WWWUSER=”nfsen”
  • $WWWGROUP=”nagcmd”
  • $SUBDIRLAYOUT=0 (if your router is very busy, otherwise 2 will give you lot of options to view the file)
  • %sources = (

‘RouterName’ => { ‘port’ => ‘9991’, ‘col’ => ‘#0000ff’, ‘type’ =>’netflow’ }, ) ; If you want to add more routers, then you can add more lines as above. For my configuration I used two routers, so my configuration was

%sources = (

‘Router1’ => { ‘port’ => ‘9991’, ‘col’ => ‘#0000ff’, ‘type’ =>’netflow’ }, Router2’ => { ‘port’ => ‘9992’, ‘col’ => ‘#0000ff’, ‘type’ =>’netflow’ }, ) ;

After editing above options run

./ install.pl etc/nfsen.conf

And the nfsen will be installed on the system.

Running nfsen

After installing nfsen, to start nfsen, issue following command

/usr/local/nfsen/bin/nfsen start

If you have changed anything on the nfsen.conf file after it has been installed always run

/usr/local/nfsen/bin/nfsen reload

Always checkout nfsen errors in syslog file.

Configuring Web interface

For this section you need to be root user. Create a file nfsen.conf in directory /etc/apache2/conf.d (path of Apache’s conf.d). Add following lines in that file # vi /etc/apache2/conf.d/nfsen.conf

  • lias /nfsen “/usr/local/nfsen/www/htdocs/nfsen”

<Directory “/usr/local/nfsen/www/htdocs/nfsen”>

Options None Order allow,deny AllowOverride None

Unknown end tag for </directory>

Save the file and exit. Restart the webserver after that using command # service apache2 restart OR #/etc/init.d/apache2 restart

Correction on some files

While running nfsen from web interface for the first time, if you see the Message

“ERROR: No value for 'statvisible'!"

Then you have to correct some lines in file details.php in lines 308 and 312

Line 308 - if ( isset($COOKIE'statpref') ) { + if ( isset($COOKIE'statpref') && $COOKIE'statpref' != '' ) {

$POST'statpref' = $COOKIE'statpref';

}

Line 312

- if ( isset($COOKIE'statvisible') ) { + if ( isset($COOKIE'statvisible') && $COOKIE'statvisible' != '' ) {

$POST'statvisible' = $COOKIE'statvisible';

}

This error is due to some part of the code which was developed in php4 and is not compatible with php5.

Integration of Existing Data

If you have existing netflow data, it can be added to the new nfsen installation by following steps 1. go to the profile directory (normally it is $NFSEN/profiles-data/live) 2. copy all the existing data to the folder or make sym link to the existing data
3. use command: a./usr/local/nfsen/bin/nfsen –r live 4. The live profile is now setup with the existing data. You can always check it using a./usr/local/nfsen/bin/nfsen –l live

Changing Hierarchy

If you check out nfsen.conf file you can find, $SUBDIRLAYOUT, which is used to change the hierarchy level of the files stored. If you want to change the way the file is stored in your system, you can change the number of this layout. The number corresponding
to the hierarchy level is defined in nfsen.conf.

After changing the layout number, just run the command

/usr/local/nfsen/bin/RebuildHierarchy.pl

This command will change all your files into preferred layout.

Comment by
apt.hous...@gmail.com, Oct 4, 2009

Is there a package available for the same?

Comment by
jamie.ma...@gmail.com, Dec 12, 2009

Where it says:

"chown –R nfsen:nagcmd /usr/local/nfsen"

and

"$WWWGROUP=”nagcmd"

Should this be "nfsenadmin" instead of "nagcmd"?

Comment by
peterd...@gmail.com, Jan 24, 2011

The nagcmd I noticed was a group created for nagios in another how to guide.

I am confused with this:

should lias be alias and what is unknown end tag for?

Configuring Web interface¶

For this section you need to be root user. Create a file nfsen.conf in directory /etc/apache2/conf.d (path of Apache’s conf.d). Add following lines in that file # vi /etc/apache2/conf.d/nfsen.conf

  • lias /nfsen “/usr/local/nfsen/www/htdocs/nfsen”

<Directory “/usr/local/nfsen/www/htdocs/nfsen”>

Options None Order allow,deny AllowOverride? None

Unknown end tag for </directory>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.