安裝 ipaudit (ipaudit under CentOS 5)
在 switch 上應用 port mirror 將出去的網路埠A 的流量 mirror 一份到網路埠 B ,並將 CentOS 的 eth0 接到 switch 上的網路埠 B ,並以 eth0 來作流量監控。
先前準備:
# yum install libpcap perl-HTML-Parser perl-HTML-Tagset perl-TimeDate gnuplot
以下文字引用自 http://140.111.74.38/blog/post/2/629 (webcache):
IPAudit 是一套以 GPL 授權釋出的網路監控軟體,可以觀看每 30 分鐘、每天、每周、每月的即時報告。
如果安裝在內部使用者對外的連線 NAT Server 上,可以得到詳盡的連線內容。
IPAudit 官方網站:http://ipaudit.sourceforge.net/
1. 在 CentOS 下安裝 IPAudit
# rpm -qa | grep libpcap
libpcap-devel-0.9.4-14.el5
libpcap-0.9.4-14.el5
# yum search perl-HTML
perl-HTML-Parser.i386 : 讓 Perl 解析 HTML 的模組
perl-HTML-Tagset.noarch : HTML::Tagset - 用於解析 HTML 的有用資料表格
# yum search perl-Time
perl-TimeDate.noarch : 處理時間和日期的 Perl 模組
# yum search gnuplot
gnuplot.i386 : 用於繪製數學算式與資料的程式。
安裝套件
# yum install perl-HTML-Parser perl-HTML-Tagset perl-TimeDate gnuplot
2. 進行安裝
增加 ipaudit 使用者
# useradd ipaudit
切換使用者
# su -l ipaudit
下載
$ wget http://prdownloads.sourceforge.net/ipaudit/ipaudit-web-1.0BETA9.tar.gz?download
$ wget http://prdownloads.sourceforge.net/ipaudit/ipaudit-1.0BETA2.tar.gz?download
解壓縮
$ tar xvzf ipaudit-web-1.0BETA9.tar.gz
切換目錄
$ cd ipaudit-web-1.0BETA9/compile/
開始編譯
$ ./configure
$ make
切換使用者成 root
$ su -
# cd /home/ipaudit/ipaudit-web-1.0BETA9/compile/
# make install
# make install-cron
退出 root
# exit
3. 檢查工作排程
# su - ipaudit
以 ipaudit 的身份檢查工作排程
$ crontab -l
0,30 * * * * cron/cron30min
15 0 * * * cron/crondaily
15 1 * * * cron/cronclean
45 1 * * 0 cron/cronweekly
45 2 1 * * cron/cronmonthly
4. 修改設定檔
修改設定檔
$ vim /home/ipaudit/ipaudit-web.conf
把
LOCALRANGE=127.0.0
修改成要偵測的網段,如果有不同的網段,可以用 : 隔開
LOCALRANGE=192.168.1.0/24
INTERFACE=eth0
改成要偵測的網路介面,如果有不同的介面,可以用 : 隔開
INTERFACE=eth1
5. 修改網頁設定
切換使用者成為 root
$ su -
修改 Web Server 設定檔
# vim /etc/httpd/conf/httpd.conf
把
UserDir disable
修改成
UserDir public_html
加入下面這二段
<Directory /home/*/public_html/>
AllowOverride All
Options MultiViews Indexes Includes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
<Directory /home/*/public_html/cgi-bin>
Options +ExecCGI -Includes -Indexes
SetHandler cgi-script
</Directory>
重新啟動 Web Server
# service httpd restart
我是把 httpd.conf 改:
UserDir enabled ipaudit
UserDir public_html
#以限制只存取 ipaudit 的網頁,其他 user 的網頁不可開。
<Directory /home/ipaudit/public_html>
AllowOverride All
Options MultiViews Indexes Includes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
<Directory /home/ipaudit/public_html/cgi-bin>
Options +ExecCGI -Includes -Indexes
SetHandler cgi-script
</Directory>
#以上將官方講的 /home/* 號改為 /home/ipaudit 這個 USER 名稱。
本機參考文件:
/home/ipaudit/ipaudit-web-1.0BETA9/INSTALL
此次安裝在 CentOS 5 ,64位元機器上,所以有些顯示有問題,參考以下方法修改:
打開檔案:
vi /home/ipaudit/reports/30min/0traffic/MakeReport30
將:
$mask = 0; ($mask = ~0 >> $2) unless($2 > 31);
改成:
$mask = 2**(32-$2) - 1;
存檔。
在 cgi-bin 目錄上加上簡單密碼:
vi /home/ipaudit/public_html/cgi-bin/.htaccess
AuthType Basic
AuthName IPAUDIT
AuthUserFile /home/httpd/passwd
require user myself friend boss
This tells Apache to only let users 'myself', 'myfriend' and 'myboss' to
run the ipaudit-report scripts.
以 root 創建 /home/httpd 目錄,並 chown ipaudit:ipaudit /home/httpd/
以 ipaudit 身份登入:
# su -l ipaudit
//於 /home/httpd/ 目錄中,鍵入下列指令
htpasswd -c passwd myself
htpasswd passwd friend
htpasswd passwd boss
# exit
以 root 權限:
# chmod 644 /home/httpd/passwd
# chmod 644 /home/ipaudit/public_html/cgi-bin/.htaccess
# service httpd restart
參考: