开发者社区> Pisces> 正文

centos7部署l2tp ipsec

简介: 1、查询操作系统版本 #cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) 2、查询系统是否支持ppp,返回yes代表通过。 #modprobe ppp-compress-18 && echo yes 3、查询系统是否开启了tun,返回File descriptor in bad state代表通过。
+关注继续查看

1、查询操作系统版本

#cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

2、查询系统是否支持ppp,返回yes代表通过。

#modprobe ppp-compress-18 && echo yes

3、查询系统是否开启了tun,返回File descriptor in bad state代表通过。

#cat /dev/net/tun

4、安装epel源

#yum install epel-release -y

5、安装xl2tpd和libreswan。centos7 版本,libreswan(ipsec)代替了openswan.

#yum install -y xl2tpd libreswan

6、编辑ipsec.conf配置文件,保持默认配置吧

config setup
        protostack=netkey
        dumpdir=/var/run/pluto/
        virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:25.0.0.0/8,%v4:100.64.0.0/10,%v6:fd00::/8,%v6:fe80::/10
 
include /etc/ipsec.d/*.conf

7、新建/etc/ipsec.d/l2tp-ipsec.conf文件

#vim /etc/ipsec.d/l2tp-ipsec.conf
conn L2TP-PSK-NAT
  rightsubnet=0.0.0.0/0
  dpddelay=10
  dpdtimeout=20
  dpdaction=clear
  forceencaps=yes
  also=L2TP-PSK-noNAT
conn L2TP-PSK-noNAT
  authby=secret
  pfs=no
  auto=add
  keyingtries=3
  rekey=no
  ikelifetime=8h
  keylife=1h
  type=transport
  left=192.168.10.9    #ppp接口的IP地址,对应下面的xl2tpd的配置文件
  leftprotoport=17/1701
  right=%any
  rightprotoport=17/%any

8、配置置预共享密钥PSK

#vim /etc/ipsec.d/default.secrets
: PSK "123A?a456"

9、编辑xl2tpd配置文件

#vim /etc/xl2tpd/xl2tpd.conf
[lns default]
ip range = 192.168.10.10-192.168.10.100
local ip = 192.168.10.9
require chap = yes
refuse pap = yes
require authentication = yes
name = LinuxVPNserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

10、编辑pppoptfile文件

#vim /etc/ppp/options.xl2tpd
ipcp-accept-local
ipcp-accept-remote
ms-dns  192.168.10.3  #内部的DNS服务器
ms-dns  114.114.114.114
name xl2tpd
#noccp
auth
#crtscts
idle 1800
mtu 1410
mru 1410
nodefaultroute
debug
#lock
proxyarp
connect-delay 5000
refuse-pap
refuse-mschap
require-mschap-v2
persist
logfile /var/log/xl2tpd.log

11、配置拨号用户名和密码

vim /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client        server  secret 
# 格式为:用户名  服务类型  密码  允许访问的ip
# *代表所有
aliyunvip    *      Abc?123       *

12、配置CentOS7 防火墙

#firewall-cmd --permanent --add-service=ipsec      #允许ipsec服务
#firewall-cmd --permanent --add-port=1701/udp    #允许 xl2tp 
#firewall-cmd --permanent --add-port=4500/udp   #允许 xl2tp
#firewall-cmd --permanent --add-masquerade       #启用nat转发
#firewall-cmd --reload                          #重新加载配置

13、修改内核参数

#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.send_redirects = 0

#sysctl -p  #修改内核生效

14、启动ipsec服务

#systemctl enable ipsec     # 设为开机自动启动
#systemctl start ipsec       # 开启服务
#systemctl status ipsec
● ipsec.service - Internet Key Exchange (IKE) Protocol Daemon for IPsec
   Loaded: loaded (/usr/lib/systemd/system/ipsec.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-10-25 17:28:56 CST; 3 days ago
     Docs: man:ipsec(8)
           man:pluto(8)
           man:ipsec.conf(5)
 Main PID: 8831 (pluto)
   Status: "Startup completed."
   CGroup: /system.slice/ipsec.service
           └─8831 /usr/libexec/ipsec/pluto --leak-detective --config /etc/ipsec.conf --nofork

15、检查ipsec状态

#ipsec verify     

Verifying installed system and configuration files

Version check and ipsec on-path                         [OK]
Libreswan 3.25 (netkey) on 3.10.0-862.2.3.el7.x86_64
Checking for IPsec support in kernel                    [OK]
 NETKEY: Testing XFRM related proc values
         ICMP default/send_redirects                    [OK]
         ICMP default/accept_redirects                  [OK]
         XFRM larval drop                               [OK]
Pluto ipsec.conf syntax                                 [OK]
Two or more interfaces found, checking IP forwarding    [OK]
Checking rp_filter                                      [OK]
Checking that pluto is running                          [OK]
 Pluto listening for IKE on udp 500                     [OK]
 Pluto listening for IKE/NAT-T on udp 4500              [OK]
 Pluto ipsec.secret syntax                              [OK]
Checking 'ip' command                                   [OK]
Checking 'iptables' command                             [OK]
Checking 'prelink' command does not interfere with FIPS [OK]
Checking for obsolete ipsec.conf options                [OK]

16、启动xl2tp

#systemctl enable xl2tpd     #设置自启动
#systemctl start xl2tpd      #启动xl2tp

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
CentOS7安装MySQL5.7太慢了
CentOS7安装MySQL5.7太慢了
584 0
CentOS8 服务器安装MySQL
安装 查看状态 开启: 使用MySQL 设置密码&&外部访问
223 0
centos7安装mysql5.6.38史上最详细的安装步骤
最近由于要用到mysql,就想着装一个mysql,但是因为我的虚拟机是centos7的,centos7将默认数据库mysql替换成了Mariadb安装起来就比较的麻烦,遇到各种各样的问题,网上的教程很多,但是基本没有好使的,按照他们的步骤到最后没有一个成功的,搞了很长时间才装好,我记得之前在centos6.5上面安装也没那么复杂啊,但是在7上面不管是用yum方式,还是安装包的方式都搞了好几遍,最后用安装包的方式安装成功了,今天就来总结一下安装的过程.为了方便大家看整个过程,我又重新装了一遍.过程写的比较详细,建议大家先收藏在观看.
177 0
阿里云centos安装mysql
阿里云centos安装mysql
267 0
centos7 安装指定版本的mysql8.0
centos7 安装指定版本的mysql8.0
463 0
三十五、Centos安装mysql(rpm终结版)
三十五、Centos安装mysql(rpm终结版)
166 0
centos8重装MySQL8
前言: 本来也不想卸载的,因为之前有往db里插入一千多万的数据了。。但是这个数据库好像被我弄坏了。。 输入正确的账号密码一直进不了 很无奈。。 😵 一开始是启动不了,后来发现用户的权限不对(要通过 chgrp 和 chown 去修改),改了之后可以启动,但是就无法登录成功了。。出此下策,顺便换个方式再去插入数据试试 😄
100 0
mysql问题记录:centos7无法启动mysql
mysql问题记录:centos7无法启动mysql
77 0
CentOS7 部署 MySQL 主从复制,读写分离
在实际的生产环境中,如果对数据库的读写都在同一个数据库服务器中操作,无论是在安全性、高可用性还是高并发等各个方面都是完全不能满足实际需求的,因此,一般来说都是通过主从复制(Master-Slave)的方式来同步数据,再通过读写分离来提升数据库的并发负载能力这样的方案来进行部署与实施的。
217 0
CentOS7 MySQL 增量备份与恢复
CentOS7 MySQL 增量备份与恢复
158 0
+关注
Pisces
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载
相关实验场景
更多