拒绝未加密连接

hh785003

CentOS 7下搭建IPsec/L2TP VPN服务详解:从零开始配置企业级安全远程访问

在当今远程办公日益普及的背景下,企业对安全、稳定的远程访问解决方案需求不断增长,CentOS 7作为一款成熟且稳定的企业级Linux发行版,常被用于部署各类网络服务,本文将详细介绍如何在CentOS 7系统上搭建基于IPsec/L2TP协议的VPN服务,实现跨公网的安全远程接入,适用于中小型企业或个人开发者快速构建私有网络隧道。

确保你的CentOS 7服务器已安装并配置好基础环境,登录服务器后,执行以下命令更新系统:

sudo yum update -y

安装必要的软件包,我们需要ipsec-tools(用于IPsec协商)、xl2tpd(L2TP守护进程)以及iptables防火墙工具:

sudo yum install -y ipsec-tools xl2tpd iptables-services

完成安装后,我们开始配置IPsec部分,编辑/etc/ipsec.conf文件,添加如下内容:

config setup
    protostack=netkey
    plutodebug=all
    dumpdir=/var/run/pluto/
    nat_traversal=yes
    interfaces=%defaultroute
conn L2TP-PSK-NAT
    right=%any
    left=%defaultroute
    leftid=@your-server-ip.com
    rightsubnet=vhost:%priv
    authby=secret
    pfs=yes
    auto=add
    keyingtries=3
    rekey=no
    type=transport
    ike=aes256-sha1-modp1024
    phase2alg=aes256-sha1
    dpddelay=30
    dpdtimeout=120
    dpdaction=clear

leftid应替换为你的服务器公网IP或域名,rightsubnet定义客户端子网,若无特殊要求可保留默认值。

配置共享密钥,编辑/etc/ipsec.secrets文件:

@your-server-ip.com %any : PSK "your-strong-pre-shared-key"

请务必使用强密码(如随机生成的长字符串),避免弱密钥导致安全风险。

然后配置L2TP服务,编辑/etc/xl2tpd/xl2tpd.conf

[global]
port = 1701
access control = yes
[lns default]
ip range = 192.168.100.100-192.168.100.200
local ip = 192.168.100.1
require chap = yes
refuse pap = yes
require authentication = yes
name = l2tpserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

这里定义了分配给客户端的IP地址池(192.168.100.100-200),本地IP为网关地址。

创建PPP选项文件/etc/ppp/options.xl2tpd

 refuse-chap
 refuse-mschap
 require-mschap-v2
 require-mppe-128
 ms-dns 8.8.8.8
 ms-dns 8.8.4.4
 proxyarp
 lock
 noauth

设置用户认证信息,编辑/etc/ppp/chap-secrets

# client        server  secret                  IP addresses
username        l2tpserver      password                *

完成所有配置后,启动服务:

sudo systemctl enable ipsec xl2tpd
sudo systemctl start ipsec xl2tpd
sudo systemctl restart iptables

同时开放相关端口(需根据实际情况调整防火墙规则):

sudo iptables -I INPUT -p udp --dport 500 -j ACCEPT
sudo iptables -I INPUT -p udp --dport 4500 -j ACCEPT
sudo iptables -I INPUT -p udp --dport 1701 -j ACCEPT
sudo iptables -I FORWARD -s 192.168.100.0/24 -d 0.0.0.0/0 -j ACCEPT
sudo service iptables save

至此,一个完整的IPsec/L2TP VPN服务已在CentOS 7上成功部署,客户端可通过Windows自带的“连接到工作场所”或第三方L2TP客户端进行连接,输入服务器IP和预共享密钥即可建立安全隧道,此方案具有高安全性、兼容性好、易于维护等优点,适合需要远程安全接入的企业环境。

拒绝未加密连接

半仙加速器-海外加速器|VPN加速器|vpn翻墙加速器|VPN梯子|VPN外网加速

文章版权声明:除非注明,否则均为半仙加速器-海外加速器|VPN加速器|外网加速器|梯子加速器|访问外国网站首选半仙加速器原创文章,转载或复制请以超链接形式并注明出处。

取消
微信二维码
微信二维码
支付宝二维码