CentOS架IKEv2 VPN Server - Linux

Catherine avatar
By Catherine
at 2014-04-17T23:42

Table of Contents

最近我的手機Windows Phone 8.1 DP支援了IKEv2協定的VPN,
所以我就想在CentOS 6.5上架IKEv2的VPN server,使得手機也能連上。
我用的VPN server軟體是strongswan。
我試了一天才試出來。網路上有些資料,但有的沒講很清楚,只能try and error。
以下我就把設定IKEv2 VPN server的指令步驟寫出來,也有寫一些註解(英文),
有問題再問我,我有空再回應。

yum install strongswan openssl

# Create CA
## See:
http://www.topdog.za.net/2012/08/23/iphone-ipad-mac-osx-ipsec-vpn-with-strongswan-5-on-centos-rhel-6/
cd /etc/pki/tls/misc
## Common Name is arbitray, e.g. My CA.
./CA -newca
echo 00 > /etc/pki/CA/crlnumber
openssl ca -gencrl -out /etc/pki/CA/crl.pem
ln -s /etc/pki/CA/cacert.pem /etc/strongswan/ipsec.d/cacerts/
ln -s /etc/pki/CA/crl.pem /etc/strongswan/ipsec.d/crls/

# Create the server certificate
## Add extendedKeyUsage and subjectAltName lines under [ usr_cert ] in
openssl.cnf.
## See: http://wiki.strongswan.org/projects/strongswan/wiki/Win7CertReq
## E.g:
## extendedKeyUsage = serverAuth
## subjectAltName=IP:your.vpn.server.ip
## or subjectAltName=DNS:your.vpn.server.dns
vim ../openssl.cnf

## Common Name must be equal to the IP or the DNS set in subjectAltName!
## E.g Common Name is your.vpn.server.ip
## Please remeber the password. You will use it later in ipsec.secrets.
./CA -newreq
./CA -sign
mv newcert.pem /etc/strongswan/ipsec.d/certs/your.vpn.server.ip.pem
mv newkey.pem /etc/strongswan/ipsec.d/private/your.vpn.server.ip.key

## Add this line to ipsec.secrets:
## : RSA your.vpn.server.ip.key "password of your.vpn.server.ip.key"
vim /etc/strongswan/ipsec.secrets
## If you want to use EAP-MSCHAPV2 for a client "jack" and his password
"passwd",
## add this line to ipsec.secrets:
## jack : EAP "passwd"

# Create the client certificate
## Uncomment extendedKeyUsage and subjectAltName in openssl.cnf!
## Common Name is arbitray, e.g. Client Test.
./CA -newreq
./CA -sign
## Export for Windows.
openssl pkcs12 -export -in newcert.pem -inkey newkey.pem -certfile /etc/pki/CA/cacert.pem -out client.p12

# Import the certificate to Windows 7 tutorial:
## http://wiki.strongswan.org/projects/strongswan/wiki/Win7Certs

# NAT
echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -s 10.71.132.0/24 -o eth0 -j MASQUERADE

# Import client.p12 to Windows Phone 8.1 DP.
## Import through IE or OneDrive.
## Then: go to Windows Phone/Settings/VPN/On/add/Connect using/user
name+password/fill "jack" and "passwd"/...

# Example setting files
--------------------------- ipsec.conf -------------------------
# basic configuration
config setup

# Add connections here.
conn %default
keyexchange=ikev2
ike=aes256-sha1-modp1024!
esp=aes256-sha1!
dpdaction=clear
dpddelay=300s
rekey=no
leftfirewall=yes
left=%any
leftsubnet=0.0.0.0/0
leftauth=pubkey
leftcert=your.vpn.server.ip.pem
[email protected]
right=%any
rightsourceip=10.71.132.1/24
auto=add

conn win-pubkey
rightauth=pubkey
eap_identity=%any

conn win-eap-mschapv2
rightauth=eap-mschapv2
rightsendcert=never
eap_identity=%any

--------------------------- ipsec.secrets -------------------------
: RSA your.vpn.server.ip.key "password of your.vpn.server.ip.key"
jack : EAP "passwd"

--------------------------- strongswan.conf -------------------------
charon {
load_modular = yes
plugins {
include strongswan.d/charon/*.conf
}
# Set the DNS server.
dns1 = 8.8.8.8
#dns2 = x.x.x.x
}

include strongswan.d/*.conf

--
楞嚴咒(附注音):
http://sdrv.ms/130iapv

--
Tags: Linux

All Comments

區域網路要瀏覽網頁之問題?

Ula avatar
By Ula
at 2014-04-17T16:03
各位大大好~~ 剛開始摸索linux不久,目前碰到的問題描述如下: 在一區域網路中架設一測試網頁,想讓其它部電腦可以利用IP連結至此網頁, 但目前只有本部電腦可以連結成功,其他電腦則失敗,所以想請教大家提供 可以解決此問題之方向。 P.S. 已尋找鳥哥私房菜裡的相關資料但是還是毫無頭緒andgt; ...

apache目錄驗證經過squid

Andy avatar
By Andy
at 2014-04-17T15:28
我有架一個squid的reverse proxy server user=andgt;squid server=andgt; web server 網頁身分驗證會失敗 但 user=andgt;web server 就會成功驗證 請問是哪裡還需要設定啥東西嗎? - ...

Linux C跑Glpk套件疑問!?

James avatar
By James
at 2014-04-16T22:35
各位板友大家好, 小弟目前用Glpk求解二元決策變數線性規劃問題, 是假設有三個家電,將一天切割成5個時段,做排程規劃。 目前先採用一次性規劃,故矩陣為8*15,共有120個係數。 這樣的條件狀況下能夠順利求解,並顯示決策變數。 不過...當我把一天切割成24個時段做排程規劃後,故矩陣為27*72,共有1 ...

ssh連線問題

Daph Bay avatar
By Daph Bay
at 2014-04-16T18:21
實驗室是共用ip,請問要如何架設我這台電腦的ssh server 我已經試過 ssh usernameat實驗室ip andgt; 失敗,等待畫面沒回應.. 也申請了no-ip, ssh xxx.no-ip.organdgt; 一樣沒回應... 有人可以告訴我差再哪邊嗎? 架設ssh server還有 ...

Canonical 在臺灣的工作機會

Frederica avatar
By Frederica
at 2014-04-16T16:50
最近多了三個新的工作機會 工作職稱:Software Engineer - Kernel 工作內容:http://bit.ly/1eyHZDC Linux 系統相關偏底層 工作地點:台北 101 大樓 工作職稱:Software Engineer 工作內容:http://bit.ly/1eyI0aD Ub ...