荣耀之链论坛

 找回密码
 立即注册
搜索
查看: 2831|回复: 6

centos7安装L2TP服务端

[复制链接]

1325

主题

2372

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10262
发表于 2018-5-14 10:59 | 显示全部楼层 |阅读模式
https://blog.csdn.net/kxwinxp/article/details/78764013   #一键脚本  用这个试试 https://github.com/teddysun/across

用这个的一键脚本  

非常简单



至于linux怎么当客户端还在找
回复

使用道具 举报

1325

主题

2372

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10262
 楼主| 发表于 2018-5-14 11:15 | 显示全部楼层
WIN10连接方法
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PolicyAgent下新建“AllowL2TPWeakCrypto”,然后把值改成“1”
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PolicyAgent 在这个位置新建一个DWORD类型,名为AssumeUDPEncapsulationContextOnSendRule的键,将值修改为2 。

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Rasman\Paramete新建ProhibitIpSec,然后然后创建DWORD值为1
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Rasman\Paramete下找到“AllowL2TPWeakCrypto”,然后把值改成“1”


安卓和ios都正常使用就行了
回复 支持 反对

使用道具 举报

1325

主题

2372

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10262
 楼主| 发表于 2018-5-29 01:36 | 显示全部楼层
iptables -I INPUT -p udp -m multiport --dports 500,4500,1701 -j ACCEPT
iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
回复 支持 反对

使用道具 举报

1325

主题

