centos7安装xl2tpd

1.  先看看你的主机是否支持pptp,返回结果为yes就表示通过。

modprobe ppp-compress-18 && echo yes

2.是否开启了TUN,有的虚拟机主机需要开启,返回结果为cat: /dev/net/tun: File descriptor in bad state。就表示通过。

cat /dev/net/tun

3 安装EPEL源(CentOS7官方源中已经去掉了xl2tpd)

yum install -y epel-release

4 安装xl2tpd和libreswan(openswan已经停止维护)

yum install -y xl2tpd libreswan lsof

5 编辑xl2tpd配置文件

公司内网为192.168.1.1的网段

vim /etc/xl2tpd/xl2tpd.conf  

[lns default]
ip range = 192.168.1.128-192.168.1.254        
local ip = 192.168.1.253
require chap = yes
refuse pap = yes
require authentication = yes
name = LinuxVPNserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

6 编辑pppoptfile文件

vim /etc/ppp/options.xl2tpd     

ipcp-accept-local
ipcp-accept-remote
ms-dns  192.168.1.1             公司有内网域名.所以这里DNS写的192.168.1.1
name xl2tpd
auth
idle 1800
mtu 1410
mru 1410
nodefaultroute
debug
proxyarp
connect-delay 5000
refuse-pap
refuse-mschap
require-mschap-v2
persist
logfile /var/log/xl2tpd.log

7 编辑ipsec配置文件

vim /etc/ipsec.conf      # 只修改以下项,其他默认

8 编辑include的conn文件

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.1.253
        leftprotoport=17/1701
        right=%any
        rightprotoport=17/%any

9 设置用户名密码

vim /etc/ppp/chap-secrets  

用户名:qxtx      密码:123456

10 设置预共享密钥PSK

vim /etc/ipsec.d/default.secrets  
: PSK "123456"               前面的冒号不能少


11 CentOS7 防火墙设置,如果防火墙关闭就不用管了

firewall-cmd --permanent --add-service=ipsec      # 放行ipsec服务,安装时会自定生成此服务
firewall-cmd --permanent --add-port=1701/udp      # xl2tp 的端口,默认1701. 
firewall-cmd --permanent --add-port=4500/udp 
firewall-cmd --permanent --add-masquerade      # 启用NAT转发功能。必须启用此功能
firewall-cmd --reload      # 重载配置
 

修改内核参数

vim /etc/sysctl.conf    # 添加如下配置到文件中,参数后面不能有空格-net.ipv4.ip_forward = 1net.ipv4.conf.all.accept_redirects = 0net.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

net.ipv4.conf.eth0.accept_redirects = 0

net.ipv4.conf.eth0.rp_filter = 0                             这里网卡名不一定是eth0,根据实际网卡名改一下就好了,只需要改这一个地方

net.ipv4.conf.eth0.send_redirects = 0

net.ipv4.conf.eth1.accept_redirects = 0

net.ipv4.conf.eth1.rp_filter = 0

net.ipv4.conf.eth1.send_redirects = 0

net.ipv4.conf.eth2.accept_redirects = 0

net.ipv4.conf.eth2.rp_filter = 0

net.ipv4.conf.eth2.send_redirects = 0

net.ipv4.conf.ip_vti0.accept_redirects = 0

net.ipv4.conf.ip_vti0.rp_filter = 0

net.ipv4.conf.ip_vti0.send_redirects = 0

net.ipv4.conf.lo.accept_redirects = 0

net.ipv4.conf.lo.rp_filter = 0

net.ipv4.conf.lo.send_redirects = 0

net.ipv4.conf.ppp0.accept_redirects = 0

net.ipv4.conf.ppp0.rp_filter = 0

net.ipv4.conf.ppp0.send_redirects = 0

sysctl -p    # 加载内核参数使生效
上面的很多配置可能是无效的,不需要在乎

13 启动ipsec

systemctl enable ipsec     # 设为开机启动
systemctl start ipsec     # 启动服务

14 检查配置

ipsec verify     # 检查命令

15 启动xl2tp

systemctl enable xl2tpd      # 设为卡机启动
systemctl start xl2tpd      # 启动xl2tp

16.路由器做端口映射(1701端口)

这个搭建完后我用手机可以连接,但是用电脑始终连不上。手机连接后内网域名打开都是正常的

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章