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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.安全技术 (1)入侵检测与管理系统(Intrusion Detection Systems): 特点是不阻断任...
    尛尛大尹阅读 2,533评论 0 2
  • 1.常见防火墙选用 硬件防火墙 开源软件:iptables(默认规则改为INPUT DROP) 云服务器:安全组(...
    酷酷的伟阅读 1,184评论 0 2
  • 目前市面上比较常见的有3、4层的防火墙,叫网络层的防火墙,还有7层的防火墙,其实是代理层的网关。 三层的防火墙会在...
    辉耀辉耀阅读 2,704评论 0 2
  • 一. 什么是防火墙 防火墙,就是用于实现Linux下访问控制的功能的,它分为硬件的或者软件的防火墙两种。无论是在哪...
    InnocenceYWQ阅读 1,078评论 0 3
  • 下午放学儿子饿了,先吃了点地瓜充充饥,就开始写作业了。儿子选择先写语文,是7个生字2音2字2词,当写到第三个的...
    朱新玲阅读 201评论 0 2