配置L2TP/IPSEC的一些问题解决

==== .conf 书写格式问题 ========================

该文件里增加内容不多,但需要注意缩进格式

/etc/ipsec.conf

config setup

    protostack=netkey

    interfaces="%defaultroute"

内容属于config setup的子项,需要TAB缩进保持一致

注释最好换行写,不要写在配置项的后面

/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=152.32.123.45

        leftprotoport=17/1701

        right=%any

        rightprotoport=17/%any



==== IPSec 启动失败 ==================================

systemctl restart ipsec

启动失败

可以用 systemctl status ipsec

如缺少有用信息可以执行

journalctl -u ipsec

一些配置错误的具体信息会有体现,例如下面中 cannot load config '/etc/ipsec.conf': /etc/ipsec.conf:24: syntax error, u

[root@10-7-162-198 ~]# journalctl -u ipsec

-- Logs begin at Fri 2021-10-01 02:29:23 HKT, end at Sun 2021-10-03 23:53:44 HKT. --

Oct 03 20:01:50 10-7-162-198 systemd[1]: Starting Internet Key Exchange (IKE) Protocol Daemon for IPsec...

Oct 03 20:01:50 10-7-162-198 addconn[1995]: cannot load config '/etc/ipsec.conf': /etc/ipsec.conf:24: syntax error, u

Oct 03 20:01:50 10-7-162-198 systemd[1]: ipsec.service: control process exited, code=exited status=3

Oct 03 20:01:50 10-7-162-198 ipsec[2003]: cannot load config '/etc/ipsec.conf': /etc/ipsec.conf:24: syntax error, une

Oct 03 20:01:50 10-7-162-198 systemd[1]: Failed to start Internet Key Exchange (IKE) Protocol Daemon for IPsec.

Oct 03 20:01:50 10-7-162-198 systemd[1]: Unit ipsec.service entered failed state.

Oct 03 20:01:50 10-7-162-198 systemd[1]: ipsec.service failed.

Oct 03 20:01:50 10-7-162-198 systemd[1]: ipsec.service holdoff time over, scheduling restart.

Oct 03 20:01:50 10-7-162-198 systemd[1]: Stopped Internet Key Exchange (IKE) Protocol Daemon for IPsec.

Oct 03 20:01:50 10-7-162-198 systemd[1]: Starting Internet Key Exchange (IKE) Protocol Daemon for IPsec...

Oct 03 20:01:50 10-7-162-198 addconn[2012]: cannot load config '/etc/ipsec.conf': /etc/ipsec.conf:24: syntax error, u

Oct 03 20:01:50 10-7-162-198 systemd[1]: ipsec.service: control process exited, code=exited status=3

Oct 03 20:01:50 10-7-162-198 ipsec[2020]: cannot load config '/etc/ipsec.conf': /etc/ipsec.conf:24: syntax error, une

Oct 03 20:01:50 10-7-162-198 systemd[1]: Failed to start Internet Key Exchange (IKE) Protocol Daemon for IPsec.



====  ipsec verify 报错 ===================================

[root@10-7-162-198 ~]# ipsec verify

Verifying installed system and configuration files

Version check and ipsec on-path [OK]

Libreswan 3.25 (netkey) on 4.19.0-9.el7.ucloud.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]

##rp_filter警告

Checking rp_filter                                      [ENABLED]

/proc/sys/net/ipv4/conf/eth1/rp_filter                [ENABLED]

/proc/sys/net/ipv4/conf/eth2/rp_filter                [ENABLED]

  rp_filter is not fully aware of IPsec and should be disabled

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]

ipsec verify: encountered 5 errors - see 'man ipsec_verify' for help

##确认问题如下

[root@10-7-162-198 ~]# cat /proc/sys/net/ipv4/conf/eth1/rp_filter

1

##解决方法

[root@10-7-162-198 ~]# echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter

[root@10-7-162-198 ~]# echo 0 > /proc/sys/net/ipv4/conf/eth2/rp_filter

[root@10-7-162-198 ~]# ipsec verify

Verifying installed system and configuration files

Version check and ipsec on-path                        [OK]

Libreswan 3.25 (netkey) on 4.19.0-9.el7.ucloud.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]

[root@10-7-162-198 ~]#

[root@10-7-162-198 ~]#

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

推荐阅读更多精彩内容

  • L2TP+IPSec虚拟专用网 特点:跨平台,数据加密传输,安全 1,部署IPSec服务 1)安装软件包 [roo...
    4a873e424089阅读 3,429评论 0 1
  • 用到的软件openswan(ipsec) : 提供一个密钥ppp :提供用户名和密码xl2tpd : 提供L2TP...
    梅梅呐阅读 10,305评论 1 3
  • 讲真,我已经快被这个弄疯了!不是电脑连不上就是手机连不上。PPTP也没这么多问题啊! F**K!先把我的配置放上来...
    真的是选么阅读 6,435评论 4 3
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,606评论 28 53
  • 首先介绍下自己的背景: 我11年左右入市到现在,也差不多有4年时间,看过一些关于股票投资的书籍,对于巴菲特等股神的...
    瞎投资阅读 5,788评论 3 8