2372

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10262
 楼主| 发表于 2019-2-11 06:57 | 显示全部楼层
  1. #!/usr/bin/env bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. #=======================================================================#
  5. #   System Supported:  CentOS 6+ / Debian 7+ / Ubuntu 12+               #
  6. #   Description: L2TP VPN Auto Installer                                #
  7. #   Author: Teddysun <i@teddysun.com>                                   #
  8. #   Intro:  https://teddysun.com/448.html                               #
  9. #=======================================================================#
  10. cur_dir=`pwd`

  11. libreswan_filename="libreswan-3.20"
  12. download_root_url="http://dl.teddysun.com/files"

  13. rootness(){
  14.     if [[ $EUID -ne 0 ]]; then
  15.        echo "Error:This script must be run as root!" 1>&2
  16.        exit 1
  17.     fi
  18. }

  19. tunavailable(){
  20.     if [[ ! -e /dev/net/tun ]]; then
  21.         echo "Error:TUN/TAP is not available!" 1>&2
  22.         exit 1
  23.     fi
  24. }

  25. disable_selinux(){
  26. if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
  27.     sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  28.     setenforce 0
  29. fi
  30. }

  31. get_opsy(){
  32.     [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
  33.     [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
  34.     [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
  35. }

  36. get_os_info(){
  37.     IP=$( ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1 )
  38.     [ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )

  39.     local cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
  40.     local cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
  41.     local freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
  42.     local tram=$( free -m | awk '/Mem/ {print $2}' )
  43.     local swap=$( free -m | awk '/Swap/ {print $2}' )
  44.     local up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=$1%60} {printf("%ddays, %d:%d:%d\n",a,b,c,d)}' /proc/uptime )
  45.     local load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' )
  46.     local opsy=$( get_opsy )
  47.     local arch=$( uname -m )
  48.     local lbit=$( getconf LONG_BIT )
  49.     local host=$( hostname )
  50.     local kern=$( uname -r )

  51.     echo "########## System Information ##########"
  52.     echo
  53.     echo "CPU model            : ${cname}"
  54.     echo "Number of cores      : ${cores}"
  55.     echo "CPU frequency        : ${freq} MHz"
  56.     echo "Total amount of ram  : ${tram} MB"
  57.     echo "Total amount of swap : ${swap} MB"
  58.     echo "System uptime        : ${up}"
  59.     echo "Load average         : ${load}"
  60.     echo "OS                   : ${opsy}"
  61.     echo "Arch                 : ${arch} (${lbit} Bit)"
  62.     echo "Kernel               : ${kern}"
  63.     echo "Hostname             : ${host}"
  64.     echo "IPv4 address         : ${IP}"
  65.     echo
  66.     echo "########################################"
  67. }

  68. check_sys(){
  69.     local checkType=$1
  70.     local value=$2

  71.     local release=''
  72.     local systemPackage=''

  73.     if [[ -f /etc/redhat-release ]]; then
  74.         release="centos"
  75.         systemPackage="yum"
  76.     elif cat /etc/issue | grep -Eqi "debian"; then
  77.         release="debian"
  78.         systemPackage="apt"
  79.     elif cat /etc/issue | grep -Eqi "ubuntu"; then
  80.         release="ubuntu"
  81.         systemPackage="apt"
  82.     elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
  83.         release="centos"
  84.         systemPackage="yum"
  85.     elif cat /proc/version | grep -Eqi "debian"; then
  86.         release="debian"
  87.         systemPackage="apt"
  88.     elif cat /proc/version | grep -Eqi "ubuntu"; then
  89.         release="ubuntu"
  90.         systemPackage="apt"
  91.     elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
  92.         release="centos"
  93.         systemPackage="yum"
  94.     fi

  95.     if [[ ${checkType} == "sysRelease" ]]; then
  96.         if [ "$value" == "$release" ];then
  97.             return 0
  98.         else
  99.             return 1
  100.         fi
  101.     elif [[ ${checkType} == "packageManager" ]]; then
  102.         if [ "$value" == "$systemPackage" ];then
  103.             return 0
  104.         else
  105.             return 1
  106.         fi
  107.     fi
  108. }

  109. rand(){
  110.     index=0
  111.     str=""
  112.     for i in {a..z}; do arr[index]=${i}; index=`expr ${index} + 1`; done
  113.     for i in {A..Z}; do arr[index]=${i}; index=`expr ${index} + 1`; done
  114.     for i in {0..9}; do arr[index]=${i}; index=`expr ${index} + 1`; done
  115.     for i in {1..10}; do str="$str${arr[$RANDOM%$index]}"; done
  116.     echo ${str}
  117. }

  118. is_64bit(){
  119.     if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
  120.         return 0
  121.     else
  122.         return 1
  123.     fi
  124. }

  125. download_file(){
  126.     if [ -s ${1} ]; then
  127.         echo "$1 [found]"
  128.     else
  129.         echo "$1 not found!!!download now..."
  130.         if ! wget -c -t3 -T60 ${download_root_url}/${1}; then
  131.             echo "Failed to download $1, please download it to ${cur_dir} directory manually and try again."
  132.             exit 1
  133.         fi
  134.     fi
  135. }

  136. versionget(){
  137.     if [[ -s /etc/redhat-release ]];then
  138.         grep -oE  "[0-9.]+" /etc/redhat-release
  139.     else
  140.         grep -oE  "[0-9.]+" /etc/issue
  141.     fi
  142. }

  143. centosversion(){
  144.     if check_sys sysRelease centos;then
  145.         local code=${1}
  146.         local version="`versionget`"
  147.         local main_ver=${version%%.*}
  148.         if [ "${main_ver}" == "${code}" ];then
  149.             return 0
  150.         else
  151.             return 1
  152.         fi
  153.     else
  154.         return 1
  155.     fi
  156. }

  157. debianversion(){
  158.     if check_sys sysRelease debian;then
  159.         local version=$( get_opsy )
  160.         local code=${1}
  161.         local main_ver=$( echo ${version} | sed 's/[^0-9]//g')
  162.         if [ "${main_ver}" == "${code}" ];then
  163.             return 0
  164.         else
  165.             return 1
  166.         fi
  167.     else
  168.         return 1
  169.     fi
  170. }

  171. version_check(){
  172.     if check_sys packageManager yum; then
  173.         if centosversion 5; then
  174.             echo "Error: CentOS 5 is not supported, Please re-install OS and try again."
  175.             exit 1
  176.         fi
  177.     fi
  178. }

  179. get_char(){
  180.     SAVEDSTTY=`stty -g`
  181.     stty -echo
  182.     stty cbreak
  183.     dd if=/dev/tty bs=1 count=1 2> /dev/null
  184.     stty -raw
  185.     stty echo
  186.     stty $SAVEDSTTY
  187. }

  188. preinstall_l2tp(){

  189.     echo
  190.     if [ -d "/proc/vz" ]; then
  191.         echo -e "\033[41;37m WARNING: \033[0m Your VPS is based on OpenVZ, and IPSec might not be supported by the kernel."
  192.         echo "Continue installation? (y/n)"
  193.         read -p "(Default: n)" agree
  194.         [ -z ${agree} ] && agree="n"
  195.         if [ "${agree}" == "n" ]; then
  196.             echo
  197.             echo "L2TP installation cancelled."
  198.             echo
  199.             exit 0
  200.         fi
  201.     fi
  202.     echo
  203.     echo "Please enter IP-Range:"
  204.     read -p "(Default Range: 192.168.18):" iprange
  205.     [ -z ${iprange} ] && iprange="192.168.18"

  206.     echo "Please enter PSK:"
  207.     read -p "(Default PSK: teddysun.com):" mypsk
  208.     [ -z ${mypsk} ] && mypsk="teddysun.com"

  209.     echo "Please enter Username:"
  210.     read -p "(Default Username: teddysun):" username
  211.     [ -z ${username} ] && username="teddysun"

  212.     password=`rand`
  213.     echo "Please enter ${username}'s password:"
  214.     read -p "(Default Password: ${password}):" tmppassword
  215.     [ ! -z ${tmppassword} ] && password=${tmppassword}

  216.     echo
  217.     echo "ServerIP:${IP}"
  218.     echo "Server Local IP:${iprange}.1"
  219.     echo "Client Remote IP Range:${iprange}.2-${iprange}.254"
  220.     echo "PSK:${mypsk}"
  221.     echo
  222.     echo "Press any key to start... or press Ctrl + C to cancel."
  223.     char=`get_char`

  224. }

  225. install_l2tp(){

  226.     mknod /dev/random c 1 9

  227.     if check_sys packageManager apt; then
  228.         apt-get -y update

  229.         if debianversion 7; then
  230.             if is_64bit; then
  231.                 local libnspr4_filename1="libnspr4_4.10.7-1_amd64.deb"
  232.                 local libnspr4_filename2="libnspr4-0d_4.10.7-1_amd64.deb"
  233.                 local libnspr4_filename3="libnspr4-dev_4.10.7-1_amd64.deb"
  234.                 local libnspr4_filename4="libnspr4-dbg_4.10.7-1_amd64.deb"
  235.                 local libnss3_filename1="libnss3_3.17.2-1.1_amd64.deb"
  236.                 local libnss3_filename2="libnss3-1d_3.17.2-1.1_amd64.deb"
  237.                 local libnss3_filename3="libnss3-tools_3.17.2-1.1_amd64.deb"
  238.                 local libnss3_filename4="libnss3-dev_3.17.2-1.1_amd64.deb"
  239.                 local libnss3_filename5="libnss3-dbg_3.17.2-1.1_amd64.deb"
  240.             else
  241.                 local libnspr4_filename1="libnspr4_4.10.7-1_i386.deb"
  242.                 local libnspr4_filename2="libnspr4-0d_4.10.7-1_i386.deb"
  243.                 local libnspr4_filename3="libnspr4-dev_4.10.7-1_i386.deb"
  244.                 local libnspr4_filename4="libnspr4-dbg_4.10.7-1_i386.deb"
  245.                 local libnss3_filename1="libnss3_3.17.2-1.1_i386.deb"
  246.                 local libnss3_filename2="libnss3-1d_3.17.2-1.1_i386.deb"
  247.                 local libnss3_filename3="libnss3-tools_3.17.2-1.1_i386.deb"
  248.                 local libnss3_filename4="libnss3-dev_3.17.2-1.1_i386.deb"
  249.                 local libnss3_filename5="libnss3-dbg_3.17.2-1.1_i386.deb"
  250.             fi
  251.             rm -rf ${cur_dir}/l2tp
  252.             mkdir -p ${cur_dir}/l2tp
  253.             cd ${cur_dir}/l2tp
  254.             download_file "${libnspr4_filename1}"
  255.             download_file "${libnspr4_filename2}"
  256.             download_file "${libnspr4_filename3}"
  257.             download_file "${libnspr4_filename4}"
  258.             download_file "${libnss3_filename1}"
  259.             download_file "${libnss3_filename2}"
  260.             download_file "${libnss3_filename3}"
  261.             download_file "${libnss3_filename4}"
  262.             download_file "${libnss3_filename5}"
  263.             dpkg -i ${libnspr4_filename1} ${libnspr4_filename2} ${libnspr4_filename3} ${libnspr4_filename4}
  264.             dpkg -i ${libnss3_filename1} ${libnss3_filename2} ${libnss3_filename3} ${libnss3_filename4} ${libnss3_filename5}

  265.             apt-get -y install wget gcc ppp flex bison make pkg-config libpam0g-dev libcap-ng-dev iptables \
  266.                                libcap-ng-utils libunbound-dev libevent-dev libcurl4-nss-dev libsystemd-daemon-dev
  267.         else
  268.             apt-get -y install wget gcc ppp flex bison make python libnss3-dev libnss3-tools libselinux-dev iptables \
  269.                                libnspr4-dev pkg-config libpam0g-dev libcap-ng-dev libcap-ng-utils libunbound-dev \
  270.                                libevent-dev libcurl4-nss-dev libsystemd-dev
  271.         fi
  272.         apt-get -y --no-install-recommends install xmlto
  273.         apt-get -y install xl2tpd

  274.         compile_install
  275.     elif check_sys packageManager yum; then
  276.         echo "Adding the EPEL repository..."
  277.         yum -y install epel-release yum-utils
  278.         [ ! -f /etc/yum.repos.d/epel.repo ] && echo "Install EPEL repository failed, please check it." && exit 1
  279.         yum-config-manager --enable epel
  280.         echo "Adding the EPEL repository complete..."

  281.         if centosversion 7; then
  282.             yum -y install ppp libreswan xl2tpd firewalld
  283.             yum_install
  284.         elif centosversion 6; then
  285.             yum -y remove libevent-devel
  286.             yum -y install libevent2-devel
  287.             yum -y install nss-devel nspr-devel pkgconfig pam-devel \
  288.                            libcap-ng-devel libselinux-devel lsof \
  289.                            curl-devel flex bison gcc ppp make iptables gmp-devel \
  290.                            fipscheck-devel unbound-devel xmlto libpcap-devel xl2tpd

  291.             compile_install
  292.         fi
  293.     fi

  294. }

  295. config_install(){

  296.     cat > /etc/ipsec.conf<<EOF
  297. version 2.0

  298. config setup
  299.     protostack=netkey
  300.     nhelpers=0
  301.     uniqueids=no
  302.     interfaces=%defaultroute
  303.     virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:!${iprange}.0/24

  304. conn l2tp-psk
  305.     rightsubnet=vhost:%priv
  306.     also=l2tp-psk-nonat

  307. conn l2tp-psk-nonat
  308.     authby=secret
  309.     pfs=no
  310.     auto=add
  311.     keyingtries=3
  312.     rekey=no
  313.     ikelifetime=8h
  314.     keylife=1h
  315.     type=transport
  316.     left=%defaultroute
  317.     leftid=${IP}
  318.     leftprotoport=17/1701
  319.     right=%any
  320.     rightprotoport=17/%any
  321.     dpddelay=40
  322.     dpdtimeout=130
  323.     dpdaction=clear
  324.     sha2-truncbug=yes
  325. EOF

  326.     cat > /etc/ipsec.secrets<<EOF
  327. %any %any : PSK "${mypsk}"
  328. EOF

  329.     cat > /etc/xl2tpd/xl2tpd.conf<<EOF
  330. [global]
  331. port = 1701

  332. [lns default]
  333. ip range = ${iprange}.2-${iprange}.254
  334. local ip = ${iprange}.1
  335. require chap = yes
  336. refuse pap = yes
  337. require authentication = yes
  338. name = l2tpd
  339. ppp debug = yes
  340. pppoptfile = /etc/ppp/options.xl2tpd
  341. length bit = yes
  342. EOF

  343.     cat > /etc/ppp/options.xl2tpd<<EOF
  344. ipcp-accept-local
  345. ipcp-accept-remote
  346. require-mschap-v2
  347. ms-dns 8.8.8.8
  348. ms-dns 8.8.4.4
  349. noccp
  350. auth
  351. hide-password
  352. idle 1800
  353. mtu 1410
  354. mru 1410
  355. nodefaultroute
  356. debug
  357. proxyarp
  358. connect-delay 5000
  359. EOF

  360.     rm -f /etc/ppp/chap-secrets
  361.     cat > /etc/ppp/chap-secrets<<EOF
  362. # Secrets for authentication using CHAP
  363. # client    server    secret    IP addresses
  364. ${username}    l2tpd    ${password}       *
  365. EOF

  366. }

  367. compile_install(){

  368.     rm -rf ${cur_dir}/l2tp
  369.     mkdir -p ${cur_dir}/l2tp
  370.     cd ${cur_dir}/l2tp
  371.     download_file "${libreswan_filename}.tar.gz"
  372.     tar -zxf ${libreswan_filename}.tar.gz

  373.     cd ${cur_dir}/l2tp/${libreswan_filename}
  374.     echo "WERROR_CFLAGS =" > Makefile.inc.local
  375.     make programs && make install

  376.     /usr/local/sbin/ipsec --version >/dev/null 2>&1
  377.     if [ $? -ne 0 ]; then
  378.         echo "${libreswan_filename} install failed."
  379.         exit 1
  380.     fi

  381.     config_install

  382.     cp -pf /etc/sysctl.conf /etc/sysctl.conf.bak

  383.     sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf

  384.     for each in `ls /proc/sys/net/ipv4/conf/`; do
  385.         echo "net.ipv4.conf.${each}.accept_source_route=0" >> /etc/sysctl.conf
  386.         echo "net.ipv4.conf.${each}.accept_redirects=0" >> /etc/sysctl.conf
  387.         echo "net.ipv4.conf.${each}.send_redirects=0" >> /etc/sysctl.conf
  388.         echo "net.ipv4.conf.${each}.rp_filter=0" >> /etc/sysctl.conf
  389.     done
  390.     sysctl -p

  391.     if centosversion 6; then
  392.         [ -f /etc/sysconfig/iptables ] && cp -pf /etc/sysconfig/iptables /etc/sysconfig/iptables.old.`date +%Y%m%d`

  393.         if [ "`iptables -L -n | grep -c '\-\-'`" == "0" ]; then
  394.             cat > /etc/sysconfig/iptables <<EOF
  395. # Added by L2TP VPN script
  396. *filter
  397. :INPUT ACCEPT [0:0]
  398. :FORWARD ACCEPT [0:0]
  399. :OUTPUT ACCEPT [0:0]
  400. -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  401. -A INPUT -p icmp -j ACCEPT
  402. -A INPUT -i lo -j ACCEPT
  403. -A INPUT -p tcp --dport 22 -j ACCEPT
  404. -A INPUT -p udp -m multiport --dports 500,4500,1701 -j ACCEPT
  405. -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
  406. -A FORWARD -s ${iprange}.0/24  -j ACCEPT
  407. COMMIT
  408. *nat
  409. :PREROUTING ACCEPT [0:0]
  410. :OUTPUT ACCEPT [0:0]
  411. :POSTROUTING ACCEPT [0:0]
  412. -A POSTROUTING -s ${iprange}.0/24 -j SNAT --to-source ${IP}
  413. COMMIT
  414. EOF
  415.         else
  416.             iptables -I INPUT -p udp -m multiport --dports 500,4500,1701 -j ACCEPT
  417.             iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
  418.             iptables -I FORWARD -s ${iprange}.0/24  -j ACCEPT
  419.             iptables -t nat -A POSTROUTING -s ${iprange}.0/24 -j SNAT --to-source ${IP}
  420.             /etc/init.d/iptables save
  421.         fi

  422.         if [ ! -f /etc/ipsec.d/cert9.db ]; then
  423.            echo > /var/tmp/libreswan-nss-pwd
  424.            certutil -N -f /var/tmp/libreswan-nss-pwd -d /etc/ipsec.d
  425.            rm -f /var/tmp/libreswan-nss-pwd
  426.         fi

  427.         chkconfig --add iptables
  428.         chkconfig iptables on
  429.         chkconfig --add ipsec
  430.         chkconfig ipsec on
  431.         chkconfig --add xl2tpd
  432.         chkconfig xl2tpd on

  433.         /etc/init.d/iptables restart
  434.         /etc/init.d/ipsec start
  435.         /etc/init.d/xl2tpd start

  436.     else
  437.         [ -f /etc/iptables.rules ] && cp -pf /etc/iptables.rules /etc/iptables.rules.old.`date +%Y%m%d`

  438.         if [ "`iptables -L -n | grep -c '\-\-'`" == "0" ]; then
  439.             cat > /etc/iptables.rules <<EOF
  440. # Added by L2TP VPN script
  441. *filter
  442. :INPUT ACCEPT [0:0]
  443. :FORWARD ACCEPT [0:0]
  444. :OUTPUT ACCEPT [0:0]
  445. -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  446. -A INPUT -p icmp -j ACCEPT
  447. -A INPUT -i lo -j ACCEPT
  448. -A INPUT -p tcp --dport 22 -j ACCEPT
  449. -A INPUT -p udp -m multiport --dports 500,4500,1701 -j ACCEPT
  450. -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
  451. -A FORWARD -s ${iprange}.0/24  -j ACCEPT
  452. COMMIT
  453. *nat
  454. :PREROUTING ACCEPT [0:0]
  455. :OUTPUT ACCEPT [0:0]
  456. :POSTROUTING ACCEPT [0:0]
  457. -A POSTROUTING -s ${iprange}.0/24 -j SNAT --to-source ${IP}
  458. COMMIT
  459. EOF
  460.         else
  461.             iptables -I INPUT -p udp -m multiport --dports 500,4500,1701 -j ACCEPT
  462.             iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
  463.             iptables -I FORWARD -s ${iprange}.0/24  -j ACCEPT
  464.             iptables -t nat -A POSTROUTING -s ${iprange}.0/24 -j SNAT --to-source ${IP}
  465.             /sbin/iptables-save > /etc/iptables.rules
  466.         fi

  467.         cat > /etc/network/if-up.d/iptables <<EOF
  468. #!/bin/sh
  469. /sbin/iptables-restore < /etc/iptables.rules
  470. EOF
  471.         chmod +x /etc/network/if-up.d/iptables

  472.         if [ ! -f /etc/ipsec.d/cert9.db ]; then
  473.            echo > /var/tmp/libreswan-nss-pwd
  474.            certutil -N -f /var/tmp/libreswan-nss-pwd -d /etc/ipsec.d
  475.            rm -f /var/tmp/libreswan-nss-pwd
  476.         fi

  477.         update-rc.d -f xl2tpd defaults

  478.         cp -f /etc/rc.local /etc/rc.local.old.`date +%Y%m%d`
  479.         sed --follow-symlinks -i -e '/^exit 0/d' /etc/rc.local
  480.         cat >> /etc/rc.local <<EOF

  481. # Added by L2TP VPN script
  482. echo 1 > /proc/sys/net/ipv4/ip_forward
  483. /usr/sbin/service ipsec start
  484. exit 0
  485. EOF
  486.         chmod +x /etc/rc.local
  487.         echo 1 > /proc/sys/net/ipv4/ip_forward

  488.         /sbin/iptables-restore < /etc/iptables.rules
  489.         /usr/sbin/service ipsec start
  490.         /usr/sbin/service xl2tpd restart

  491.     fi

  492. }

  493. yum_install(){

  494.     config_install

  495.     cp -pf /etc/sysctl.conf /etc/sysctl.conf.bak

  496.     echo "# Added by L2TP VPN" >> /etc/sysctl.conf
  497.     echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
  498.     echo "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.conf
  499.     echo "net.ipv4.icmp_echo_ignore_broadcasts=1" >> /etc/sysctl.conf
  500.     echo "net.ipv4.icmp_ignore_bogus_error_responses=1" >> /etc/sysctl.conf

  501.     for each in `ls /proc/sys/net/ipv4/conf/`; do
  502.         echo "net.ipv4.conf.${each}.accept_source_route=0" >> /etc/sysctl.conf
  503.         echo "net.ipv4.conf.${each}.accept_redirects=0" >> /etc/sysctl.conf
  504.         echo "net.ipv4.conf.${each}.send_redirects=0" >> /etc/sysctl.conf
  505.         echo "net.ipv4.conf.${each}.rp_filter=0" >> /etc/sysctl.conf
  506.     done
  507.     sysctl -p

  508.     cat > /etc/firewalld/services/xl2tpd.xml<<EOF
  509. <?xml version="1.0" encoding="utf-8"?>
  510. <service>
  511.   <short>xl2tpd</short>
  512.   <description>L2TP IPSec</description>
  513.   <port protocol="udp" port="4500"/>
  514.   <port protocol="udp" port="1701"/>
  515. </service>
  516. EOF
  517.     chmod 640 /etc/firewalld/services/xl2tpd.xml

  518.     systemctl enable ipsec
  519.     systemctl enable xl2tpd
  520.     systemctl enable firewalld

  521.     systemctl status firewalld > /dev/null 2>&1
  522.     if [ $? -eq 0 ]; then
  523.         firewall-cmd --reload
  524.         echo "Checking firewalld status..."
  525.         firewall-cmd --list-all
  526.         echo "add firewalld rules..."
  527.         firewall-cmd --permanent --add-service=ipsec
  528.         firewall-cmd --permanent --add-service=xl2tpd
  529.         firewall-cmd --permanent --add-masquerade
  530.         firewall-cmd --reload
  531.     else
  532.         echo "Firewalld looks like not running, trying to start..."
  533.         systemctl start firewalld
  534.         if [ $? -eq 0 ]; then
  535.             echo "Firewalld start successfully..."
  536.             firewall-cmd --reload
  537.             echo "Checking firewalld status..."
  538.             firewall-cmd --list-all
  539.             echo "adding firewalld rules..."
  540.             firewall-cmd --permanent --add-service=ipsec
  541.             firewall-cmd --permanent --add-service=xl2tpd
  542.             firewall-cmd --permanent --add-masquerade
  543.             firewall-cmd --reload
  544.         else
  545.             echo "Failed to start firewalld. please enable udp port 500 4500 1701 manually if necessary."
  546.         fi
  547.     fi

  548.     systemctl restart ipsec
  549.     systemctl restart xl2tpd
  550.     echo "Checking ipsec status..."
  551.     systemctl -a | grep ipsec
  552.     echo "Checking xl2tpd status..."
  553.     systemctl -a | grep xl2tpd
  554.     echo "Checking firewalld status..."
  555.     firewall-cmd --list-all

  556. }

  557. finally(){

  558.     cd ${cur_dir}
  559.     rm -fr ${cur_dir}/l2tp
  560.     # create l2tp command
  561.     cp -f ${cur_dir}/`basename $0` /usr/bin/l2tp

  562.     echo "Please wait a moment..."
  563.     sleep 5
  564.     ipsec verify
  565.     echo
  566.     echo "###############################################################"
  567.     echo "# L2TP VPN Auto Installer                                     #"
  568.     echo "# System Supported: CentOS 6+ / Debian 7+ / Ubuntu 12+        #"
  569.     echo "# Intro: https://teddysun.com/448.html                        #"
  570.     echo "# Author: Teddysun <i@teddysun.com>                           #"
  571.     echo "###############################################################"
  572.     echo "If there is no [FAILED] above, you can connect to your L2TP "
  573.     echo "VPN Server with the default Username/Password is below:"
  574.     echo
  575.     echo "Server IP: ${IP}"
  576.     echo "PSK      : ${mypsk}"
  577.     echo "Username : ${username}"
  578.     echo "Password : ${password}"
  579.     echo
  580.     echo "If you want to modify user settings, please use below command(s):"
  581.     echo "l2tp -a (Add a user)"
  582.     echo "l2tp -d (Delete a user)"
  583.     echo "l2tp -l (List all users)"
  584.     echo "l2tp -m (Modify a user password)"
  585.     echo
  586.     echo "Welcome to visit our website: https://teddysun.com/448.html"
  587.     echo "Enjoy it!"
  588.     echo
  589. }


  590. l2tp(){
  591.     clear
  592.     echo
  593.     echo "###############################################################"
  594.     echo "# L2TP VPN Auto Installer                                     #"
  595.     echo "# System Supported: CentOS 6+ / Debian 7+ / Ubuntu 12+        #"
  596.     echo "# Intro: https://teddysun.com/448.html                        #"
  597.     echo "# Author: Teddysun <i@teddysun.com>                           #"
  598.     echo "###############################################################"
  599.     echo
  600.     rootness
  601.     tunavailable
  602.     disable_selinux
  603.     version_check
  604.     get_os_info
  605.     preinstall_l2tp
  606.     install_l2tp
  607.     finally
  608. }

  609. list_users(){
  610.     if [ ! -f /etc/ppp/chap-secrets ];then
  611.         echo "Error: /etc/ppp/chap-secrets file not found."
  612.         exit 1
  613.     fi
  614.     local line="+-------------------------------------------+\n"
  615.     local string=%20s
  616.     printf "${line}|${string} |${string} |\n${line}" Username Password
  617.     grep -v "^#" /etc/ppp/chap-secrets | awk '{printf "|'${string}' |'${string}' |\n", $1,$3}'
  618.     printf ${line}
  619. }

  620. add_user(){
  621.     while :
  622.     do
  623.         read -p "Please input your Username:" user
  624.         if [ -z ${user} ]; then
  625.             echo "Username can not be empty"
  626.         else
  627.             grep -w "${user}" /etc/ppp/chap-secrets > /dev/null 2>&1
  628.             if [ $? -eq 0 ];then
  629.                 echo "Username (${user}) already exists. Please re-enter your username."
  630.             else
  631.                 break
  632.             fi
  633.         fi
  634.     done
  635.     pass=`rand`
  636.     echo "Please input ${user}'s password:"
  637.     read -p "(Default Password: ${pass}):" tmppass
  638.     [ ! -z ${tmppass} ] && pass=${tmppass}
  639.     echo "${user}    l2tpd    ${pass}       *" >> /etc/ppp/chap-secrets
  640.     echo "Username (${user}) add completed."
  641. }

  642. del_user(){
  643.     while :
  644.     do
  645.         read -p "Please input Username you want to delete it:" user
  646.         if [ -z ${user} ]; then
  647.             echo "Username can not be empty"
  648.         else
  649.             grep -w "${user}" /etc/ppp/chap-secrets >/dev/null 2>&1
  650.             if [ $? -eq 0 ];then
  651.                 break
  652.             else
  653.                 echo "Username (${user}) is not exists. Please re-enter your username."
  654.             fi
  655.         fi
  656.     done
  657.     sed -i "/^\<${user}\>/d" /etc/ppp/chap-secrets
  658.     echo "Username (${user}) delete completed."
  659. }

  660. mod_user(){
  661.     while :
  662.     do
  663.         read -p "Please input Username you want to change password:" user
  664.         if [ -z ${user} ]; then
  665.             echo "Username can not be empty"
  666.         else
  667.             grep -w "${user}" /etc/ppp/chap-secrets >/dev/null 2>&1
  668.             if [ $? -eq 0 ];then
  669.                 break
  670.             else
  671.                 echo "Username (${user}) is not exists. Please re-enter your username."
  672.             fi
  673.         fi
  674.     done
  675.     pass=`rand`
  676.     echo "Please input ${user}'s new password:"
  677.     read -p "(Default Password: ${pass}):" tmppass
  678.     [ ! -z ${tmppass} ] && pass=${tmppass}
  679.     sed -i "/^\<${user}\>/d" /etc/ppp/chap-secrets
  680.     echo "${user}    l2tpd    ${pass}       *" >> /etc/ppp/chap-secrets
  681.     echo "Username ${user}'s password has been changed."
  682. }

  683. # Main process
  684. action=$1
  685. if [ -z ${action} ] && [ "`basename $0`" != "l2tp" ]; then
  686.     action=install
  687. fi

  688. case ${action} in
  689.     install)
  690.         l2tp 2>&1 | tee ${cur_dir}/l2tp.log
  691.         ;;
  692.     -l|--list)
  693.         list_users
  694.         ;;
  695.     -a|--add)
  696.         add_user
  697.         ;;
  698.     -d|--del)
  699.         del_user
  700.         ;;
  701.     -m|--mod)
  702.         mod_user
  703.         ;;
  704.     -h|--help)
  705.         echo "Usage: `basename $0` -l,--list   List all users"
  706.         echo "       `basename $0` -a,--add    Add a user"
  707.         echo "       `basename $0` -d,--del    Delete a user"
  708.         echo "       `basename $0` -m,--mod    Modify a user password"
  709.         echo "       `basename $0` -h,--help   Print this help information"
  710.         ;;
  711.     *)
  712.         echo "Usage: `basename $0` [-l,--list|-a,--add|-d,--del|-m,--mod|-h,--help]" && exit
  713.         ;;
  714. esac
