CentOS 怎么让centos strongswann IPSec 开机自动启动

strongSwan
strongSwan on FreeBSD
the IKE daemon charon runs on . There are still some
butit has since been tested by several users (even with an adapted version of our ).
Please note that releases before
don't support IKEv1 because the old pluto IKEv1 daemon was not ported to FreeBSD.
Prepare FreeBSD
The generic FreeBSD kernel does not come with IPsec support. So you will have to compile your own kernel.
Fortunately, starting with FreeBSD 8, the NAT Traversal patch is included in the kernel sources, so you don'thave to apply any patches yourself, if you need that feature.
Build the Kernel
Basic documentation on how to build a custom kernel can be found in the .
To enable IPsec you'll need to add the following options to your kernel configuration file:
You can verify that your kernel has IPsec support using the following command, which should print a list of ipsec specific kernel state.
/sbin/sysctl -a | grep ipsec
If you need NAT Traversal, add the following option to your kernel config:
IPSEC_NAT_T
Install FreeBSD Port / Package
The easiest way to install strongSwan on FreeBSD is to use the
cd /usr/ports/security/strongswan/ && make install clean
or to install the binary package with
pkg install strongswan
or in earlier FreeBSD releases with
pkg_add -r strongswan
Manual Installation
Install Packages
Our test-system was installed using the Developer and Kern-Developer distributions in sysinstall. So there are maybe additional packages required on your system.
The packages required to build strongSwan are as follows:
libgmp (optional, depending on configuration)
openssl (optional, depending on configuration)
in earlier FreeBSD releases has been fixed and backported to FreeBSD 8. Thus, the vstr string library is not required anymore (check the history of this wiki page for details).
Building strongSwan
and configure strongSwan as follows (this compiles the GMP plugin, so libgmp is required).For details refer to .
./configure --enable-kernel-pfkey --enable-kernel-pfroute --disable-kernel-netlink \
--disable-scripts --with-group=wheel
For releases before
you also need to add --disable-pluto.
Limitations
virtual IPs could not be used on clients due to the lack of policy based routing. Since
TUN devices are created to implement this, so that FreeBSD can be used as client in road-warrior setups.
the kernel-pfroute interface lacked several features to properly support MOBIKE.
Because there is currently no way to change the IP addresses of an installed IPsec SA in the FreeBSD kernel IPsec SAs are rekeyed when a client's IP address changes.
on the FreeBSD forums has more on this.
Known Problems
did not use the modular kernel interfaces, thus, when it tried to detect an IPsec stack it failed:
Starting strongSwan 4.x.x IPsec [starter]...
no netkey IPsec stack detected
no KLIPS IPsec stack detected
no known IPsec stack detected, ignoring!
Fortunately, this detection is not really needed on FreeBSD so simply ignore this message.期间也在网络上找了很多文章,看了很多人的Blog和FAQ,终于解决 了iOS的Cisco VPN(IPSec VPN)问题。经验一定要分享,下面我会把如何搭建和配置Cisco VPN的过程做个详细的介绍。
还是先说一下iOS设备的一些限制,也就是为啥非要选用Cisco VPN:
1. iOS设备如果不越狱,支持的VPN有PPTP, L2TP, Cisco VPN, Cisco AnyConnect和Juniper的Junos Pulse。如果越狱就可以使用openVPN。
2. PPTP已经被GFW给block了,很多人都在使用L2TP,L2TP支持标准的安全特性CHAP和PAP,可以进行用户身份认证。在安全性考虑上,L2TP仅定义了控制消息的加密传输方式,对传输中的数据并不加密。不安全,不考虑。
3. Cisco AnyConnect需要连接Cisco的Router,ASA或者PIX设备,Junos Pulse需要连接Juniper的SA系列VPN产品。这都需要花钱买,都很贵的,不考虑。
4. 有人会问了,openVPN也是一个选择啊。对,没错,但是iOS设备安装openVPN Client需要越狱。这点是我不能接受的。不考虑。
5. 剩下唯一的解决方案就是找到一个软件,能够支持Cisco VPN Client。
感谢google的强大,终于找到了一款opensource的软件strongSwan。strongSwan可以支持Cisco VPN Client,而且在其官方网页上居然给出了配置方法,很详细,详情请见 。不得不说strongSwan为我们GFW内的人们做了一件大好事儿啊。
我这里给出的配置步骤是根据官方网站的文档和我自己配置过程中的一些体会结合而成,不多说了,开始配吧!
1. 首先要在无墙国家有一台主机(总要有个连接点吧,要不连到哪儿去呢?跟谁建VPN呢?)。我选择的是linode,一个评价相当高的VPS服务提供商。如果大家也选择这里作为您的VPN Server,请从 ,因为是我推荐的哦,如果您follow我的link注册成功,并且使用满90天,linode就能够赠送我$20,也就是一个月的使用期。嘻嘻。我的推荐码:2d244ab3d3fe4d033ebdc7fbb046407
2. 选用操作系统,我选的是Ubuntu。Centos我的一个同事也测试过,没问题。
3. 下载strongSwan:
* wget http://download.strongswan.org/strongswan-4.5.2.tar.bz2
* tar jxvf strongswan-4.5.2.tar.bz2.1.
* cd strongswan-4.5.2
4. 编译,安装strongSwan:
* ./configure –prefix=/usr –sysconfdir=/etc –libexecdir=/usr/lib –with-ipsecdir=/usr/lib/strongswan –enable-cisco-quirks –enable-openssl –enable-nat-transport –disable-mysql –disable-ldap –disable-static –enable-shared
* 这里–enable-cisco-quirks和 –enable-nat-transport非常关键,必须的!
* make install
5. 生成CA证书:
* ipsec pki –gen –outform pem & caKey.pem
* ipsec pki –self –in caKey.pem –dn “C=CN, O=test, CN=Test CA” –ca –outform pem & caCert.pem
6. 生成Server端证书:
* ipsec pki –gen –outform pem & serverKey.pem
* ipsec pki –pub –in serverKey.pem | ipsec pki –issue –cacert caCert.pem –cakey caKey.pem –dn “C=CN, O=test, CN=” –flag serverAuth –outform pem & serverCert.pem
7. 生成Client端证书:
* ipsec pki –gen –outform pem & clientKey.pem
* ipsec pki –pub –in clientKey.pem | ipsec pki –issue –cacert caCert.pem –cakey caKey.pem –dn “C=CN, O=test, CN=client” –outform pem & clientCert.pem
8. 将CA证书转换为.cer格式,将Client证书转换为.p12格式(解释一下原因,这里转换的这两个证书都是要安装在iOS设备上的,iOS设备也能 够支持pem格式的,但是有些朋友使用pem格式的导入iOS设备时出了一些问题,所以为了保险起见,还是cer的吧。Client的.p12格式是因为 p12格式的可以即包含key,也包含证书文件,为了方便,省得导入两个文件了)
* openssl x509 –inform PEM –outform DER –in caCert.pem –out caCert.cer
* openssl pkcs12 -export -inkey clientKey.pem -in clientCert.pem -name “client” -certfile caCert.pem -caname “Test CA” -out clientCert.p12
9. Copy生成的key和证书文件到相应的目录:
* cp caCert.pem /etc/ipsec.d/cacerts/
* cp serverCert.pem /etc/ipsec.d/certs/
* cp serverKey.pem /etc/ipsec.d/private/
* cp clientCert.pem /etc/ipsec.d/certs/
* cp clientKey.pem /etc/ipsec.d/private/
10. 配置/etc/ipsec.conf文件
config setup
plutostart=yes
nat_traversal=yes
keyexchange=ikev1
authby=xauthrsasig
xauth=server
left=%defaultroute
leftsubnet=0.0.0.0/0
leftfirewall=yes
leftcert=serverCert.pem
right=%any
rightsubnet=10.0.0.0/24 (VPN连接后分配给iOS设备的地址所在网段)
rightsourceip=10.0.0.2
rightcert=clientCert.pem
11. 创建ipsec.secrets文件 /etc/ipsec.secrets,并编辑:
# /etc/ipsec.secrets – strongSwan IPsec secrets file
: RSA serverKey.pem (Server的Key文件)
test : XAUTH “password” (test为用户名,password为密码,这里的密码一定要用“”引起来)
12. 配置/etc/strongswan.conf文件,需要分配一个没有任何污染的DSN给VPN连接成功的iOS设备:
# /etc/strongswan.conf – strongSwan configuration file
dns1 = 8.8.8.8 (google的DNS,google又做的一件好事儿!)
13. 配置iOS设备:
将生成的caCert.cer和clientCert.p12通过邮件的方式或者通过web方式下载到iOS设备上,并进行证书安装。
选择 Settings 选择 General & Network & VPN & Add VPN Configuration
选中IPSec VPN
description用来标识你的vpn的,没有特别的限制
Server一定要填入签发Server端证书时,输入的“CN=”的=后的部分,即。如果不一致,iOS设备会报错,Server验证失败。
Account填入ipsec.secrets的用户名
Password填入ipsec.secrects的密码
切换Use Certificate到on,并选择导入和Clent的证书
14. VPN连接:
在Settings & VPN下,将 VPN 切换到 ON 开始进行IPSec VPN的协商和连接。
连接好后,会给出一个Notification“Welcome to strongSwan – the Linux VPN Soluution!”。看到该notificatio后,恭喜你,连接成功了!!
BTW:我顺便说一下iptables的配置:
1. strongSwan用到的端口就是UDP 500和4500,所以在iptables的filter表的INPUT 链要加入允许UDP 500和4500进入,即:
-A INPUT -p udp –dport 500 -j ACCEPT
-A INPUT -p udp –dport 4500 -j ACCEPT
2. 大家使用VPN的主要目的是为了访问大量的信息,所以需要配置NAT,具体配置如下:
-A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
3. 需要配置filter表的Forward链:
-A FORWARD -s 10.0.0.0/24 -j ACCEPT
大功告成!
大家可以安全放心的使用VPN啦!经我的测试,WIFI通过NAT Router连接和GPRS连接都没问题。联通的网络我没有试过,如果有试过的请告知大家结果。谢谢!
如果大家在配置过程中有问题可以DM我@henrywangxf
Written by admin in:
Recent Posts
Categories架设基于StrongSwan的L2tp/IPSec VPN服务器
以下操作基于Debian 6
安装StrongSwan
apt-get install libgmp3-dev libssl-dev make
wget tar zxvf strongswan-4.6.2.tar.gz
cd /tmp/strongswan-4.6.2
./configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --with-ipsecdir=/usr/lib/strongswan --enable-cisco-quirks --enable-openssl --enable-nat-transport --disable-mysql --disable-ldap --disable-static --enable-shared --enable-eap-mschapv2 --enable-eap-radius --enable-eap-md5 --enable-dhcp
make install
编辑 IPSec 配置文件
cp /etc/ipsec.conf /etc/ipsec.conf.old
cat &/etc/ipsec.conf&&EOF
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
plutostart=yes
charonstart=yes
conn L2TP-PSK-NAT
rightsubnet=vhost:%priv
also=L2TP-PSK-noNAT
conn L2TP-PSK-noNAT
type=transport
authby=psk
keyexchange=ikev1
keyingtries=3
left=%defaultroute
leftnexthop=%defaultroute
leftprotoport=17/1701
right=%any
rightprotoport=17/%any
rightsubnetwithin=0.0.0.0/0
设置 PSK 预共享密钥,需要修改成你自己服务器的公网IP及&#”部分
cat &/etc/ipsec.secrets&&EOF
216.187.89.188 %any: PSK ""
调整网络策略, for 循环语句,请一行一行地输入,输完后按回车。
function updateipv4conf()
for each in /proc/sys/net/ipv4/conf/*
echo 0 & $each/accept_redirects
echo 0 & $each/send_redirects
updateipv4conf
重启IPSec 服务,StrongSwan的ipsec命令应该会自动添加到$PATH中
ipsec restart
apt-get install xl2tpd
编辑 xl2tpd 配置文件,请修改下面对应的服务器IP
cat &/etc/xl2tpd/xl2tpd.conf&&EOF
port = 1701
listen-addr = & SERVER_PUBLIC_IP &
ipsec saref = yes
[lns default]
local ip = 10.31.2.1
ip range = 10.31.2.2-10.31.2.254
require chap = yes
refuse pap = yes
require authentication = yes
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
name = xl2tpd
PPP 的安装配置
cat &/etc/ppp/options.xl2tpd&&EOF
require-mschap-v2
ms-dns 8.8.8.8
ms-dns 8.8.4.4
asyncmap 0
hide-password
name xl2tpd
lcp-echo-interval 30
lcp-echo-failure 4
connect-delay 50
添加 VPN 用户
cat &&/etc/ppp/chap-secrets&&EOF
test * test *
包转发及iptables设置在前面已经设置好()
重启xl2tpd
/etc/init.d/xl2tpd restart
注意:Strongswan需要单独运行ipsec命令来启动服务,安装strongswan后,以root用户执行
命令,即可启动strongswan. 试用
ipsec statusall
来查看状态,网上有自启动脚本,或者干脆把这个命令加到/etc/init.d目录下的某个启动文件中。
This entry was posted by
on 2012 年 12 月 7 日 at 下午 1:52, and is filed under . Follow any responses to this post through .
from your own site.
7 comments[求助]windows phone 科学上网方法! IKEv2 服务器端怎么设置啊? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
已注册用户请 &
Sponsored by
100offer 程序员拍卖,让不缺工作机会的优秀程序员,安全匿名的在一个月内拿到 10 - 15 个优质面试机会,从而拥有一份激(shou)动(ru)人(geng)心(gao)的事业。
Promoted by
[求助]windows phone 科学上网方法! IKEv2 服务器端怎么设置啊?
· 180 天前 · 1799 次点击
完全不知道IKEv2是什么东西, google了半天, 参考
这篇文章搭建的server, 也不知道server成功了没!!再查看
客户端设置教程, 不知道怎么用!!有没有更详细的教程? 有没有成功了的同学?
5 回复 &| &直到
16:54:30 +08:00
& &180 天前 via iPhone
升级到 8.1 Update, 用 IpSec
& &180 天前
& &179 天前
按这个方法,用strongswan搭建,然后加一步:进sysctl.conf将ipv4转发打开即可。
& &179 天前
我当时参考这个文档(http://zh.opensuse.org/SDB:Setup_Ipsec_VPN_with_Strongswan#.E4.BB.80.E4.B9.88.E6.98.AF_IPsec.EF.BC.9F)搭建成功的,不过我用的是CentOS 6.5 on Linode VPS,半年来运行非常稳定。
& &179 天前
@ 当然已经升级到8.1了啊@ @ 非常感谢两位的链接, 搭建成功@ 我使用2楼的教程, 搭建成功了, ubuntu 14.04 on Linode VPS !
& · & 1255 人在线 & 最高记录 1298 & · &
创意工作者们的社区
Lovingly made by OLIVIDA
VERSION: 3.8.0 · 36ms · UTC 05:53 · PVG 13:53 · LAX 21:53 · JFK 00:53? Do have faith in what you're doing.

我要回帖

更多关于 centos strongswan 的文章

 

随机推荐