Use FreeRADIUS to control VPN traffic

Source: Internet
Author: User
Tags vps freeradius

Since the beginning of vps, I have been asking for my vpn account. However, the traffic of your own vps is limited after all. If you send a friend's account, you must pay attention to the traffic usage, especially the usage of each user and website. In this case, you must first install and configure FreeRADIUS to monitor and limit the vpn traffic. For the method, see FreeRADIUS + MySQL installation and configuration notes. Then, perform the following operations.

1. Enable Rlm sqlcounter Module
Find "counter. conf" (row 695) and remove #

1
Vim/usr/local/etc/raddb/radiusd. conf

2. Add a Traffic Counter
Some online tutorials have spelling errors, and they have been tossing for most of the time to find the cause in the official documentation.

1
Vim/usr/local/etc/raddb/SQL/mysql/counter. conf

Add the following code at the end of the file
Sqlcounter monthlytrafficcounter {
Counter-name = Monthly-Traffic
Check-name = Max-Monthly-Traffic
Reply-name = Monthly-Traffic-LIMIT
Sqlmod-inst = SQL
KEY = User-Name
Reset = monthly
Query = "select sum (acctinputoctets + acctoutputoctets) FROM radacct WHERE UserName = '% {% k}' AND UNIX_TIMESTAMP (AcctStartTime)> '% B '"
}

The code above indicates monthly statistics. In the radacct table of the database, all inbound and outbound traffic is accumulated Based on the username (% k.

Time can also be customized (months, weeks, days, hours), you can also specify a specific value, such as reset once three days "reset = 3 d"

3. Enable Traffic Counter Traffic counters
1
Vim/usr/local/etc/raddb/sites-enabled/default

Add at the end of the authorize block (row 205)

1
Monthlytrafficcounter

4. Add dictionary files
1
Vim/usr/local/etc/raddb/dictionary

Add the following two lines at the end of the file
 
ATTRIBUTE Max-Monthly-Traffic 3003 integer
ATTRIBUTE Monthly-Traffic-Limit 3004 integer

V. Database insertion traffic limit value
Note:

1) insert it to the radgroupreply table to limit the traffic of a user group. You can also insert data to the radcheck table to limit the traffic of a user.
2) The traffic value is measured in byte, 1G = 1073741824 bytes.
3) VIP1 is the user group and 123456 is the Database root Password.

# Connect to the MySQL database
 
Mysql-uroot-p123456;

# Maximum monthly traffic (1 GB)

 
Insert into radgroupreply (groupname, attribute, op, VALUE) VALUES ('vip1', 'max-Monthly-Traffic ',': = ', '123 ');

# Interval of traffic statistics (60 seconds)
 
Insert into radgroupreply (groupname, attribute, op, VALUE) VALUES ('vip1', 'acct-Interim-Interval ',': = ', '60 ');

Citation address: https://wangyan.org/blog/freeradius-traffic-limit.html
Reference: http://wiki.freeradius.org/Rlm_sqlcounter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.