<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>秋天的博客 &#187; 网络安全</title>
	<atom:link href="http://www.fallday.org/archives/category/network/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fallday.org</link>
	<description>虚拟主机/VPS/云计算实践</description>
	<lastBuildDate>Sat, 21 Jan 2012 03:21:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>FreeRadius异常在线用户的清除</title>
		<link>http://www.fallday.org/archives/721</link>
		<comments>http://www.fallday.org/archives/721#comments</comments>
		<pubDate>Tue, 29 Nov 2011 16:31:01 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[主机管理]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[FreeRadius]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=721</guid>
		<description><![CDATA[FreeRaidus在一些情况，用户的连接已经断开，但系统中用户还处于在线状态。如果用户再次从同一IP再次登录或者服务限制一个用户不能同时多处登录时就会连接认证失败。其次FreeRaidus真是一个不错的系统，可以自己写一段SQL来处理这个情况。SQL放在/etc/freeradius/sites-enable/default的authorize section即可。 if(User-Name) { if(“%{sql:UPDATE radacct set AcctStopTime=ADDDATE(AcctStartTime,INTERVAL AcctSessionTime SECOND),AcctTerminateCause=&#8217;Clear-Stale Session&#8217; WHERE UserName=&#8217;%{User-Name}&#8217; and CallingStationId=&#8217;%{Calling-Station-Id}&#8217; and AcctStopTime is null}”){ } } 如果不允许一个用户同时多处登录，去掉Calling-Station-Id的条件即可。 if(User-Name) { if(“%{sql:UPDATE radacct set AcctStopTime=ADDDATE(AcctStartTime,INTERVAL AcctSessionTime SECOND),AcctTerminateCause=&#8217;Clear-Stale Session&#8217; WHERE UserName=&#8217;%{User-Name}&#8217; and AcctStopTime is null}”){ } } 注意这里sql是有意放在一个空的if语句中，因为在freeradius的配置文件中，一般语句中的sql会要求有返回值。放在if条件中可以避免因为检查返回值失败。 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; 补记： 再想想这样做也还有些问题，因为只是在数据库中清除了状态，如果前一个连接物理上还存在的话，并不能物理上断开相应的连接。完美解决方案需要NAS能检查连接状态，如果NAS不提供相应功能的话，不能有完好解决方案。 折中的方案是通过Acct-Interim-Interval设置NAS更新数据周期，在检查无效连接时只处理一段时间(比如三个更新周期)没有更新数据的连接。一点问题是如果一个连接异常断开后，在一段时间内无法再次登陆。 if(User-Name) { if(“%{sql:UPDATE radacct set AcctStopTime=ADDDATE(AcctStartTime,INTERVAL AcctSessionTime SECOND),AcctTerminateCause=&#8217;Clear-Stale Session&#8217; WHERE UserName=&#8217;%{User-Name}&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>FreeRaidus在一些情况，用户的连接已经断开，但系统中用户还处于在线状态。如果用户再次从同一IP再次登录或者服务限制一个用户不能同时多处登录时就会连接认证失败。其次FreeRaidus真是一个不错的系统，可以自己写一段SQL来处理这个情况。SQL放在/etc/freeradius/sites-enable/default的authorize section即可。</p>
<p>if(User-Name) {<br />
if(“%{sql:UPDATE radacct set AcctStopTime=ADDDATE(AcctStartTime,INTERVAL AcctSessionTime SECOND),AcctTerminateCause=&#8217;Clear-Stale Session&#8217; WHERE UserName=&#8217;%{User-Name}&#8217; and CallingStationId=&#8217;%{Calling-Station-Id}&#8217; and AcctStopTime is null}”){<br />
}<br />
}</p>
<p><span id="more-721"></span>如果不允许一个用户同时多处登录，去掉Calling-Station-Id的条件即可。</p>
<p>if(User-Name) {<br />
if(“%{sql:UPDATE radacct set AcctStopTime=ADDDATE(AcctStartTime,INTERVAL AcctSessionTime SECOND),AcctTerminateCause=&#8217;Clear-Stale Session&#8217; WHERE UserName=&#8217;%{User-Name}&#8217; and AcctStopTime is null}”){<br />
}<br />
}</p>
<p>注意这里sql是有意放在一个空的if语句中，因为在freeradius的配置文件中，一般语句中的sql会要求有返回值。放在if条件中可以避免因为检查返回值失败。</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>补记：</p>
<p>再想想这样做也还有些问题，因为只是在数据库中清除了状态，如果前一个连接物理上还存在的话，并不能物理上断开相应的连接。完美解决方案需要NAS能检查连接状态，如果NAS不提供相应功能的话，不能有完好解决方案。</p>
<p>折中的方案是通过Acct-Interim-Interval设置NAS更新数据周期，在检查无效连接时只处理一段时间(比如三个更新周期)没有更新数据的连接。一点问题是如果一个连接异常断开后，在一段时间内无法再次登陆。</p>
<p>if(User-Name) {<br />
if(“%{sql:UPDATE radacct set AcctStopTime=ADDDATE(AcctStartTime,INTERVAL AcctSessionTime SECOND),AcctTerminateCause=&#8217;Clear-Stale Session&#8217; WHERE UserName=&#8217;%{User-Name}&#8217; and AcctStopTime is null and (TIME_TO_SEC(TIMEDIFF(NOW(),AcctStartTime))-1000)&gt;AcctSessionTime}”){<br />
}<br />
}</p>
<p>//示例是1000秒没有新数据即清除状态</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/721/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP FastCGI做Apache虚拟主机用户隔离</title>
		<link>http://www.fallday.org/archives/714</link>
		<comments>http://www.fallday.org/archives/714#comments</comments>
		<pubDate>Sun, 27 Nov 2011 09:00:41 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[主机管理]]></category>
		<category><![CDATA[云计算]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SuExec]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=714</guid>
		<description><![CDATA[共享主机的情况，设置每个虚拟主机的进程在单独的用户下会相对安全。在PHP的情况下，可以通过PHP FastCGI及SuExec来实现。 1. CentOS可以从EPEL中安装mod_fcgid yum install httpd php-cli mod_fcgid 2. vi /etc/php.ini cgi.fix_pathinfo = 1 3. 创建vhosts First we create the users and groups: groupadd web1 groupadd web2 useradd -s /bin/false -d /var/www/web1 -m -g web1 web1 useradd -s /bin/false -d /var/www/web2 -m -g web2 web2 chmod 755 /var/www/web1 chmod 755 /var/www/web2 Then we create [...]]]></description>
			<content:encoded><![CDATA[<p>共享主机的情况，设置每个虚拟主机的进程在单独的用户下会相对安全。在PHP的情况下，可以通过PHP FastCGI及SuExec来实现。</p>
<p>1. CentOS可以从EPEL中安装mod_fcgid</p>
<p>yum install httpd php-cli mod_fcgid</p>
<p>2. vi /etc/php.ini</p>
<p>cgi.fix_pathinfo = 1</p>
<p>3. 创建vhosts</p>
<p><span id="more-714"></span>First we create the users and groups:</p>
<p>groupadd web1<br />
groupadd web2<br />
useradd -s /bin/false -d /var/www/web1 -m -g web1 web1<br />
useradd -s /bin/false -d /var/www/web2 -m -g web2 web2<br />
chmod 755 /var/www/web1<br />
chmod 755 /var/www/web2</p>
<p>Then we create the document roots and make them owned by the users/groups web1 resp. web2:</p>
<p>mkdir -p /var/www/web1/web<br />
chown web1:web1 /var/www/web1/web<br />
mkdir -p /var/www/web2/web<br />
chown web2:web2 /var/www/web2/web</p>
<p>We will run PHP using suExec; suExec’s document root is /var/www, as the following command shows:</p>
<p>/usr/sbin/suexec -V</p>
<p>[root@server1 ~]# /usr/sbin/suexec -V<br />
-D AP_DOC_ROOT=”/var/www”<br />
-D AP_GID_MIN=100<br />
-D AP_HTTPD_USER=”apache”<br />
-D AP_LOG_EXEC=”/var/log/httpd/suexec.log”<br />
-D AP_SAFE_PATH=”/usr/local/bin:/usr/bin:/bin”<br />
-D AP_UID_MIN=500<br />
-D AP_USERDIR_SUFFIX=”public_html”<br />
[root@server1 ~]#</p>
<p>Therefore we cannot call the PHP binary (/usr/bin/php-cgi) directly because it is located outside suExec’s document root. As suExec does not allow symlinks, the only way to solve the problem is to create a wrapper script for each web site in a subdirectory of /var/www; the wrapper script will then call the PHP binary /usr/bin/php-cgi. The wrapper script must be owned by the user and group of each web site, therefore we need one wrapper script for each web site. I’m going to create the wrapper scripts in subdirectories of /var/www/php-fcgi-scripts, e.g. /var/www/php-fcgi-scripts/web1 and /var/www/php-fcgi-scripts/web2.</p>
<p>mkdir -p /var/www/php-fcgi-scripts/web1<br />
mkdir -p /var/www/php-fcgi-scripts/web2</p>
<p>vi /var/www/php-fcgi-scripts/web1/php-fcgi-starter</p>
<table width="90%" border="1" cellspacing="0" cellpadding="2" align="center" bgcolor="#cccccc">
<tbody>
<tr>
<td>
<pre>#!/bin/sh
PHPRC=/etc/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/bin/php-cgi</pre>
</td>
</tr>
</tbody>
</table>
<p>vi /var/www/php-fcgi-scripts/web2/php-fcgi-starter</p>
<table width="90%" border="1" cellspacing="0" cellpadding="2" align="center" bgcolor="#cccccc">
<tbody>
<tr>
<td>
<pre>#!/bin/sh
PHPRC=/etc/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/bin/php-cgi</pre>
</td>
</tr>
</tbody>
</table>
<p>The PHPRC line contains the directory where the php.ini file is located (i.e., /etc/ translates to /etc/php.ini). PHP_FCGI_MAX_REQUESTS is the maximum number of requests before an fcgid process is stopped and a new one is launched. PHP_FCGI_CHILDREN defines the number of PHP children that will be launched.</p>
<p>The php-fcgi-starter scripts must be executable, and they (and the directories they are in) must be owned by the web site’s user and group:</p>
<p>chmod 755 /var/www/php-fcgi-scripts/web1/php-fcgi-starter<br />
chmod 755 /var/www/php-fcgi-scripts/web2/php-fcgi-starter<br />
chown -R web1:web1 /var/www/php-fcgi-scripts/web1<br />
chown -R web2:web2 /var/www/php-fcgi-scripts/web2</p>
<p>Now we create the Apache vhosts for www.example1.com and www.example2.com. Add the following two vhosts at the end of /etc/httpd/conf/httpd.conf:</p>
<p>vi /etc/httpd/conf/httpd.conf</p>
<table width="90%" border="1" cellspacing="0" cellpadding="2" align="center" bgcolor="#cccccc">
<tbody>
<tr>
<td>
<pre>[...]
NameVirtualHost *:80

&lt;VirtualHost *:80&gt;
  ServerName www.example1.com
  ServerAlias example1.com
  ServerAdmin webmaster@example1.com
  DocumentRoot /var/www/web1/web/

  &lt;IfModule mod_fcgid.c&gt;
    SuexecUserGroup web1 web1
    PHP_Fix_Pathinfo_Enable 1
    &lt;Directory /var/www/web1/web/&gt;
      Options +ExecCGI
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    &lt;/Directory&gt;
  &lt;/IfModule&gt;

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off

&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
  ServerName www.example2.com
  ServerAlias example2.com
  ServerAdmin webmaster@example2.com
  DocumentRoot /var/www/web2/web/

  &lt;IfModule mod_fcgid.c&gt;
    SuexecUserGroup web2 web2
    PHP_Fix_Pathinfo_Enable 1
    &lt;Directory /var/www/web2/web/&gt;
      Options +ExecCGI
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/web2/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    &lt;/Directory&gt;
  &lt;/IfModule&gt;

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off

&lt;/VirtualHost&gt;</pre>
</td>
</tr>
</tbody>
</table>
<p>Make sure you fill in the right paths (and the correct user and group in the SuexecUserGroup lines).</p>
<p>Reload Apache afterwards:</p>
<p>/etc/init.d/httpd reload</p>
<p>原文链接：http://www.mounix.com/blog/2011/08/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-centos-5-6/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/714/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>基于FreeRADIUS 的VPN(PPTP/L2TP)认证及流量控制</title>
		<link>http://www.fallday.org/archives/703</link>
		<comments>http://www.fallday.org/archives/703#comments</comments>
		<pubDate>Fri, 25 Nov 2011 14:53:36 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[云计算]]></category>
		<category><![CDATA[网络安全]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=703</guid>
		<description><![CDATA[在VPS设置的VPN可以与朋友分享，但流量还是要控制的。不然流量超了可要自己去埋单。 参考网上的说明，安装还是很顺利的，PPTP和L2TP都可以支持，FreeRADIUS还是很强大的。 管理界面用的FreeRADIUS自己带的Dailup Admin. 安装可以参考官方网站 ( http://www.freeradius.org/ )。 下面是几篇参考文章： 1. PPTP/L2TP + FreeRADIUS + MySQL 安装与配置  ( https://wangyan.org/blog/freeradius-pptp-l2tp-html.html ) 2. 通过FreeRADIUS实现VPN流量控制功能 ( https://wangyan.org/blog/freeradius-traffic-limit.html ) 3. 在PPTP VPN服务器上配置FreeRADIUS+daloRADIUS实现用户跟踪管理 ( http://dayanjia.com/2011/03/configure-freeradius-and-daloradius-on-pptp-vpn-server.html ) 也摘录在此 PPTP/L2TP + FreeRADIUS + MySQL 安装与配置 &#160; FreeRADIUS 是实现 RADIUS 协议的开源软件，而 RADIUS 主要用来实现认证(Authentication)、授权(Authorization)以及计费(Accounting)功能。 首先请确认你已经搭建好pptpd，并可以正常使用。安装方法见《Debian/Ubuntu PPTP VPN 安装笔记》 一、FreeRADIUS 服务端安装 1.1、下载、编译、安装 1 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p>在VPS设置的VPN可以与朋友分享，但流量还是要控制的。不然流量超了可要自己去埋单。</p>
<p>参考网上的说明，安装还是很顺利的，PPTP和L2TP都可以支持，FreeRADIUS还是很强大的。</p>
<p>管理界面用的FreeRADIUS自己带的Dailup Admin. 安装可以参考官方网站 ( http://www.freeradius.org/ )。</p>
<p>下面是几篇参考文章：</p>
<p>1. PPTP/L2TP + FreeRADIUS + MySQL 安装与配置  ( https://wangyan.org/blog/freeradius-pptp-l2tp-html.html )</p>
<p>2. 通过FreeRADIUS实现VPN流量控制功能 ( https://wangyan.org/blog/freeradius-traffic-limit.html )</p>
<p>3. 在PPTP VPN服务器上配置FreeRADIUS+daloRADIUS实现用户跟踪管理 ( http://dayanjia.com/2011/03/configure-freeradius-and-daloradius-on-pptp-vpn-server.html )</p>
<p><span id="more-703"></span>也摘录在此</p>
<h2><a href="https://wangyan.org/blog/freeradius-pptp-l2tp-html.html">PPTP/L2TP + FreeRADIUS + MySQL 安装与配置</a></h2>
<p>&nbsp;</p>
<section>FreeRADIUS 是实现 RADIUS 协议的开源软件，而 RADIUS 主要用来实现认证(Authentication)、授权(Authorization)以及计费(Accounting)功能。</p>
<p>首先请确认你已经搭建好pptpd，并可以正常使用。安装方法见<a href="https://wangyan.org/blog/debian-pptp-vpn.html">《Debian/Ubuntu PPTP VPN 安装笔记》</a></p>
<h3>一、FreeRADIUS 服务端安装</h3>
<h4>1.1、下载、编译、安装</h4>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4
5</pre>
</td>
<td>
<pre>wget -c ftp://ftp.freeradius.org/pub/freeradius/freeradius-server-2.1.11.tar.gz
tar zxf freeradius-server-2.1.11.tar.gz
cd freeradius-server-2.1.11
./configure
make &amp;&amp; make install</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>1.2、基本文件的本地测试（选做）</h4>
<p>测试是否安装成功，如果不需要与mysql集成，那么就已安装完成。</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2</pre>
</td>
<td>
<pre>vim /usr/local/etc/raddb/users
查找 steve Cleartext-Password := "testing" （76-84行）, 取消该段内容的注释。</pre>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4
5</pre>
</td>
<td>
<pre># 大写X，意思是以debug模式运行。
/usr/local/sbin/radiusd -X 

#新开一个窗口执行，看到 "Access-Accept packet" 表示成功了，"Access-Reject" 表示失败了。
/usr/local/bin/radtest steve testing localhost 0 testing123</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>二、FreeRadius MySQL 模块配置</h3>
<h4>2.1、启用MySQL模块支持</h4>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2</pre>
</td>
<td>
<pre># 查找"sql.conf”(683行)，去掉#号
vim /usr/local/etc/raddb/radiusd.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>2.2、创建 radius 数据库及表</h4>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2</pre>
</td>
<td>
<pre># 123456是你mysql的root密码
mysqladmin -uroot -p123456 create radius;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4</pre>
</td>
<td>
<pre>#修改radius帐号的密码
cd /usr/local/etc/raddb/sql/mysql
sed -i 's/radpass/123456/g' admin.sql
sed -i 's/radpass/123456/g' /usr/local/etc/raddb/sql.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4
5
6</pre>
</td>
<td>
<pre>mysql -uroot -p123456 &lt; admin.sql
mysql -uroot -p123456 radius &lt; ippool.sql
mysql -uroot -p123456 radius &lt; schema.sql
mysql -uroot -p123456 radius &lt; wimax.sql
mysql -uroot -p123456 radius &lt; cui.sql
mysql -uroot -p123456 radius &lt; nas.sql</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>2.3、打开从数据库查询nas支持</h4>
<p>默认从 “/usr/local/etc/raddb/clients.conf” 文件读取，开启后可从数据库nas表读取。</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>sed -i 's/\#readclients/readclients/g' /usr/local/etc/raddb/sql.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>2.4、打开在线人数查询支持</h4>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2</pre>
</td>
<td>
<pre># 查找simul_count_query将279-282行注释去掉
vim /usr/local/etc/raddb/sql/mysql/dialup.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>2.5、修改sites-enabled目录配置文件</h4>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>vim /usr/local/etc/raddb/sites-enabled/default</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>找到authorize {}模块，注释掉files（159行），去掉sql前的#号（166行）<br />
找到accounting {}模块，注释掉radutmp(385行),注释掉去掉sql前面的#号(395行)。<br />
找到session {}模块，注释掉radutmp（439行），去掉sql前面的#号（443行）。<br />
找到post-auth {}模块，去掉sql前的#号（464行），去掉sql前的#号（552行）。</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>vim /usr/local/etc/raddb/sites-enabled/inner-tunnel</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>找到authorize {}模块，注释掉files（124行），去掉sql前的#号（131行）。<br />
找到session {}模块，注释掉radutmp（251行），去掉sql前面的#号（255行）。<br />
找到post-auth {}模块，去掉sql前的#号（277行）,去掉sql前的#号（301行）。</p>
<h3>三、FreeRADIUS 客户端安装与配置</h3>
<h4>3.1、编译与安装</h4>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4
5</pre>
</td>
<td>
<pre>wget -c ftp://ftp.freeradius.org/pub/freeradius/freeradius-client-1.1.6.tar.gz
tar -zxf freeradius-client-1.1.6.tar.gz
cd freeradius-client-1.1.6
./configure
make &amp;&amp; make install</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>3.2、设置通信密码</h4>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3</pre>
</td>
<td>
<pre>cat &gt;&gt;/usr/local/etc/radiusclient/servers&lt;&lt;EOF
localhost   testing123
EOF</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>其中localhost可以写成服务器IP地址，testing123是认证服务器的连接密码。<br />
注：如果使用的是IP地址，记得同时修改下面设置。</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>sed -i 's/localhost/192.168.8.129/g' /usr/local/etc/radiusclient/radiusclient.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>3.3、增加字典</h4>
<p>这一步很重要！否则windows客户端无法连接服务器。</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2</pre>
</td>
<td>
<pre>wget -c http://small-script.googlecode.com/files/dictionary.microsoft
mv ./dictionary.microsoft /usr/local/etc/radiusclient/</pre>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4
5
6
7</pre>
</td>
<td>
<pre>cat &gt;&gt;/usr/local/etc/radiusclient/dictionary&lt;&lt;EOF
INCLUDE /usr/local/etc/radiusclient/dictionary.sip
INCLUDE /usr/local/etc/radiusclient/dictionary.ascend
INCLUDE /usr/local/etc/radiusclient/dictionary.merit
INCLUDE /usr/local/etc/radiusclient/dictionary.compat
INCLUDE /usr/local/etc/radiusclient/dictionary.microsoft
EOF</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>3.4、PPTP启用freeradius插件</h4>
<p>这一步网上一些教程没提，但很重要，否则会报错！</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3</pre>
</td>
<td>
<pre>sed -i 's/logwtmp/\#logwtmp/g' /etc/pptpd.conf
sed -i 's/radius_deadtime/\#radius_deadtime/g' /usr/local/etc/radiusclient/radiusclient.conf
sed -i 's/bindaddr/\#bindaddr/g' /usr/local/etc/radiusclient/radiusclient.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>注：64位系统插件路径是 “/usr/lib64/pppd/2.4.5/radius.so”</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4</pre>
</td>
<td>
<pre>cat &gt;&gt;/etc/ppp/pptpd-options&lt;&lt;EOF
plugin /usr/lib/pppd/2.4.5/radius.so
radius-config-file /usr/local/etc/radiusclient/radiusclient.conf
EOF</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>3.5、L2TP启用freeradius插件</h4>
<p>L2TP 的道理也一样，你首先安装配置好L2TP/IPSec，并保证能正常使用。<br />
<a href="https://wangyan.org/blog/debian-l2tp-ipsec-vpn.html">《Debian/Ubuntu L2TP/IPSec VPN 安装笔记》</a></p>
<p>注：64位系统插件路径是 “/usr/lib64/pppd/2.4.5/radius.so”</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4</pre>
</td>
<td>
<pre>cat &gt;&gt;/etc/ppp/options.xl2tpd&lt;&lt;EOF
plugin /usr/lib/pppd/2.4.5/radius.so
radius-config-file /usr/local/etc/radiusclient/radiusclient.conf
EOF</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>四、用户权限管理</h3>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21</pre>
</td>
<td>
<pre># 连接 MySQL 数据库
mysql -uroot -p123456;

# 使用 radius 数据库
USE radius;

# 添加用户demo，密码demo，注意是在radchec表
INSERT INTO radcheck (username,attribute,op,VALUE) VALUES ('demo','Cleartext-Password',':=','demo');

# 将用户demo加入VIP1用户组
INSERT INTO radusergroup (username,groupname) VALUES ('demo','VIP1');

# 限制同时登陆人数，注意是在radgroupcheck表
INSERT INTO radgroupcheck (groupname,attribute,op,VALUE) VALUES ('normal','Simultaneous-Use',':=','1');

# 其他
INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES ('VIP1','Auth-Type',':=','Local');
INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES ('VIP1','Service-Type',':=','Framed-User');
INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES ('VIP1','Framed-Protocol',':=','PPP');
INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES ('VIP1','Framed-MTU',':=','1500');
INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES ('VIP1','Framed-Compression',':=','Van-Jacobson-TCP-IP');</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>五、启动</h3>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2</pre>
</td>
<td>
<pre>cp /usr/local/sbin/rc.radiusd /etc/init.d/radiusd
/etc/init.d/radiusd start</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>参考资料：</p>
<p>1. <a href="http://wiki.freeradius.org/SQL%20HOWTO" rel="nofollow">http://wiki.freeradius.org/SQL%20HOWTO</a><br />
2. <a href="https://tomem.info/blog/2011/04/562" rel="nofollow">https://tomem.info/blog/2011/04/562</a><br />
3. <a href="https://tomem.info/blog/2011/04/577" rel="nofollow">https://tomem.info/blog/2011/04/577</a><br />
4. <a href="http://www.xtgly.com/2011/01/05/pptpdfreeradiusmysql%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE.htm" rel="nofollow">http://www.xtgly.com/2011/01/05/&#8230;</a><br />
5. <a href="http://ichinihachi.blogspot.com/2011/02/ubuntufreeradius.html" rel="nofollow">http://ichinihachi.blogspot.com/2011/02/ubuntufreeradius.html</a></p>
<p>最后更新：2011.08.23</p>
<p>原文地址 : <a href="https://wangyan.org/blog/freeradius-pptp-l2tp-html.html">https://wangyan.org/blog/freeradius-pptp-l2tp-html.html</a></p>
</section>
<h2><a href="https://wangyan.org/blog/freeradius-traffic-limit.html">通过FreeRADIUS实现VPN流量控制功能</a></h2>
<section>&nbsp;</p>
<section>搭建一个VPN非常容易，但如何实现PPTP/L2TP VPN流量限制？首先必须先安装配置好FreeRADIUS，方法见<a href="https://wangyan.org/blog/freeradius-pptp-l2tp-html.html">《PPTP/L2TP + FreeRADIUS + MySQL 安装与配置》</a>，然后再进行下面操作。</p>
<h3>一、启用 Rlm sqlcounter 模块</h3>
<p>查找”counter.conf”(695行)，去掉#号</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>vim /usr/local/etc/raddb/radiusd.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>二、添加 Traffic Counter流量计数器</h3>
<p>网上一些教程有拼写错误，折腾了大半天才在<a href="http://wiki.freeradius.org/Rlm_sqlcounter">官方文档</a>上找到原因。</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>vim /usr/local/etc/raddb/sql/mysql/counter.conf</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>在文件末尾添加下面代码</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2
3
4
5
6
7
8
9</pre>
</td>
<td>
<pre>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) &gt; '%b'"
}</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>上面代码意思是按月进行统计，从数据库的radacct表中，根据用户名(%k)将所有入站和出站流量累加。</p>
<p>时间也是可以自定义的（months、weeks、days、hours），也可以指定具体值，如三天重置一次 “reset = 3 d”</p>
<h3>三、启用Traffic Counter流量计数器</h3>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>vim /usr/local/etc/raddb/sites-enabled/default</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>在authorize区块的末尾（205行）添加</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>monthlytrafficcounter</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>四、添加字典文件</h3>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>vim /usr/local/etc/raddb/dictionary</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>在文件末尾添加下面两行</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1
2</pre>
</td>
<td>
<pre>ATTRIBUTE Max-Monthly-Traffic 3003 integer
ATTRIBUTE Monthly-Traffic-Limit 3004 integer</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>五、数据库插入流量限制值</h3>
<p>注意事项：</p>
<p>1）这里插入到radgroupcheck表，是限制某个用户组的流量。也可以插入到radcheck表，以限制某个用户的流量。<br />
2）流量值以 byte 为单位，1G = 1073741824 bytes<br />
3）VIP1是用户组，123456是数据库root密码</p>
<p># 连接到MySQL数据库</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>mysql -uroot -p123456;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p># 每月最大流量（1G）</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>INSERT INTO radgroupcheck (groupname,attribute,op,VALUE) VALUES ('VIP1','Max-Monthly-Traffic',':=','1073741824');</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p># 流量统计时间的间隔（60秒）</p>
<div>
<table>
<tbody>
<tr>
<td>
<pre>1</pre>
</td>
<td>
<pre>INSERT INTO radgroupcheck (groupname,attribute,op,VALUE) VALUES ('VIP1','Acct-Interim-Interval',':=','60');</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>参考资料：</p>
<p>1. <a href="http://wiki.freeradius.org/Rlm_sqlcounter" rel="nofollow">http://wiki.freeradius.org/Rlm_sqlcounter</a><br />
2. <a href="http://freeradius.org/rfc/attributes.html" rel="nofollow">http://freeradius.org/rfc/attributes.html</a><br />
3. <a href="https://blog.easisee.com/2010/09/freeradius-traffic-limit/" rel="nofollow">https://blog.easisee.com/2010/09/freeradius-traffic-limit/</a></p>
</section>
<section>原文地址 : <a href="https://wangyan.org/blog/freeradius-traffic-limit.html">https://wangyan.org/blog/freeradius-traffic-limit.html</a></section>
<section></section>
<section>
<h1>在PPTP VPN服务器上配置FreeRADIUS+daloRADIUS实现用户跟踪管理</h1>
<p>现在很多拥有国外VPS的朋友都纷纷安装了VPN服务来方便自己上网，有时候我们还会共享出一些帐号给自己的同学、朋友使用。使用VPN来 上网、玩网游等能够有效地解决某些线路上的问题，但是用的人一多难免会出现资源分配不均的情况，这时合理的管理手段就显得很有必要了。不过拿常见的 PPTP VPN来说，最简单的配置就是使用PPP的<code>chap-secrets</code>文件来静态地保存用户名和密码，这样我们没有办法知道各个用户连接VPN的时间，上传下载的数据量等信息，所谓用户跟踪管理完全就是一笔糊涂账。我们将目光转向一种更加高级的用户验证手段——RADIUS服务，用它就能实现完善的用户跟踪管理功能。</p>
<p>本文以CentOS 5.5操作系统上的PoPToP VPN服务为例讲述<strong>配置FreeRADIUS服务，使用MySQL数据库管理用户验证信息，安装Web管理界面daloRADIUS</strong>的方法，其他VPN例如L2TP、OpenVPN等类似。本文内容参考了诸多资料，恕不一一列出。</p>
<h2>前置条件</h2>
<p>首先要保证使用<code>chap-secrets</code>验证的PPTP服务能够正常使用。关于配置简单PPTP VPN的方法不在本文的范围之内，请参考<a title="在CentOS下安装PPTP的VPN" href="http://www.black-xstar.com/blog/691.html" target="_blank">这篇文章</a>或其他相关教程。<br />
其次，你需要在服务器上安装好HTTP+PHP+MySQL环境，本例中使用Apache作为HTTP服务器。此外PHP需要安装PEAR。</p>
<h2>科普时间</h2>
<p><strong>PPP</strong>：Point-to-Point Protocol，<a title="点对点协议" href="http://zh.wikipedia.org/wiki/%E7%82%B9%E5%AF%B9%E7%82%B9%E5%8D%8F%E8%AE%AE" target="_blank">点对点协议</a>， 是工作在数据链路层的连接协议。常见的ADSL连接时使用的PPPoE便是指的以太网上的点对点协议（Point-to-Point Protocol over Ethernet）。而我们创建连接VPN时也会通过PPP来进行，*nix操作系统上的pppd能够完成这一任务，其进行用户验证的默认方法便是<code>chap-secrets</code>文件。配置完FreeRADIUS后，我们需要把用户验证这一环节交给RADIUS服务器来完成。</p>
<p><strong>RADIUS</strong>：Remote Authentication Dial In User Service，远程用户拨号验证服务，基于<a title="RFC2865 - Internet Engineering Task Force" href="http://www.ietf.org/rfc/rfc2865.txt" target="_blank">RFC2865</a>和<a title="RFC2866 - Internet Engineering Task Force" href="http://www.ietf.org/rfc/rfc2866.txt" target="_blank">RFC2866</a>。具体的工作原理挺复杂的，仔细阅读这两个RFC标准应该可以搞明白。简单的说，它是一个兼顾验证（authentication）、授权（authorization）及记账（accounting）三种服务的协议，即<a title="AAA protocol" href="http://en.wikipedia.org/wiki/AAA_protocol" target="_blank">AAA协议</a>。RADIUS运行在应用层，使用UDP进行传输，它被广泛用于ISP和企业用来控制Internet或内部网络、无线网络的访问。</p>
<p><a href="http://freeradius.org/"><img title="FreeRADIUS" src="http://freeradius.org/css/freeradius.png" alt="" width="188" height="39" /></a><strong><a title="freeradius" href="http://freeradius.org/" target="_blank">FreeRADIUS</a></strong>：是一个实现RADIUS协议的软件，基于GPLv2开源。它是目前部署最广泛的开源RADIUS软件。</p>
<p><strong><a title="daloRADIUS" href="http://daloradius.com/" target="_blank">daloRADIUS</a></strong>：是一个FreeRADIUS的Web挂历程序，使用PHP编写。</p>
<h2>安装配置流程</h2>
<h3>配置FreeRADIUS</h3>
<p>1. 登入终端后，首先安装FreeRAIUS，一般源里两个版本，其中FreeRADIUS 1.x已经不被支持了，我们安装的是freeradius2。</p>
<div>
<div id="highlighter_853943">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>yum </code><code>install</code> <code>freeradius2 freeradius2-mysql freeradius2-utils</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>2. 安装完后，我们编辑<code>/etc/raddb/users</code>，在文件开头加上：<code>testing Cleartext-Password := "password"</code>。</p>
<blockquote><p>Tips：你需要了解如何使用SSH终端，和终端里文本编辑的方法，例如Vim的使用。</p></blockquote>
<p>3. 启动radiusd，第一次启动会生成密钥，稍等片刻即可。使用<code>-X</code>参数可以让调试信息直接输出屏幕：</p>
<div>
<div id="highlighter_769649">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>radiusd -X</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>4. 新打开一个SSH终端，测试服务器是否连通：</p>
<div>
<div id="highlighter_314287">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>radtest testing password 127.0.0.1 0 testing123</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>如果看到Access-Accept就说明连接成功了。如果看到类似“Ignoring request to authentication address * port 1812 from unknownclient”的文字，可能需要去修改<code>/etc/raddb/clients.conf</code>，将<code>client localhost</code>段下的<code>ipaddr</code>改为服务器的IP，而不是127.0.0.1。<br />
测试连接成功后，我们可以把<code>users</code>里临时加上去的第一行删除。</p>
<p>5. 下载ppp源码，因为要用到其中的配置文件：</p>
<div>
<div id="highlighter_494172">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
</td>
<td>
<div>
<div><code>wget </code><code>ftp</code><code>:</code><code>//ftp</code><code>.samba.org</code><code>/pub/ppp/ppp-2</code><code>.4.5.</code><code>tar</code><code>.gz</code></div>
<div><code>tar</code> <code>zxvf ppp-2.4.5.</code><code>tar</code><code>.gz</code></div>
<div><code>cp</code> <code>-R </code><code>/root/ppp-2</code><code>.4.5</code><code>/pppd/plugins/radius/etc/</code> <code>/usr/local/etc/radiusclient</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>6. 编辑<code>/usr/local/etc/radiusclient/servers</code>，加上一组服务器和密钥，本例中为“MyVPN”：</p>
<div>
<div id="highlighter_297494">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
</td>
<td>
<div>
<div><code>localhost MyVPN</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>7. 编辑<code>/usr/local/etc/radiusclient/dictionary</code>，将最后一行改为：<br />
<code>INCLUDE /usr/local/etc/radiusclient/dictionary.microsoft</code><br />
可以再添加一行：<br />
<code>INCLUDE /usr/local/etc/radiusclient/dictionary.merit</code></p>
<p>8. 编辑<code>/etc/raddb/clients.conf</code>，把<code>client localhost</code>段下的<code>secret</code>改成刚才指定的密钥。</p>
<p>9. 编辑<code>/etc/raddb/radiusd.conf</code>，找到<code>$INCLUDE sql.conf</code>，去掉前面的<code>#</code>；找到<code>$INCLUDE sql/mysql/counter.conf</code>，去掉前面的<code>#</code>。</p>
<p>10. 添加MySQL用户及数据库，你可以使用现成的phpMyAdmin等工具，也可以在终端下操作。本例中，创建了radius的用户和同名的数据库：</p>
<div>
<div id="highlighter_409427">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
</td>
<td>
<div>
<div><code>CREATE</code> <code>USER</code> <code>'radius'</code><code>@</code><code>'localhost'</code> <code>IDENTIFIED </code><code>BY</code> <code>'***'</code><code>;</code></div>
<div><code>CREATE</code> <code>DATABASE</code> <code>IF </code><code>NOT</code> <code>EXISTS `radius` ;</code></div>
<div><code>GRANT</code> <code>ALL</code> <code>PRIVILEGES</code> <code>ON</code> <code>`radius` . * </code><code>TO</code> <code>'radius'</code><code>@</code><code>'localhost'</code><code>;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>11. 编辑<code>/etc/raddb/sql.conf</code>，配置<code>login</code>（用户名），<code>password</code>（密码），<code>radius_db</code>（数据库名）等字段，并找到<code>readclients</code>一行，设为<code>yes</code>并去掉注释符号<code>#</code>。</p>
<p>12. 编辑<code>/etc/raddb/sites-enabled/default</code>，根据下面的说明注释或取消注释相应的行：</p>
<ul>
<li><code>authorize</code>段，关掉<code>files</code>，打开<code>sql</code>，也可以把<code>unix</code>关掉</li>
<li><code>preacct</code>段，关掉<code>files</code></li>
<li><code>accounting</code>段，打开<code>sql</code>，也可以把<code>unix</code>关掉</li>
<li><code>session</code>段，打开<code>sql</code></li>
<li><code>post-auth</code>段，打开<code>sql</code></li>
<li><code>pre-proxy</code>段，关掉<code>files</code></li>
</ul>
<p>到这一步，我们的FreeRADIUS就算配置好了，用户信息都将保存在MySQL数据库中。至于数据库中的表，我们在后面统一导入。</p>
<h3>配置daloRADIUS</h3>
<p>13. 首先下载并安装daloRADIUS，其中需要安装一个Pear-DB的包：</p>
<div>
<div id="highlighter_247323">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</td>
<td>
<div>
<div><code>wget http:</code><code>//sourceforge</code><code>.net</code><code>/projects/daloradius/files/daloradius/daloradius-0</code><code>.9-8</code><code>/daloradius-0</code><code>.9-8.</code><code>tar</code><code>.gz</code></div>
<div><code>pear </code><code>install</code> <code>DB</code></div>
<div><code>mkdir</code> <code>/usr/share/daloRadius</code></div>
<div><code>tar</code> <code>zxvf daloradius-0.9-8.</code><code>tar</code><code>.gz</code></div>
<div><code>mv</code> <code>daloradius-0.9-8/* </code><code>/usr/share/daloRadius/</code></div>
<div><code>rm</code> <code>-r daloradius-0.9-8</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>14. 这时我们将daloRADIUS中附带的sql文件导入MySQL数据库，别忘了输入密码：</p>
<div>
<div id="highlighter_700547">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>mysql -uroot -p radius &lt; </code><code>/usr/share/daloRadius/contrib/db/fr2-mysql-daloradius-and-freeradius</code><code>.sql</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>15. 编辑<code>/usr/share/daloRadius/library/daloradius.conf.php</code>，这是daloRADIUS的配置文件。首先是MySQL登录信息：</p>
<div>
<div id="highlighter_190441">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</td>
<td>
<div>
<div><code>$configValues</code><code>[</code><code>'CONFIG_DB_HOST'</code><code>] = </code><code>'localhost'</code><code>;</code></div>
<div><code>$configValues</code><code>[</code><code>'CONFIG_DB_USER'</code><code>] = </code><code>'radius'</code><code>;</code></div>
<div><code>$configValues</code><code>[</code><code>'CONFIG_DB_PASS'</code><code>] = </code><code>'***'</code><code>; </code><code>// 设为自己的密码</code></div>
<div><code>$configValues</code><code>[</code><code>'CONFIG_DB_NAME'</code><code>] = </code><code>'radius'</code><code>;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>下面有一个daloRADIUS的bug，默认配置中有一个表名和我们导入的不一样，把它改过来：</p>
<div>
<div id="highlighter_932965">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>$configValues</code><code>[</code><code>'CONFIG_DB_TBL_RADUSERGROUP'</code><code>] = </code><code>'radusergroup'</code><code>;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>然后修改daloRADIUS的路径：</p>
<div>
<div id="highlighter_644955">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>$configValues</code><code>[</code><code>'CONFIG_PATH_DALO_VARIABLE_DATA'</code><code>] = </code><code>'/usr/share/daloRadius/var'</code><code>;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>16. 添加Apache虚拟主机，如果有Web控制面板什么的自然就方便多了，不然就编辑<code>/etc/httpd/conf/httpd.conf</code>，加入：</p>
<div>
<div id="highlighter_308547">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
</td>
<td>
<div>
<div><code>Alias /vpn "/usr/share/daloRadius/"</code></div>
<div><code>&lt;Directory "/usr/share/daloRADIUS"&gt;</code></div>
<div><code>&lt;/Directory&gt;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>17. 重启重启Apache和MySQL：</p>
<div>
<div id="highlighter_469421">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
</td>
<td>
<div>
<div><code>service httpd restart</code></div>
<div><code>service mysqld restart</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>18. 打开浏览器，进入daloRADIUS的管理页面（本例中为<code>http://your.domain/vpn</code>），使用默认用户名<code>administrator</code>和密码<code>radius</code>登录。</p>
<p>daloRADIUS似乎写的不怎么样，最新稳定版已经是三年之前的了，不过作者直到现在还在更新SVN，下次有机会可以用最新的SVN版本试试看。在Management中添加一个新用户，注意密码类型选择Cleartext-Password。</p>
<p>19. 在终端里再次启动<code>radius -X</code>，同时在另一个终端中用<code>radtest username password localhost 0 MyVPN</code>测试一下，看看现在是不是还能正常接通，如果没问题就OK，让我们把这套系统接驳到PPP上。</p>
<h3>配置pppd</h3>
<p>20. 编辑<code>/etc/ppp/options.pptpd</code>，里面已经有许多配置选项了，我们要保证有下面的几行，如果没有就添加上去，为了保障用户登录的安全我们限制只使用MS-CHAPv2：</p>
<div>
<div id="highlighter_141838">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</td>
<td>
<div>
<div><code>refuse-pap</code></div>
<div><code>refuse-chap</code></div>
<div><code>refuse-mschap</code></div>
<div><code>require-mppe-128</code></div>
<div><code>require-mschap-v2</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>在配置文件最后加上3行：</p>
<div>
<div id="highlighter_909435">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
</td>
<td>
<div>
<div><code>plugin radius.so</code></div>
<div><code>plugin radattr.so</code></div>
<div><code>radius-config-file /usr/local/etc/radiusclient/radiusclient.conf</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3>启动服务</h3>
<p>21. 一切完成后我们不需要使用debug模式启动radiusd了：</p>
<div>
<div id="highlighter_231383">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>service radiusd start</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>22. 当然，我们可以把radiusd和pptpd设为开机启动服务：</p>
<div>
<div id="highlighter_103574">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
</td>
<td>
<div>
<div><code>chkconfig radiusd on</code></div>
<div><code>chkconfig pptpd on</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>至此，PPTP+FreeRADIUS+MySQL+daloRADIUS全部配置完毕，我们在本机上使用添加的用户名和密码拨入VPN，可以正常 使用。在daloRADIUS中，还可以看到各个用户每次连接的时长，上传和下载的数据量统计等。daloRADIUS其他的使用方法，本文不再叙述。</p>
</section>
<p>&nbsp;</p>
</section>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/703/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>L2TP/IPSec : iPhone/iPad断开VPN连接后不能再连接成功</title>
		<link>http://www.fallday.org/archives/693</link>
		<comments>http://www.fallday.org/archives/693#comments</comments>
		<pubDate>Fri, 25 Nov 2011 12:45:29 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[主机管理]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[L2TP]]></category>
		<category><![CDATA[Openswan]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=693</guid>
		<description><![CDATA[在iPhone/iPad上遇到一个奇怪现象，L2TP/IPSec的VPN，Windows 7连接好好的。但在iPhone/iPad上却有一个奇怪现象。第一次连接很下正常，但如果断开VPN连接，再次连接时却怎么可连接不成功，后台log中有如下信息： Nov 25 00:17:58 srv xl2tpd[3447]: control_finish: Peer requested tunnel 18 twice, ignoring second one. Nov 25 00:17:58 srv xl2tpd[3447]: Maximum retries exceeded for tunnel 6477.  Closing. 解决方法如下： 在/etc/ipsec.conf里的L2TP-PSK-noNAT中加上 dpddelay=40 dpdtimeout=130 dpdaction=clear 参数说明： dpddelay Set the delay (in seconds) between Dead Peer Dectection (RFC 3706) keepalives (R_U_THERE, R_U_THERE_ACK) that are sent for this connection [...]]]></description>
			<content:encoded><![CDATA[<p>在iPhone/iPad上遇到一个奇怪现象，L2TP/IPSec的VPN，Windows 7连接好好的。但在iPhone/iPad上却有一个奇怪现象。第一次连接很下正常，但如果断开VPN连接，再次连接时却怎么可连接不成功，后台log中有如下信息：</p>
<pre>Nov 25 00:17:58 srv xl2tpd[3447]: control_finish: Peer requested tunnel 18 twice, ignoring second one.
Nov 25 00:17:58 srv xl2tpd[3447]: Maximum retries exceeded for tunnel 6477.  Closing.</pre>
<p>解决方法如下：</p>
<p><span id="more-693"></span>在/etc/ipsec.conf里的L2TP-PSK-noNAT中加上</p>
<pre>dpddelay=40
dpdtimeout=130
dpdaction=clear</pre>
<p>参数说明：</p>
<p><strong>dpddelay</strong></p>
<p>Set the delay (in seconds) between Dead Peer Dectection (RFC 3706) keepalives (R_U_THERE, R_U_THERE_ACK) that are sent for this connection (default 30 seconds). If dpddelay is set, dpdtimeout also needs to be set.</p>
<p><strong>dpdtimeout</strong></p>
<p>Set the length of time (in seconds) we will idle without hearing either an R_U_THERE poll from our peer, or an R_U_THERE_ACK reply. After this period has elapsed with no response and no traffic, we will declare the peer dead, and remove the SA (default 120 seconds). If dpdtimeout is set, dpdaction also needs to be set.</p>
<p><strong>dpdaction</strong></p>
<dl compact="compact">
<dd>When a DPD enabled peer is declared dead, what action should be taken. <strong>hold</strong> (default) means the eroute will be put into %hold status, while <strong>clear</strong> means the eroute and SA with both be cleared. <strong>restart</strong> means the the SA will immediately be renegotiated, and <strong>restart_by_peer</strong> means that <em>ALL</em>SA&#8217;s to the dead peer will renegotiated.<em>dpdaction=clear</em> is really only useful on the server of a Road Warrior config.</p>
</dd>
</dl>
<p>呵呵，更多说明。还是做个明白人好。</p>
<p>Support for Dead Peer Detection:<br />
A Traffic-Based Method of Detecting Dead IKE Peers</p>
<p>The DPD feacture provides support for RFC3706 Dead Peer Detection.</p>
<p>DPD works using a keepalive system, where when a tunnel is idle<br />
(established, but no traffic has traversed it for N period (dpddelay=N1)<br />
one or both sides send a “hello” messages (R_U_THERE) and the other<br />
replies with a acknowledge message (R_U_THERE_ACK). If no response<br />
received, this continues until the DPD timeout value (dpdtimeout=N2)<br />
has elapsed. If there still hasn&#8217;t been any traffic or R_U_THERE_ACK<br />
packets received, the peer is declared to be dead, and the SA deleted,<br />
and related eroute removed from the table.</p>
<p>DPD support is tuneable on a per connection basis, using the dpdaction,<br />
dpddelay and dpdaction directives. See also the ipsec.conf man page for<br />
more information.</p>
<p>An example follows:</p>
<p>conn laptop2myhome<br />
left=%defaultroute<br />
leftnexthop=%defaultroute<br />
right=192.168.0.1<br />
dpddelay=30<br />
dpdtimeout=120<br />
dpdaction=clear</p>
<p>In the above example, our keepalive time is 30 seconds, our timeout is 120<br />
seconds, and our action is clear. So during idle periods, we send<br />
R_U_THERE packets every 30 seconds. If the tunnel is idle and we haven&#8217;t<br />
received an R_U_THERE_ACK from our peer in 120 seconds, we declare the<br />
peer dead, and clear the SA + eroute (the entire tunnel is removed).</p>
<p>Note that both sides must have either dpddelay or dpdtimeout set for DPD<br />
to be proposed or accepted. If one directive is set but not the other,<br />
the defaults are used (dpddelay=30, dpdtimeout=120).</p>
<p>The dpdaction parameter controls what we do when a peer is determined to<br />
be dead. If set to “hold” (the default) it will place the eroute into<br />
%hold status, and wait for the peer to return. If set to “clear” it will<br />
remove the connection entirely, including both the SA and eroute.</p>
<p>We recommend that “hold” be used for statically defined tunnels, and<br />
“clear” be used for roadwarrior tunnels.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/693/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenWRT PPTP NAT Traversal</title>
		<link>http://www.fallday.org/archives/689</link>
		<comments>http://www.fallday.org/archives/689#comments</comments>
		<pubDate>Tue, 22 Nov 2011 14:02:41 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[互联网]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[NAT]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[PPTP]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=689</guid>
		<description><![CDATA[PPTP VPN自己在几个VPS上装过很多次，但这次在Linode东京节点的VPS安装PPTP却遇到一个奇怪现象。自己的Windows 7可顺利连接上，但iPhone/iPad连接却总是失败。但iPhone/iPad连接BuyVM上VPS的PPTP VPN却是可以的。百思不得其解下，想到是不家里的无线路由器设置引起的。路由器是Baffola WZR-HP-G300NH，自己刷的OpenWRT。Google上搜索了OpenWRT PPTP，得到一些线索。 最后安装kmod-ipt-nathelper-extra包重起路由器后，奇迹出现了，iPhone/iPad可以连上了。 下面是OpenWRT Wiki的说明: PPTP NAT Traversal (This information still needs to be verified!) This is how to get a stable solution for establishing PPTP tunnels from one or multiple LAN clients to one or multiple WAN servers passing through OpenWRT&#8217;s network address translation (NAT). Thus this is often referred to [...]]]></description>
			<content:encoded><![CDATA[<p>PPTP VPN自己在几个VPS上装过很多次，但这次在Linode东京节点的VPS安装PPTP却遇到一个奇怪现象。自己的Windows 7可顺利连接上，但iPhone/iPad连接却总是失败。但iPhone/iPad连接BuyVM上VPS的PPTP VPN却是可以的。百思不得其解下，想到是不家里的无线路由器设置引起的。路由器是Baffola WZR-HP-G300NH，自己刷的OpenWRT。Google上搜索了OpenWRT PPTP，得到一些线索。 最后安装kmod-ipt-nathelper-extra包重起路由器后，奇迹出现了，iPhone/iPad可以连上了。</p>
<p>下面是OpenWRT Wiki的说明:</p>
<h1><span id="more-689"></span>PPTP NAT Traversal</h1>
<div>
<p>(This information still needs to be verified!)</p>
<p>This is how to get a stable solution for establishing PPTP tunnels from one or multiple LAN clients to one or multiple <acronym title="Wide Area Network">WAN</acronym> servers passing through OpenWRT&#8217;s network address translation (NAT). Thus this is often referred to as “PPTP pass through”.</p>
</div>
<h2><a id="background" name="background"></a>Background</h2>
<div>
<p>PPTP utilizes the Generic Routing Encapsulation (GRE) protocol for its point-to-point tunnel. As a pure IP protocol GRE uses only IP addresses but no port numbers giving the router&#8217;s NAT a tough time to track such a connection. In its base configuration OpenWRT Backfire is able to NAT a single PPTP connections but not multiple such connections concurrently. It is also unreliable when trying to establish consecutive single PPTP connections from different LAN clients in rapid succession. This limitation can be lifted (as far as I could make out so far) by installing the following package.</p>
</div>
<h2><a id="required.packages" name="required.packages"></a>Required Packages</h2>
<div>
<table>
<tbody>
<tr>
<th>Packages Name</th>
<th>Size in Bytes</th>
<th>Description</th>
</tr>
<tr>
<td>kmod-ipt-nathelper-extra</td>
<td>55770</td>
<td>Extra Netfilter (IPv4) Conntrack and NAT helpers</td>
</tr>
</tbody>
</table>
</div>
<h2><a id="installation" name="installation"></a>Installation</h2>
<div>
<p><a title="doc:techref:opkg" href="http://wiki.openwrt.org/doc/techref/opkg">opkg</a></p>
<pre>opkg install kmod-ipt-nathelper-extra</pre>
<p>You should now be able to use multiple PPTP connections from LAN to <acronym title="Wide Area Network">WAN</acronym> at the same time.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/689/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenWRT无线路由器设置PPTP服务器</title>
		<link>http://www.fallday.org/archives/675</link>
		<comments>http://www.fallday.org/archives/675#comments</comments>
		<pubDate>Fri, 18 Nov 2011 06:29:47 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[互联网]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[PPTP]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=675</guid>
		<description><![CDATA[有时需要从外面访问家里的网络，可以在无线路由器上开一个VPN服务器。 1.安裝pptpd: opkg update opkg install pptpd opkg install kmod-mppe /etc/init.d/pptpd enable /etc/init.d/pptpd start 2. 配置pptpd &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; vi /etc/pptpd.conf option /etc/ppp/options.pptpd localip 192.168.1.1 remoteip 192.168.1.2-99 speed 1152000 stimeout 10 #localip &#038; remoteip are not needed, ip management is done by pppd &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; vi /etc/ppp/options.pptpd auth name “pptp-server” lcp-echo-failure 3 lcp-echo-interval 60 default-asyncmap mtu 1482 mru [...]]]></description>
			<content:encoded><![CDATA[<p>有时需要从外面访问家里的网络，可以在无线路由器上开一个VPN服务器。</p>
<p>1.安裝pptpd:<br />
 opkg update<br />
 opkg install pptpd<br />
 opkg install kmod-mppe<br />
 /etc/init.d/pptpd enable<br />
 /etc/init.d/pptpd start</p>
<p><span id="more-675"></span>2. 配置pptpd<br />
 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
 vi /etc/pptpd.conf</p>
<p> option /etc/ppp/options.pptpd<br />
 localip 192.168.1.1<br />
 remoteip 192.168.1.2-99<br />
 speed 1152000<br />
 stimeout 10<br />
 #localip &#038; remoteip are not needed, ip management is done by pppd</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
 vi /etc/ppp/options.pptpd</p>
<p> auth<br />
 name “pptp-server”<br />
 lcp-echo-failure 3<br />
 lcp-echo-interval 60<br />
 default-asyncmap<br />
 mtu 1482<br />
 mru 1482<br />
 nobsdcomp<br />
 nodeflate<br />
 #noproxyarp<br />
 #nomppc<br />
 chapms-strip-domain<br />
 # Otherwise, your chap-secret file will have to include “DOMAIN\\user” instead of user.<br />
 mppe required,no40,no56,stateless<br />
 require-mschap-v2<br />
 refuse-chap<br />
 refuse-mschap<br />
 refuse-eap<br />
 refuse-pap<br />
 ms-dns 192.168.1.1<br />
 #plugin radius.so<br />
 #radius-config-file /etc/radius.conf<br />
 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
 最後修改你pptp用戶名及密碼,格式: username * password *</p>
<p>vi /etc/ppp/chap-secrets</p>
<p>user * 123 *<br />
 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>加入以下firewall rule:</p>
<p>vi /etc/firewall.user</p>
<p> iptables    -A input_wan -p tcp &#8211;dport 1723 -j ACCEPT<br />
 iptables    -A input_wan -p gre -j ACCEPT<br />
 iptables -A input_rule -i ppp+ -j ACCEPT<br />
 iptables -A forwarding_rule -i ppp+ -j ACCEPT<br />
 iptables -A forwarding_rule -o ppp+ -j ACCEPT<br />
 iptables -A output_rule -o ppp+ -j ACCEPT</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/675/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>免费SSL证书 &#8211; startssl</title>
		<link>http://www.fallday.org/archives/655</link>
		<comments>http://www.fallday.org/archives/655#comments</comments>
		<pubDate>Sun, 06 Nov 2011 05:20:39 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[主机管理]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=655</guid>
		<description><![CDATA[不小心取消了Godaddy的SSL证书，客服竟然不同意恢复，只能再购买。原来是主机免费送的，要买的话就太不合算了。早就听说有免费的SSL证书，也就趁机试试了。 不知道startssl是不是唯一一家其根证书被主流浏览器认可且提供免费的SSL证书的。申请(https://www.startssl.com/)过程并不麻烦，需要确认电邮地址还域名归属，确认都是通过电子邮件瞬间完成。 在Apache上安装却并不顺利，总是找不到证书。问题是出在文件格式，证书是在Windows下生成的，需要转成unix文件格式。这个可又通过dos2unix完成。另外，在Windows创建文件时，要使用纯文本格式。自己存成了UTF8格式，apache也不行。最后删除的文件开始的UTF8文件标识就好了。]]></description>
			<content:encoded><![CDATA[<p>不小心取消了Godaddy的SSL证书，客服竟然不同意恢复，只能再购买。原来是主机免费送的，要买的话就太不合算了。早就听说有免费的SSL证书，也就趁机试试了。</p>
<p>不知道startssl是不是唯一一家其根证书被主流浏览器认可且提供免费的SSL证书的。申请(https://www.startssl.com/)过程并不麻烦，需要确认电邮地址还域名归属，确认都是通过电子邮件瞬间完成。</p>
<p>在Apache上安装却并不顺利，总是找不到证书。问题是出在文件格式，证书是在Windows下生成的，需要转成unix文件格式。这个可又通过dos2unix完成。另外，在Windows创建文件时，要使用纯文本格式。自己存成了UTF8格式，apache也不行。最后删除的文件开始的UTF8文件标识就好了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/655/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debian如何保存iptables配置</title>
		<link>http://www.fallday.org/archives/641</link>
		<comments>http://www.fallday.org/archives/641#comments</comments>
		<pubDate>Tue, 28 Jun 2011 14:47:14 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=641</guid>
		<description><![CDATA[Once you are happy, save the new rules to the master iptables file: &#160; iptables-save &#62; /etc/iptables.up.rules To make sure the iptables rules are started on a reboot we&#8217;ll create a new file: nano /etc/network/if-pre-up.d/iptables Add these lines to it: &#160; #!/bin/bash /sbin/iptables-restore &#60; /etc/iptables.up.rules The file needs to be executable so change the permissions: [...]]]></description>
			<content:encoded><![CDATA[<p>Once you are happy, save the new rules to the master iptables file:</p>
<p>&nbsp;</p>
<pre> iptables-save &gt; /etc/iptables.up.rules</pre>
<p>To make sure the iptables rules are started on a reboot we&#8217;ll create a new file:</p>
<pre> nano /etc/network/if-pre-up.d/iptables</pre>
<p><span id="more-641"></span>Add these lines to it:</p>
<p>&nbsp;</p>
<pre> #!/bin/bash
 /sbin/iptables-restore &lt; /etc/iptables.up.rules</pre>
<p>The file needs to be executable so change the permissions:</p>
<p>&nbsp;</p>
<pre> chmod +x /etc/network/if-pre-up.d/iptables

From: http://wiki.debian.org/iptables</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/641/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VPS中设置主IP</title>
		<link>http://www.fallday.org/archives/588</link>
		<comments>http://www.fallday.org/archives/588#comments</comments>
		<pubDate>Sat, 19 Feb 2011 11:33:48 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[主机管理]]></category>
		<category><![CDATA[网络安全]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=588</guid>
		<description><![CDATA[如果VPS设置了多个IP，该VPS访问外部服务时显示出的IP为主IP。有时可能需要改娈主IP。其实就是改娈VPS的路由表，把默认路由设置为通过该IP。 route -p add 0.0.0.0 mask 0.0.0.0 dev eth0:x]]></description>
			<content:encoded><![CDATA[<p>如果VPS设置了多个IP，该VPS访问外部服务时显示出的IP为主IP。有时可能需要改娈主IP。其实就是改娈VPS的路由表，把默认路由设置为通过该IP。</p>
<p>route -p add 0.0.0.0 mask 0.0.0.0 dev eth0:x </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/588/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CentOS安装L2TP/IPSec</title>
		<link>http://www.fallday.org/archives/554</link>
		<comments>http://www.fallday.org/archives/554#comments</comments>
		<pubDate>Fri, 28 Jan 2011 16:33:53 +0000</pubDate>
		<dc:creator>fallday</dc:creator>
				<category><![CDATA[主机管理]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[IPSec]]></category>
		<category><![CDATA[L2TP]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.fallday.org/?p=554</guid>
		<description><![CDATA[入手了iPhone 4后，发现中国联通的3G封了PPTP的VPN访问。但L2TP还是可以用的。于是自己在VPS的CentOS(5.5)上安装个L2TP/IPSec服务。 在网上找了些文章，安装过程中遇到些问题，最终还是配置好。主是要注意的不能用CentOS 5自身带的OpenSwan(Federa 14中的OpenSwan是可以的），需要从更新版本的源码自己编译安装，XL2TP可是从EPEL中安装，当然也可通过源码安装。 下面内容引自 http://www.wifay.com/blog/2010/08/21/centos-install-ipsec-l2tp-vpn/ 一、部署IPSEC 、安装 openswan 1、关联包 yum install make gcc gmp-devel bison flex 2、编译安装 cd /usr/src wget http://www.openswan.org/download/openswan-2.6.24.tar.gz tar zxvf openswan-2.6.24.tar.gz cd openswan-2.6.24 make programs install 3、配置 vi /etc/ipsec.conf config setup nat_traversal=yes virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12 oe=off protostack=netkey conn L2TP-PSK-NAT rightsubnet=vhost:%priv also=L2TP-PSK-noNAT conn L2TP-PSK-noNAT authby=secret pfs=no auto=add keyingtries=3 rekey=no ikelifetime=8h keylife=1h type=transport left=YOUR.SERVER.IP.ADDRESS [...]]]></description>
			<content:encoded><![CDATA[<p>入手了iPhone 4后，发现中国联通的3G封了PPTP的VPN访问。但L2TP还是可以用的。于是自己在VPS的CentOS(5.5)上安装个L2TP/IPSec服务。</p>
<p>在网上找了些文章，安装过程中遇到些问题，最终还是配置好。主是要注意的不能用CentOS 5自身带的OpenSwan(Federa 14中的OpenSwan是可以的），需要从更新版本的源码自己编译安装，XL2TP可是从EPEL中安装，当然也可通过源码安装。</p>
<p><span id="more-554"></span>下面内容引自 <a href="http://www.wifay.com/blog/2010/08/21/centos-install-ipsec-l2tp-vpn/">http://www.wifay.com/blog/2010/08/21/centos-install-ipsec-l2tp-vpn/</a></p>
<h4>一、部署IPSEC 、安装 openswan</h4>
<p>1、关联包</p>
<blockquote><p>yum install make gcc gmp-devel bison flex</p></blockquote>
<p>2、编译安装</p>
<blockquote><p>cd /usr/src<br />
wget <a href="http://www.openswan.org/download/openswan-2.6.24.tar.gz">http://www.openswan.org/download/openswan-2.6.24.tar.gz</a><br />
tar zxvf openswan-2.6.24.tar.gz<br />
cd openswan-2.6.24<br />
make programs install</p></blockquote>
<p>3、配置</p>
<blockquote><p><strong>vi /etc/ipsec.conf</strong></p>
<p>config setup<br />
nat_traversal=yes<br />
virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12<br />
oe=off<br />
protostack=netkey</p>
<p>conn L2TP-PSK-NAT<br />
rightsubnet=vhost:%priv<br />
also=L2TP-PSK-noNAT</p>
<p>conn L2TP-PSK-noNAT<br />
authby=secret<br />
pfs=no<br />
auto=add<br />
keyingtries=3<br />
rekey=no<br />
ikelifetime=8h<br />
keylife=1h<br />
type=transport<br />
left=YOUR.SERVER.IP.ADDRESS<br />
leftprotoport=17/1701<br />
right=%any<br />
rightprotoport=17/%any</p></blockquote>
<p>4、 设置 Shared Key</p>
<blockquote><p><strong>vi /etc/ipsec.secrets</strong></p>
<p>YOUR.SERVER.IP.ADDRESS %any: PSK “YourSharedSecret”</p></blockquote>
<p>5、 修改包转发设置</p>
<blockquote><p>for each in /proc/sys/net/ipv4/conf/*<br />
do<br />
echo 0 &gt; $each/accept_redirects<br />
echo 0 &gt; $each/send_redirects<br />
done</p></blockquote>
<p>6、 重启 IPSec ，测试</p>
<blockquote><p>/etc/init.d/ipsec restart<br />
ipsec verify</p></blockquote>
<h4>.</h4>
<h4>二、安装 L2TP</h4>
<p>1、关联包</p>
<blockquote><p>yum install libpcap-devel ppp</p></blockquote>
<p>2、编译安装</p>
<blockquote><p>cd /usr/src<br />
wget <a href="http://downloads.sourceforge.net/project/rp-l2tp/rp-l2tp/0.4/rp-l2tp-0.4.tar.gz">http://downloads.sourceforge.net/project/rp-l2tp/rp-l2tp/0.4/rp-l2tp-0.4.tar.gz</a><br />
tar zxvf rp-l2tp-0.4.tar.gz<br />
cd rp-l2tp-0.4<br />
./configure<br />
make<br />
cp handlers/l2tp-control /usr/local/sbin/<br />
mkdir /var/run/xl2tpd/<br />
ln -s /usr/local/sbin/l2tp-control /var/run/xl2tpd/l2tp-control</p>
<p>cd /usr/src<br />
wget  <a href="http://www.xelerance.com/software/xl2tpd/xl2tpd-1.2.4.tar.gz">http://www.xelerance.com/software/xl2tpd/xl2tpd-1.2.4.tar.gz</a><br />
tar zxvf xl2tpd-1.2.4.tar.gz<br />
cd xl2tpd-1.2.4<br />
make install</p></blockquote>
<p>3、配置</p>
<blockquote><p><strong>mkdir /etc/xl2tpd</strong><br />
<strong>vi /etc/xl2tpd/xl2tpd.conf</strong></p>
<p>[global]<br />
ipsec saref = yes</p>
<p>[lns default]<br />
ip range = 10.1.2.2-10.1.2.254<br />
local ip = 10.1.2.1<br />
refuse chap = yes<br />
refuse pap = yes<br />
require authentication = yes<br />
ppp debug = yes<br />
pppoptfile = /etc/ppp/options.xl2tpd<br />
length bit = yes</p></blockquote>
<p>4、修改 ppp 配置</p>
<blockquote><p><strong>vi /etc/ppp/options.xl2tpd</strong></p>
<p>require-mschap-v2<br />
ms-dns 8.8.8.8<br />
ms-dns 8.8.4.4<br />
asyncmap 0<br />
auth<br />
crtscts<br />
lock<br />
hide-password<br />
modem<br />
debug<br />
name l2tpd<br />
proxyarp<br />
lcp-echo-interval 30<br />
lcp-echo-failure 4</p></blockquote>
<p>5、添加用户名/密码</p>
<blockquote><p><strong>vi /etc/ppp/chap-secrets</strong></p>
<p># user      server      password            ip<br />
username        l2tpd       userpass        *</p></blockquote>
<p>6、启用包转发</p>
<blockquote>
<pre>iptables --table nat --append POSTROUTING --jump MASQUERADE</pre>
<p>echo 1 &gt; /proc/sys/net/ipv4/ip_forward</p></blockquote>
<p>7、修改/etc/sysctl.conf</p>
<blockquote><p><strong>vi  /etc/sysctl.conf</strong></p>
<p>net.ipv4.ip_forward = 1<br />
net.ipv4.conf.default.rp_filter = 0<br />
net.ipv4.conf.default.accept_source_route = 0<br />
kernel.sysrq = 0<br />
kernel.core_uses_pid = 1<br />
net.ipv4.tcp_syncookies = 1<br />
kernel.msgmnb = 65536<br />
kernel.msgmax = 65536<br />
kernel.shmmax = 68719476736<br />
kernel.shmall = 4294967296</p></blockquote>
<p>8、启动 xl2tpd</p>
<blockquote><p>/usr/local/sbin/xl2tpd</p></blockquote>
<h4>.</h4>
<h4>三、扫尾</h4>
<p>设置开机自动运行</p>
<blockquote><p><strong>vi /etc/rc.local</strong></p>
<pre>iptables --table nat --append POSTROUTING --jump MASQUERADE</pre>
<p>echo 1 &gt; /proc/sys/net/ipv4/ip_forward<br />
for each in /proc/sys/net/ipv4/conf/*<br />
do<br />
echo 0 &gt; $each/accept_redirects<br />
echo 0 &gt; $each/send_redirects<br />
done<br />
/etc/init.d/ipsec restart<br />
/usr/local/sbin/xl2tpd</p></blockquote>
<h4>.</h4>
]]></content:encoded>
			<wfw:commentRss>http://www.fallday.org/archives/554/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

