特殊:Badtitle/NS100:HowToMonitorInternetTrafficTotals
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/HowToMonitorInternetTrafficTotals }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/af | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Afrikaans| [[::HowToMonitorInternetTrafficTotals/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ar | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|العربية| [[::HowToMonitorInternetTrafficTotals/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/az | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|azərbaycanca| [[::HowToMonitorInternetTrafficTotals/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/bcc | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|جهلسری بلوچی| [[::HowToMonitorInternetTrafficTotals/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/bg | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|български| [[::HowToMonitorInternetTrafficTotals/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/br | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|brezhoneg| [[::HowToMonitorInternetTrafficTotals/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ca | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|català| [[::HowToMonitorInternetTrafficTotals/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/cs | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|čeština| [[::HowToMonitorInternetTrafficTotals/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/de | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Deutsch| [[::HowToMonitorInternetTrafficTotals/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/el | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Ελληνικά| [[::HowToMonitorInternetTrafficTotals/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/es | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|español| [[::HowToMonitorInternetTrafficTotals/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/fa | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|فارسی| [[::HowToMonitorInternetTrafficTotals/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/fi | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|suomi| [[::HowToMonitorInternetTrafficTotals/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/fr | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|français| [[::HowToMonitorInternetTrafficTotals/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/gu | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|ગુજરાતી| [[::HowToMonitorInternetTrafficTotals/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/he | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|עברית| [[::HowToMonitorInternetTrafficTotals/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/hu | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|magyar| [[::HowToMonitorInternetTrafficTotals/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/id | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Bahasa Indonesia| [[::HowToMonitorInternetTrafficTotals/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/it | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|italiano| [[::HowToMonitorInternetTrafficTotals/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ja | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|日本語| [[::HowToMonitorInternetTrafficTotals/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ko | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|한국어| [[::HowToMonitorInternetTrafficTotals/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ksh | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Ripoarisch| [[::HowToMonitorInternetTrafficTotals/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/mr | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|मराठी| [[::HowToMonitorInternetTrafficTotals/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ms | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Bahasa Melayu| [[::HowToMonitorInternetTrafficTotals/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/nl | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Nederlands| [[::HowToMonitorInternetTrafficTotals/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/no | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|norsk| [[::HowToMonitorInternetTrafficTotals/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/oc | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|occitan| [[::HowToMonitorInternetTrafficTotals/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/pl | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|polski| [[::HowToMonitorInternetTrafficTotals/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/pt | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|português| [[::HowToMonitorInternetTrafficTotals/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ro | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|română| [[::HowToMonitorInternetTrafficTotals/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/ru | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|русский| [[::HowToMonitorInternetTrafficTotals/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/si | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|සිංහල| [[::HowToMonitorInternetTrafficTotals/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/sq | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|shqip| [[::HowToMonitorInternetTrafficTotals/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/sr | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|српски / srpski| [[::HowToMonitorInternetTrafficTotals/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/sv | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|svenska| [[::HowToMonitorInternetTrafficTotals/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/th | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|ไทย| [[::HowToMonitorInternetTrafficTotals/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/tr | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Türkçe| [[::HowToMonitorInternetTrafficTotals/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/vi | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|Tiếng Việt| [[::HowToMonitorInternetTrafficTotals/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/yue | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|粵語| [[::HowToMonitorInternetTrafficTotals/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/zh | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|中文| [[::HowToMonitorInternetTrafficTotals/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/zh-hans | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|中文(简体)| [[::HowToMonitorInternetTrafficTotals/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals | UbuntuHelp:HowToMonitorInternetTrafficTotals | {{#if: | :}}HowToMonitorInternetTrafficTotals}}/zh-hant | • {{#if: UbuntuHelp:HowToMonitorInternetTrafficTotals|中文(繁體)| [[::HowToMonitorInternetTrafficTotals/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:HowToMonitorInternetTrafficTotals|:HowToMonitorInternetTrafficTotals|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :HowToMonitorInternetTrafficTotals/zh | | {{#ifexist: HowToMonitorInternetTrafficTotals/zh | | {{#ifeq: {{#titleparts:HowToMonitorInternetTrafficTotals|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:HowToMonitorInternetTrafficTotals|1|-1|}} | zh | | }}
Parent page: Internet and Networking
ipac-ng
Aimed at people with a small home network, who want to monitor the amount uploaded / download from the internet but not the local traffic on the LAN. This might be useful if your ISP sets monthly bandwidth limits, and you also transfer files across your local network. The instructions guide you through setting up IPAC-NG, an iptables/ipchains based IP accounting package.
Installation
You will need access to the Universe repository - see AddingRepositoriesHowto if you need more information. First install ipac-ng, either with Synaptic (SynapticHowto)or type in a terminal:
sudo aptitude install ipac-ng
Configuration
Edit /etc/ipac-ng/rules.conf to tell it the type of traffic you want to log. To simply measure upload and download totals, it should read:
# /etc/ipac-ng/rules.conf total upload |ipac~i|eth0|all|| total download |ipac~o|eth0|all||
Note: replace eth0 with the network adapter you wish to measure. Edit /etc/ipac-ng/ipac.conf and change the storage method to gdbm, otherwise the logs will take up a very large amount of space. (postgre could probably be used too)
# /etc/ipac-ng/ipac.conf storage = gdbm
To ignore LAN traffic, some simple iptables rules are added to the startup scripts. Edit /etc/init.d/ipac-ng and add the four lines between the ##'s as follows:
case "$1" in start) echo -n "Starting $DESC: " check $DAEMON -S $IPTABLES -I INPUT -s aaa.bbb.ccc.0/24 -j ACCEPT $IPTABLES -I OUTPUT -d aaa.bbb.ccc.0/24 -j ACCEPT echo "$NAME." ;; stop) echo -n "Stopping $DESC: " # fetch accounting before removing the rules $DAEMON echo -n "flushing IP accounting rules ..." $IPTABLES --flush ipac~o $IPTABLES --flush ipac~i $IPTABLES --flush ipac~fi $IPTABLES --flush ipac~fo # here should the ipac_* rule be removed from INPUT OUTPUT and FORWARD but --flush is # evil because it would remove all rules in these chains. $IPTABLES -D INPUT -s aaa.bbb.ccc.0/24 -j ACCEPT $IPTABLES -D OUTPUT -d aaa.bbb.ccc.0/24 -j ACCEPT echo "$NAME stopped." ;;
Note: replace aaa.bbb.ccc.0 with your local network. For example, if your router is at 192.168.0.1, you would use 192.168.0.0. That's it! The traffic totals will be automatically fetched from iptables every 10 minutes when your computer is running. To view the totals, use 'ipacsum'. It can be configured to display a specific time interval, and will even draw graphs of the traffic.
Links
vnstat
vnstat is another app that can be used to monitor bandwidth usage. It is a little simpler and easier to use then the ipac-ng package. One of the benefits of vnstat is it's not a running daemon so it takes up no memory. The process is created via a cron job which is run every 5 minutes.
Install
The vnstat package is very easy to install from the repositories with no dependencies.
sudo apt-get install vnstat
Setup
vnstat is meant to be used by any user so it needs to be set up that way first by giving correct permission. The following gives any user permission to use this feature. If desired you can set up a group so only users in the group can use this.
sudo chmod o+x /usr/bin/vnstat
sudo chmod o+wx /var/lib/vnstat/
Now vnstat should be ready to run
Usage
To create the cron job simply run this command
vnstat -u -i ath0
Replace ath0 with the interface you want to monitor This creates a file in /var/lib/vnstat/ that collects the data for that interface. A cron job will run every 5 minutes to update the data. Below is a sample output with no options.
Database updated: Thu Jan 12 22:20:01 2006 ath0 received: 0.11 MB (nan%) transmitted: 0.01 MB (nan%) total: 0.12 MB rx | tx | total -----------------------+------------+----------- today 0.11 MB | 0.01 MB | 0.12 MB -----------------------+------------+----------- estimated 0 MB | 0 MB | 0 MB
You can read more about options you can use to modify the output in the man page of vnstat.