cnetos6.8 和 centos 7.3 搭建L2TP 路由器连接使用

一 使用一键脚本搭建L2TP+IPSec
wget --no-check-certificate https://raw.githubusercontent.com/teddysun/across/master/l2tp.sh
chmod +x l2tp.sh
./l2tp.sh
二 操作
l2tp -a : 增加一个连接账户
l2tp -d : 删除一个连接账户
l2tp -l : 展示现有的账户
l2tp -m : 修改账户的密码
三 手动添加 账号绑定ip
vim /etc/ppp/chap-secrets

路由器功能拓展

注意事项

centos6.8中要做防火墙端口映射并关闭防火墙配置中POSTROUTING 中NAT模式(有的没有不用管) 否则无法上网
centos6.8 防火墙配置 /etc/sysconfig/iptables

iptables -t nat -A POSTROUTING -s 192.168.18.0/24 -o eth0 -j MASQUERADE
服务器脚本
#!/bin/bash
source /etc/profile
IFCONIFGPPP=`ifconfig | sed -En 's/127.0.0.1//;s/.*destination (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`
#arry_list1=(`echo $IFCONIFGPPP | tr ' ' ' '`)
DATE=$(date "+%Y-%m-%d %H:%M:%S")
#arry_list2=("192.168.18.4" "192.168.18.5" "192.168.18.6" "192.168.18.7" "192.168.18.8" "192.168.18.9" "192.168.18.10" "192.168.18.11")
arry_list1=("192.168.18.2" "192.168.18.3" "192.168.18.4" "192.168.18.5" "192.168.18.6" "192.168.18.7" "192.168.18.8" "192.168.18.9" "192.168.18.10" "192.168.18.11")
arry_list2=(`echo $IFCONIFGPPP | tr ' ' ' '`)
declare -a diff_list
t=0
flag=0
#echo arry_list1=${arry_list1[@]}
#echo arry_list2=${arry_list2[@]}

for list1_num in "${arry_list1[@]}"
do
    #echo list1_num is ${list1_num}
    for list2_num in "${arry_list2[@]}"
    do
       #echo list2_num is ${list2_num}
        if [[ "${list1_num}" == "${list2_num}" ]]; then
            flag=1
            break
        fi
    done
    if [[ $flag -eq 0 ]]; then
        diff_list[t]=$list1_num
        t=$((t+1))
    else
        flag=0
    fi
done
num=${#diff_list[@]}
if [ $num -gt 0 ];then
    for diff_list in "${diff_list[@]}"
    do
        echo ${diff_list[i]}   $DATE>>/udplog/udp.log
        #echo ${diff_list[i]}
    done
fi

路由器脚本
#!/bin/sh
`mkdir -p /root/home`
echo "#!/bin/sh
#DATE=`date +%Y-%m-%d-%H:%M:%S`
tries=0
echo --- my_watchdog start --
while [[ "$""tries" -lt 5 ]]
do
    if /bin/ping -c 1 114.114.114.114 >/dev/null
    then
        echo --- exit --
        exit 0
    fi
    tries=$((tries+1))
    sleep 10
done
#echo $DATE reboot >>my_watchdog.log
echo reboot" >> /root/home/watchdog.sh
`crontab -r`
echo "*/5 * * * * sh /root/home/watchdog.sh" >>/var/spool/cron/crontabs/root
`/etc/init.d/cron restart`
查看连接数
Centos7.3:    ifconfig | sed -En 's/127.0.0.1//;s/.*destination (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'
Centos6.8:    ifconfig | grep -w P-t-P | cut  -c 41-54

你可能感兴趣的:(cnetos6.8 和 centos 7.3 搭建L2TP 路由器连接使用)