{"id":171,"date":"2022-09-13T19:56:40","date_gmt":"2022-09-13T11:56:40","guid":{"rendered":"https:\/\/www.yiyuanlt.cn\/?p=171"},"modified":"2022-09-13T19:56:40","modified_gmt":"2022-09-13T11:56:40","slug":"centos-ubuntu%e4%b8%80%e9%94%ae%e5%ae%89%e8%a3%85ipsec-ikev2-vpn%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.yiyuanlt.cn\/index.php\/2022\/09\/13\/centos-ubuntu%e4%b8%80%e9%94%ae%e5%ae%89%e8%a3%85ipsec-ikev2-vpn%e6%9c%8d%e5%8a%a1%e5%99%a8\/","title":{"rendered":"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668"},"content":{"rendered":"\n<p>1\u3001\u5728azure\u4e0a\u521b\u5efaubuntu\u865a\u62df\u673a \u9009\u62e9v15.04 server \u7248\u672c<\/p>\n\n\n\n<p>2\u3001\u6dfb\u52a0\u7aef\u53e3\u53f7<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791159-4.png\" alt=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" title=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" ><img decoding=\"async\" src=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791159-4.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>3\u3001\u8fdc\u7a0b\u684c\u9762\u5230<\/p>\n\n\n\n<p>\u547d\u4ee4\u884c \u8f93\u5165 sudo su \u8f93\u5165\u521b\u5efa ubuntu\u865a\u62df\u673a \u65f6\u5019\u7684 \u5bc6\u7801<\/p>\n\n\n\n<p>\u5207\u6362\u5230root\u8eab\u4efd\u3002<\/p>\n\n\n\n<p>4\u3001\u5f00\u59cb\u521b\u5efa ipsec\/ikev2 vpn \u670d\u52a1\u5668<\/p>\n\n\n\n<p>\u3010\u6ce8\u3011 \u6211\u9009\u62e9\u7684\u662f Xen\u3001KVM \u7684vps\u7c7b\u578b<\/p>\n\n\n\n<p>\u3010\u6ce8\u3011\u4fee\u6539\u540e \u6587\u4ef6 \u4e0d\u751f\u6548 \u5219\u91cd\u65b0\u542f\u52a8\u865a\u62df\u673a<\/p>\n\n\n\n<p>\u3010\u6ce8\u3011win7\u5ba2\u6237\u7aef\u8fde\u63a5vpn \u9700\u8981\u8bc1\u4e66\u5b89\u88c5\u5230 \u8ba1\u7b97\u673a\u8d26\u6237\u7684 \u53d7\u4fe1\u4efb\u7684\u6839\u8bc1\u4e66\u9881\u53d1\u673a\u6784<\/p>\n\n\n\n<p>\u5177\u4f53\u5982\u4e0b\uff1a<br>1.\u4e0b\u8f7d\u811a\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wget https:\/\/raw.githubusercontent.com\/quericy\/one-key-ikev2-vpn\/master\/one-key-ikev2.sh<\/pre>\n\n\n\n<p>2.\u8fd0\u884c\uff08\u5982\u679c\u6709\u9700\u8981\u4f7f\u7528\u81ea\u5df1\u5df2\u6709\u7684\u6839\u8bc1\u4e66\uff0c\u8bf7\u5c06\u79c1\u94a5\u547d\u540d\u4e3aca.cert\uff0c\u5c06\u6839\u8bc1\u4e66\u547d\u540d\u4e3aca.cert.pem\uff0c\u653e\u5230\u811a\u672c\u7684\u76f8\u540c\u76ee\u5f55\u4e0b\u518d\u8fd0\u884c\u8be5\u811a\u672c\uff0c\u6ca1\u6709\u8bc1\u4e66\u7684\u8bdd\u5c06\u81ea\u52a8\u751f\u6210\u81ea\u7b7e\u540d\u8bc1\u4e66\u54af\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod +x one-key-ikev2.sh\nbash one-key-ikev2.sh<\/pre>\n\n\n\n<p>3.\u7b49\u5f85\u81ea\u52a8\u914d\u7f6e\u90e8\u5206\u5185\u5bb9\u540e\uff0c\u9009\u62e9vps\u7c7b\u578b\uff08OpenVZ\u8fd8\u662fXen\u3001KVM\uff09\uff0c\u9009\u9519\u5c06\u65e0\u6cd5\u6210\u529f\u8fde\u63a5\uff0c\u8bf7\u52a1\u5fc5\u6838\u5b9e\u670d\u52a1\u5668\u7684\u7c7b\u578b\u3002\u8f93\u5165\u670d\u52a1\u5668ip\u6216\u8005\u7ed1\u5b9a\u7684\u57df\u540d\uff08\u8fde\u63a5vpn\u65f6\u670d\u52a1\u5668\u5730\u5740\u5c06\u9700\u8981\u4e0e\u6b64\u4fdd\u6301\u4e00\u81f4\uff09\uff0c\u4ee5\u53ca\u8bc1\u4e66\u7684\u76f8\u5173\u4fe1\u606f\uff08C\uff0cO\uff0cCN\uff09\uff0c\u4f7f\u7528\u81ea\u5df1\u7684\u6839\u8bc1\u4e66\u7684\u8bdd\uff0cC\uff0cO\uff0cCN\u7684\u503c\u9700\u8981\u4e0e\u6839\u8bc1\u4e66\u4e00\u81f4\uff0c\u4e3a\u7a7a\u5c06\u4f7f\u7528\u9ed8\u8ba4\u503c\uff08default value\uff09\uff0c\u786e\u8ba4\u65e0\u8bef\u540e\u6309\u4efb\u610f\u952e\u7ee7\u7eed<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791159-54.png\" alt=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" title=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" ><img decoding=\"async\" src=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791159-54.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>4.\u8f93\u5165\u4e24\u6b21pkcs12\u8bc1\u4e66\u7684\u5bc6\u7801\uff08\u53ef\u4ee5\u4e3a\u7a7a\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791160-18.png\" alt=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" title=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" ><img decoding=\"async\" src=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791160-18.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>5.\u770b\u5230install success\u5b57\u6837\u5373\u8868\u793a\u5b89\u88c5\u6210\u529f\u3002\u9ed8\u8ba4\u7528\u6237\u540d\u5bc6\u7801\u5c06\u4ee5\u9ec4\u5b57\u663e\u793a\uff0c\u53ef\u6839\u636e\u63d0\u793a\u81ea\u884c\u4fee\u6539\u6587\u4ef6\u4e2d\u7684\u7528\u6237\u540d\u5bc6\u7801\u3002\uff08WindowsPhone8.1\u7684\u7528\u6237\u8bf7\u5c06\u7528\u6237\u540dmyUserNames\u4fee\u6539\u4e3a%any \uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u7531\u4e8e\u57df\u7684\u95ee\u9898\u65e0\u6cd5\u8fde\u63a5\uff0c\u5177\u4f53\u53c2\u89c1<a href=\"http:\/\/quericy.me\/blog\/512\" rel=\"noreferrer noopener\" target=\"_blank\" rel=\"nofollow\" >\u8fd9\u7bc7\u6587\u7ae0<\/a>\u4e2d\u7684\u8bf4\u660e\uff09<\/p>\n\n\n\n<p>6.\u5c06\u63d0\u793a\u4fe1\u606f\u4e2d\u7684\u8bc1\u4e66\u6587\u4ef6ca.cert.pe\u62f7\u8d1d\u5230\u5ba2\u6237\u7aef\uff0c\u4fee\u6539\u540e\u7f00\u540d\u4e3a.cer\u540e\u5bfc\u5165\u3002ios\u8bbe\u5907\u4f7f\u7528Ikev1\u65e0\u9700\u5bfc\u5165\u8bc1\u4e66\uff0c\u800c\u662f\u9700\u8981\u5728\u8fde\u63a5\u65f6\u8f93\u5165\u5171\u4eab\u5bc6\u94a5\uff0c\u5171\u4eab\u5bc6\u94a5\u5373\u662f\u63d0\u793a\u4fe1\u606f\u4e2d\u7684\u9ec4\u5b57PSK.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791160-14.png\" alt=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" title=\"Centos\/Ubuntu\u4e00\u952e\u5b89\u88c5IPSEC\/IKEV2 VPN\u670d\u52a1\u5668\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" ><img decoding=\"async\" src=\"https:\/\/cdn.aeink.com\/\/content\/uploadfile\/202208\/AEimg-1660791160-14.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>\u670d\u52a1\u5668\u91cd\u542f\u540e\u9ed8\u8ba4ipsec\u4e0d\u4f1a\u81ea\u542f\u52a8\uff0c\u8bf7\u81ea\u884c\u6dfb\u52a0\uff0c\u6216\u4f7f\u7528\u547d\u4ee4\u624b\u52a8\u5f00\u542f\uff1a<\/p>\n\n\n\n<p>&nbsp;<br>\u542f\u52a8\u65f6\u95f4<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ipsec start<\/pre>\n\n\n\n<p>\u8fde\u4e0a\u670d\u52a1\u5668\u540e\u65e0\u6cd5\u94fe\u63a5\u5916\u7f51\uff1a<\/p>\n\n\n\n<p>&nbsp;<br>vim \/etc\/sysctl.conf<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim \/etc\/sysctl.conf\n\n\u4fee\u6539net.ipv4.ip_forward=1\u540e\u4fdd\u5b58\u5e76\u5173\u95ed\u6587\u4ef6 \u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\u5237\u65b0sysctl\uff1a\n\nsysctl -p<\/pre>\n\n\n\n<p>\u5982\u9047\u62a5\u9519\u4fe1\u606f\uff0c\u8bf7\u91cd\u65b0\u6253\u5f00\/etc\/syctl\u5e76\u5c06\u62a5\u9519\u7684\u90a3\u4e9b\u4ee3\u7801\u7528#\u53f7\u6ce8\u91ca\uff0c\u4fdd\u5b58\u540e\u518d\u5237\u65b0sysctl\u76f4\u81f3\u4e0d\u4f1a\u62a5\u9519\u4e3a\u6b62\u3002<\/p>\n\n\n\n<p>bash\u811a\u672c\u6e90\u7801\uff08\u70b9\u51fb\u5c55\u5f00\uff09<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>#! \/bin\/bash\nPATH=\/bin:\/sbin:\/usr\/bin:\/usr\/sbin:\/usr\/<strong>local<\/strong>\/bin:\/usr\/<strong>local<\/strong>\/sbin:~\/bin\nexport PATH\n#===============================================================================================\n#   System Required:  CentOS6.x (32bit\/64bit) or Ubuntu\n#   Description:  Install IKEV2 VPN for CentOS and Ubuntu\n#   Author: quericy\n#   Intro:  http:\/\/quericy.me\/blog\/699\n#===============================================================================================\n \nclear\necho \"#############################################################\"\necho \"# Install IKEV2 VPN for CentOS6.x (32bit\/64bit) or Ubuntu\"\necho \"# Intro: http:\/\/quericy.me\/blog\/699\"\necho \"#\"\necho \"# Author:quericy\"\necho \"#\"\necho \"#############################################################\"\necho \"\"\n \n# Install IKEV2\n<strong>function<\/strong> install_ikev2(){\n\trootness\n\tdisable_selinux\n\tget_my_ip\n\tget_system\n\tyum_install\n\tpre_install\n\tdownload_files\n\tsetup_strongswan\n\tget_key\n\tconfigure_ipsec\n\tconfigure_strongswan\n\tconfigure_secrets\n\tiptables_set\n\tipsec start\n\tsuccess_info\n}\n \n# Make sure only root can run our script\n<strong>function<\/strong> rootness(){\n<strong>if<\/strong> &#91;&#91; $EUID -ne 0 ]]; <strong>then<\/strong>\n   echo \"Error:This script must be run as root!\" 1>&amp;2\n   exit 1\n<strong>fi<\/strong>\n}\n \n# Disable selinux\n<strong>function<\/strong> disable_selinux(){\n<strong>if<\/strong> &#91; -s \/etc\/selinux\/config ] &amp;&amp; grep 'SELINUX=enforcing' \/etc\/selinux\/config; <strong>then<\/strong>\n    sed -i 's\/SELINUX=enforcing\/SELINUX=disabled\/g' \/etc\/selinux\/config\n    setenforce 0\n<strong>fi<\/strong>\n}\n \n# Get IP address of the server\n<strong>function<\/strong> get_my_ip(){\n    echo \"Preparing, Please wait a moment...\"\n    IP=`curl -s checkip.dyndns.com | cut -d' ' -f 6  | cut -d'&lt;' -f 1`\n    <strong>if<\/strong> &#91; -z $IP ]; <strong>then<\/strong>\n        IP=`curl -s ifconfig.me\/ip`\n    <strong>fi<\/strong>\n}\n \n# Ubuntu or CentOS\n<strong>function<\/strong> get_system(){\n\tget_system_str=`cat \/etc\/issue`\n\techo \"$get_system_str\" |grep -q \"CentOS\"\n\t<strong>if<\/strong>  &#91; $? -eq 0 ]\n\t<strong>then<\/strong>\n\t\tsystem_str=\"0\"\n\t<strong>else<\/strong>\n\t\techo \"$get_system_str\" |grep -q \"Ubuntu\"\n\t\t<strong>if<\/strong> &#91; $? -eq 0 ]\n\t\t<strong>then<\/strong>\n\t\t\tsystem_str=\"1\"\n\t\t<strong>else<\/strong>\n\t\t\techo \"This Script must be running at the CentOS or Ubuntu!\"\n\t\t\texit 1\n\t\t<strong>fi<\/strong>\n\t<strong>fi<\/strong>\n \n}\n \n# Pre-installation settings\n<strong>function<\/strong> pre_install(){\n\techo \"#############################################################\"\n\techo \"# Install IKEV2 VPN for CentOS6.x (32bit\/64bit) or Ubuntu\"\n\techo \"# Intro: http:\/\/quericy.me\/blog\/699\"\n\techo \"#\"\n\techo \"# Author:quericy\"\n\techo \"#\"\n\techo \"#############################################################\"\n\techo \"\"\n    echo \"please choose the type of your VPS(Xen\u3001KVM: 1  ,  OpenVZ: 2):\"\n    read -p \"your choice(1 or 2):\" os_choice\n    <strong>if<\/strong> &#91; \"$os_choice\" = \"1\" ]; <strong>then<\/strong>\n        os=\"1\"\n\t\tos_str=\"Xen\u3001KVM\"\n\t\t<strong>else<\/strong>\n\t\t\t<strong>if<\/strong> &#91; \"$os_choice\" = \"2\" ]; <strong>then<\/strong>\n\t\t\t\tos=\"2\"\n\t\t\t\tos_str=\"OpenVZ\"\n\t\t\t\t<strong>else<\/strong>\n\t\t\t\techo \"wrong choice!\"\n\t\t\t\texit 1\n\t\t\t<strong>fi<\/strong>\n    <strong>fi<\/strong>\n\techo \"please input the ip (or domain) of your VPS:\"\n    read -p \"ip or domain(default_vale:${IP}):\" vps_ip\n\t<strong>if<\/strong> &#91; \"$vps_ip\" = \"\" ]; <strong>then<\/strong>\n\t\tvps_ip=$IP\n\t<strong>fi<\/strong>\n\techo \"please input the cert country(C):\"\n    read -p \"C(default value:com):\" my_cert_c\n\t<strong>if<\/strong> &#91; \"$my_cert_c\" = \"\" ]; <strong>then<\/strong>\n\t\tmy_cert_c=\"com\"\n\t<strong>fi<\/strong>\n\techo \"please input the cert organization(O):\"\n    read -p \"O(default value:myvpn):\" my_cert_o\n\t<strong>if<\/strong> &#91; \"$my_cert_o\" = \"\" ]; <strong>then<\/strong>\n\t\tmy_cert_o=\"myvpn\"\n\t<strong>fi<\/strong>\n\techo \"please input the cert common name(CN):\"\n    read -p \"CN(default value:VPN CA):\" my_cert_cn\n\t<strong>if<\/strong> &#91; \"$my_cert_cn\" = \"\" ]; <strong>then<\/strong>\n\t\tmy_cert_cn=\"VPN CA\"\n\t<strong>fi<\/strong>\n\techo \"####################################\"\n    get_char(){\n        SAVEDSTTY=`stty -g`\n        stty -echo\n        stty cbreak\n        dd <strong>if<\/strong>=\/dev\/tty bs=1 count=1 2> \/dev\/null\n        stty -raw\n        stty echo\n        stty $SAVEDSTTY\n    }\n    echo \"Please confirm the information:\"\n\techo \"\"\n\techo -e \"the type of your server: &#91;\\033&#91;32;1m$os_str\\033&#91;0m]\"\n\techo -e \"the ip(or domain) of your server: &#91;\\033&#91;32;1m$vps_ip\\033&#91;0m]\"\n\techo -e \"the cert_info:&#91;\\033&#91;32;1mC=${my_cert_c}, O=${my_cert_o}\\033&#91;0m]\"\n\techo \"\"\n    echo \"Press any key to start...or Press Ctrl+C to cancel\"\n\tchar=`get_char`\n\t#Current folder\n    cur_dir=`pwd`\n    cd $cur_dir\n}\n \n#install necessary lib\n<strong>function<\/strong> yum_install(){\n\t<strong>if<\/strong> &#91; \"$system_str\" = \"0\" ]; <strong>then<\/strong>\n\tyum -y update\n\tyum -y install pam-devel openssl-devel make gcc\n\t<strong>else<\/strong>\n\tapt-get -y update\n\tapt-get -y install libpam0g-dev libssl-dev make gcc\n\t<strong>fi<\/strong>\n}\n \n# Download strongswan\n<strong>function<\/strong> download_files(){\n    <strong>if<\/strong> &#91; -f strongswan.tar.gz ];<strong>then<\/strong>\n        echo -e \"strongswan.tar.gz &#91;\\033&#91;32;1mfound\\033&#91;0m]\"\n    <strong>else<\/strong>\n        <strong>if<\/strong> ! wget http:\/\/download.strongswan.org\/strongswan.tar.gz;<strong>then<\/strong>\n            echo \"Failed to download strongswan.tar.gz\"\n            exit 1\n        <strong>fi<\/strong>\n    <strong>fi<\/strong>\n    tar xzf strongswan.tar.gz\n    <strong>if<\/strong> &#91; $? -eq 0 ];<strong>then<\/strong>\n        cd $cur_dir\/strongswan-*\/\n    <strong>else<\/strong>\n        echo \"\"\n        echo \"Unzip strongswan.tar.gz failed! Please visit http:\/\/quericy.me\/blog\/699 and contact.\"\n        exit 1\n    <strong>fi<\/strong>\n}\n \n# configure and install strongswan\n<strong>function<\/strong> setup_strongswan(){\n\t<strong>if<\/strong> &#91; \"$os\" = \"1\" ]; <strong>then<\/strong>\n\t\t.\/configure  --enable-eap-identity --enable-eap-md5 \\\n--enable-eap-mschapv2 --enable-eap-tls --enable-eap-ttls --enable-eap-peap  \\\n--enable-eap-tnc --enable-eap-dynamic --enable-eap-radius --enable-xauth-eap  \\\n--enable-xauth-pam  --enable-dhcp  --enable-openssl  --enable-addrblock --enable-unity  \\\n--enable-certexpire --enable-radattr --enable-tools --enable-openssl --disable-gmp\n \n\t<strong>else<\/strong>\n\t\t.\/configure  --enable-eap-identity --enable-eap-md5 \\\n--enable-eap-mschapv2 --enable-eap-tls --enable-eap-ttls --enable-eap-peap  \\\n--enable-eap-tnc --enable-eap-dynamic --enable-eap-radius --enable-xauth-eap  \\\n--enable-xauth-pam  --enable-dhcp  --enable-openssl  --enable-addrblock --enable-unity  \\\n--enable-certexpire --enable-radattr --enable-tools --enable-openssl --disable-gmp --enable-kernel-libipsec\n \n\t<strong>fi<\/strong>\n\tmake; make install\n}\n \n# configure cert and key\n<strong>function<\/strong> get_key(){\n\tcd $cur_dir\n    <strong>if<\/strong> &#91; -f ca.pem ];<strong>then<\/strong>\n        echo -e \"ca.pem &#91;\\033&#91;32;1mfound\\033&#91;0m]\"\n    <strong>else<\/strong>\n        echo -e \"ca.pem &#91;\\033&#91;32;1mauto create\\032&#91;0m]\"\n\t\techo \"auto create ca.pem ...\"\n\t\tipsec pki --gen --outform pem > ca.pem\n    <strong>fi<\/strong>\n \n\t<strong>if<\/strong> &#91; -f ca.cert.pem ];<strong>then<\/strong>\n        echo -e \"ca.cert.pem &#91;\\033&#91;32;1mfound\\033&#91;0m]\"\n    <strong>else<\/strong>\n        echo -e \"ca.cert.pem &#91;\\032&#91;33;1mauto create\\032&#91;0m]\"\n\t\techo \"auto create ca.cert.pem ...\"\n\t\tipsec pki --self --<strong>in<\/strong> ca.pem --dn \"C=${my_cert_c}, O=${my_cert_o}, CN=${my_cert_cn}\" --ca --outform pem >ca.cert.pem\n    <strong>fi<\/strong>\n\t<strong>if<\/strong> &#91; ! -d my_key ];<strong>then<\/strong>\n        mkdir my_key\n    <strong>fi<\/strong>\n\tmv ca.pem my_key\/ca.pem\n\tmv ca.cert.pem my_key\/ca.cert.pem\n\tcd my_key\n\tipsec pki --gen --outform pem > server.pem\n\tipsec pki --pub --<strong>in<\/strong> server.pem | ipsec pki --issue --cacert ca.cert.pem \\\n--cakey ca.pem --dn \"C=${my_cert_c}, O=${my_cert_o}, CN=${vps_ip}\" \\\n--san=\"${vps_ip}\" --flag serverAuth --flag ikeIntermediate \\\n--outform pem > server.cert.pem\n\tipsec pki --gen --outform pem > client.pem\n\tipsec pki --pub --<strong>in<\/strong> client.pem | ipsec pki --issue --cacert ca.cert.pem --cakey ca.pem --dn \"C=${my_cert_c}, O=${my_cert_o}, CN=VPN Client\" --outform pem > client.cert.pem\n\techo \"configure the pkcs12 cert password(Can be empty):\"\n\topenssl pkcs12 -export -inkey client.pem -<strong>in<\/strong> client.cert.pem -name \"client\" -certfile ca.cert.pem -caname \"${my_cert_cn}\"  -out client.cert.p12\n\techo \"####################################\"\n    get_char(){\n        SAVEDSTTY=`stty -g`\n        stty -echo\n        stty cbreak\n        dd <strong>if<\/strong>=\/dev\/tty bs=1 count=1 2> \/dev\/null\n        stty -raw\n        stty echo\n        stty $SAVEDSTTY\n    }\n    echo \"Press any key to install ikev2 VPN cert\"\n\tcp -r ca.cert.pem \/usr\/<strong>local<\/strong>\/etc\/ipsec.d\/cacerts\/\n\tcp -r server.cert.pem \/usr\/<strong>local<\/strong>\/etc\/ipsec.d\/certs\/\n\tcp -r server.pem \/usr\/<strong>local<\/strong>\/etc\/ipsec.d\/private\/\n\tcp -r client.cert.pem \/usr\/<strong>local<\/strong>\/etc\/ipsec.d\/certs\/\n\tcp -r client.pem  \/usr\/<strong>local<\/strong>\/etc\/ipsec.d\/private\/\n \n}\n \n# configure the ipsec.conf\n<strong>function<\/strong> configure_ipsec(){\n cat > \/usr\/<strong>local<\/strong>\/etc\/ipsec.conf&lt;&lt;-EOF\nconfig setup\n    uniqueids=never \n \nconn iOS_cert\n    keyexchange=ikev1\n    fragmentation=yes\n    left=%defaultroute\n    leftauth=pubkey\n    leftsubnet=0.0.0.0\/0\n    leftcert=server.cert.pem\n    right=%any\n    rightauth=pubkey\n    rightauth2=xauth\n    rightsourceip=10.31.2.0\/24\n    rightcert=client.cert.pem\n    auto=add\n \nconn android_xauth_psk\n    keyexchange=ikev1\n    left=%defaultroute\n    leftauth=psk\n    leftsubnet=0.0.0.0\/0\n    right=%any\n    rightauth=psk\n    rightauth2=xauth\n    rightsourceip=10.31.2.0\/24\n    auto=add\n \nconn networkmanager-strongswan\n    keyexchange=ikev2\n    left=%defaultroute\n    leftauth=pubkey\n    leftsubnet=0.0.0.0\/0\n    leftcert=server.cert.pem\n    right=%any\n    rightauth=pubkey\n    rightsourceip=10.31.2.0\/24\n    rightcert=client.cert.pem\n    auto=add\n \nconn windows7\n    keyexchange=ikev2\n    ike=aes256-sha1-modp1024!\n    rekey=no\n    left=%defaultroute\n    leftauth=pubkey\n    leftsubnet=0.0.0.0\/0\n    leftcert=server.cert.pem\n    right=%any\n    rightauth=eap-mschapv2\n    rightsourceip=10.31.2.0\/24\n    rightsendcert=never\n    eap_identity=%any\n    auto=add\n \nEOF\n}\n \n# configure the strongswan.conf\n<strong>function<\/strong> configure_strongswan(){\n cat > \/usr\/<strong>local<\/strong>\/etc\/strongswan.conf&lt;&lt;-EOF\n charon {\n        load_modular = yes\n        duplicheck.enable = no\n        compress = yes\n        plugins {\n                include strongswan.d\/charon\/*.conf\n        }\n        dns1 = 8.8.8.8\n        dns2 = 8.8.4.4\n        nbns1 = 8.8.8.8\n        nbns2 = 8.8.4.4\n}\ninclude strongswan.d\/*.conf\nEOF\n}\n \n# configure the ipsec.secrets\n<strong>function<\/strong> configure_secrets(){\n\tcat > \/usr\/<strong>local<\/strong>\/etc\/ipsec.secrets&lt;&lt;-EOF\n: RSA server.pem\n: PSK \"myPSKkey\"\n: XAUTH \"myXAUTHPass\"\nmyUserName %any : EAP \"myUserPass\"\n\tEOF\n}\n \n# iptables set\n<strong>function<\/strong> iptables_set(){\n    sysctl -w net.ipv4.ip_forward=1\n    <strong>if<\/strong> &#91; \"$os\" = \"1\" ]; <strong>then<\/strong>\n\t\tiptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT\n\t\tiptables -A FORWARD -s 10.31.0.0\/24  -j ACCEPT\n\t\tiptables -A FORWARD -s 10.31.1.0\/24  -j ACCEPT\n\t\tiptables -A FORWARD -s 10.31.2.0\/24  -j ACCEPT\n\t\tiptables -A INPUT -i eth0 -p esp -j ACCEPT\n\t\tiptables -A INPUT -i eth0 -p udp --dport 500 -j ACCEPT\n\t\tiptables -A INPUT -i eth0 -p tcp --dport 500 -j ACCEPT\n\t\tiptables -A INPUT -i eth0 -p udp --dport 4500 -j ACCEPT\n\t\tiptables -A INPUT -i eth0 -p udp --dport 1701 -j ACCEPT\n\t\tiptables -A INPUT -i eth0 -p tcp --dport 1723 -j ACCEPT\n\t\tiptables -A FORWARD -j REJECT\n\t\tiptables -t nat -A POSTROUTING -s 10.31.0.0\/24 -o eth0 -j MASQUERADE\n\t\tiptables -t nat -A POSTROUTING -s 10.31.1.0\/24 -o eth0 -j MASQUERADE\n\t\tiptables -t nat -A POSTROUTING -s 10.31.2.0\/24 -o eth0 -j MASQUERADE\n\t<strong>else<\/strong>\n\t\tiptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT\n\t\tiptables -A FORWARD -s 10.31.0.0\/24  -j ACCEPT\n\t\tiptables -A FORWARD -s 10.31.1.0\/24  -j ACCEPT\n\t\tiptables -A FORWARD -s 10.31.2.0\/24  -j ACCEPT\n\t\tiptables -A INPUT -i venet0 -p esp -j ACCEPT\n\t\tiptables -A INPUT -i venet0 -p udp --dport 500 -j ACCEPT\n\t\tiptables -A INPUT -i venet0 -p tcp --dport 500 -j ACCEPT\n\t\tiptables -A INPUT -i venet0 -p udp --dport 4500 -j ACCEPT\n\t\tiptables -A INPUT -i venet0 -p udp --dport 1701 -j ACCEPT\n\t\tiptables -A INPUT -i venet0 -p tcp --dport 1723 -j ACCEPT\n\t\tiptables -A FORWARD -j REJECT\n\t\tiptables -t nat -A POSTROUTING -s 10.31.0.0\/24 -o venet0 -j MASQUERADE\n\t\tiptables -t nat -A POSTROUTING -s 10.31.1.0\/24 -o venet0 -j MASQUERADE\n\t\tiptables -t nat -A POSTROUTING -s 10.31.2.0\/24 -o venet0 -j MASQUERADE\n    <strong>fi<\/strong>\n\t<strong>if<\/strong> &#91; \"$system_str\" = \"0\" ]; <strong>then<\/strong>\n\t\tservice iptables save\n\t<strong>else<\/strong>\n\t\tiptables-save > \/etc\/iptables.rules\n\t\tcat > \/etc\/network\/<strong>if<\/strong>-up.d\/iptables&lt;&lt;EOF\n#!\/bin\/sh\niptables-restore &lt; \/etc\/iptables.rules\nEOF\n\t\tchmod +x \/etc\/network\/<strong>if<\/strong>-up.d\/iptables\n\t<strong>fi<\/strong>\n}\n \n# echo the success info\n<strong>function<\/strong> success_info(){\n\techo \"#############################################################\"\n\techo -e \"#\"\n\techo -e \"# &#91;\\033&#91;32;1mInstall Successful\\033&#91;0m]\"\n\techo -e \"# There is the default login info of your VPN\"\n\techo -e \"# UserName:\\033&#91;33;1m myUserName\\033&#91;0m\"\n\techo -e \"# PassWord:\\033&#91;33;1m myUserPass\\033&#91;0m\"\n\techo -e \"# PSK:\\033&#91;33;1m myPSKkey\\033&#91;0m\"\n\techo -e \"# you can change UserName and PassWord in\\033&#91;32;1m \/usr\/local\/etc\/ipsec.secrets\\033&#91;0m\"\n\techo -e \"# you must copy the cert \\033&#91;32;1m ${cur_dir}\/my_key\/ca.cert.pem \\033&#91;0m to the client and install it.\"\n\techo -e \"#\"\n\techo -e \"#############################################################\"\n\techo -e \"\"\n}\n \n# Initialization step\ninstall_ikev2<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>\u5982\u9700Debian\u7cfb\u7edf\u7684IKEV2\u4e00\u952e\u5b89\u88c5\u811a\u672c\uff0c\u53ef\u53c2\u8003magic282\u7ae5\u978b\u7684\u4e00\u952e\u811a\u672c\uff1a<br>https:\/\/github.com\/magic282\/One-Key-L2TP-IKEV2-Setup<\/p>\n\n\n\n<p>\u8f6c\u8f7d\u81ea\u66f2\u745e\u65af Eden*\u7684\u535a\u5ba2<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u5728azure\u4e0a\u521b\u5efaubuntu\u865a\u62df\u673a \u9009\u62e9v15.04 server \u7248\u672c 2\u3001\u6dfb\u52a0\u7aef\u53e3\u53f7 3\u3001\u8fdc\u7a0b\u684c\u9762\u5230 \u547d\u4ee4\u884c \u8f93\u5165 su &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-sort"],"_links":{"self":[{"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":1,"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":172,"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/posts\/171\/revisions\/172"}],"wp:attachment":[{"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yiyuanlt.cn\/index.php\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}