复制代码


回复 支持 反对

使用道具 举报

1325

主题

2372

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10262
 楼主| 发表于 2019-2-11 06:58 | 显示全部楼层
Server IP: ----
PSK      : ----
Username : w----
Password : 6----

If you want to modify user settings, please use below command(s):
l2tp -a (Add a user)
l2tp -d (Delete a user)
l2tp -l (List all users)
l2tp -m (Modify a user password)


回复 支持 反对

使用道具 举报

1325

主题

2372

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10262
 楼主| 发表于 2019-2-11 07:42 | 显示全部楼层
设置固定IP
vi /etc/ppp/chap-secrets
回复 支持 反对

使用道具 举报

1325

主题

2372

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10262
 楼主| 发表于 2023-6-2 01:21 | 显示全部楼层

  1. 刚刚重新研究纯L2TP模式的XL2TP
  2. 过程如下 最下面的是一些结论



  3. linux 下建立 纯L2TP 服务端和客户端
  4. https://blog.csdn.net/lfw19891101/article/details/7206217


  5. 参考资料

  6. http://www.jacco2.dds.nl/networking/linux-l2tp.html

  7. http://www.cublog.cn/u/8057/showart_83292.html

  8. http://strongvpn.com/forum/viewtopic.php?id=788


  9. ###
  10. echo 'c myvpn' > /var/run/xl2tpd/l2tp-control

  11. ################还有另外一个教程
  12. https://help.ubuntu.com/community/L2TPServer#:~:text=refuse%20pap%20%3D%20refure%20pap%20authentication%20ppp%20debug,should%20probably%20be%20longer%20to%20ensure%20sufficient%20security.

  13. ################还有另外一个教程  这个可以看看
  14. https://blog.csdn.net/u013485792/article/details/51740776

  15. 这里比较详细
  16. https://manpages.debian.org/bullseye/xl2tpd/index.html

  17. 这里是这个人的其他文档
  18. https://manpages.debian.org/contents-bullseye.html

  19. pppd的配置(用于/etc/ppp/options.xl2tpd)
  20. https://manpages.debian.org/bullseye/ppp/pppd.8.en.html
  21. ##################
  22. xl2tpd源码分析
  23. https://blog.csdn.net/eydwyz/article/details/66973988





  24. 我终于摸得差不多了
  25. 首先xl2tpd安装好以后 默认什么都不用改,就可以直接输入命令 xl2tpd启动 如果要观察可以加一个-D参数

  26. 服务端的配置文件里面 global可以修改端口,客户端连接可以指定用什么端口



  27. 然后客户端的配置,客户端需要删除lns 然后添加配置lac  
  28. [lac l2tpvpn]
  29. lns = 172.17.0.2:1701
  30. ppp debug = yes
  31. pppoptfile = /etc/ppp/options.xl2tpd
  32. 如果不要ipsec 在global里面配置 ipsec saref = no  可以修改端口号

  33. 然后配置ppp文件
  34. /etc/ppp/options.xl2tpd
  35. ipcp-accept-local
  36. ipcp-accept-remote
  37. refuse-eap
  38. noccp
  39. auth
  40. idle 1800
  41. mtu 1410
  42. mru 1410
  43. defaultroute
  44. usepeerdns
  45. debug
  46. lock
  47. connect-delay 5000

  48. 最后服务端也要先启动服务 xl2tpd -D
  49. 然后用xl2tpd-control命令来连接和查看 -d参数是必须的

  50. xl2tpd-control -d available #查看服务的信息
  51. xl2tpd-control -d connect-lac lacname #连接这个lac 外面的教程里面都是 echo "c lacname">/var/    太不专业了
复制代码

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

荣耀之链

GMT+8, 2025-6-18 03:03 , Processed in 0.019018 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表