zoukankan      html  css  js  c++  java
  • 在linux下搭建l2tp隧道

    搭一个l2tp隧道,拓扑如下

    两台机器是CentOS5,内核选上CONFIG_LEGACY_PTYS选项后自己编译的,l2tp是已经停更的l2tpd-0.69。先在LS上配置IP地址,iptables规则,这些不在多说,直接看l2tpd的配置文件

    ;/etc/l2tpd/l2tpd.conf
    [global]
    ; if you run l2tpd on the internal interface only, enable the line below
    ; listen-addr = 192.168.1.98
    [lns default]
    ip range = 192.168.1.128- 192.168.1.254
    local ip = 192.168.1.98
    require chap = yes
    refuse pap = yes
    ;下面这行说的是要PPP认证,我实际测试中感觉有没有这一行都没影响
    require authentication = yes
    ppp debug = yes
    pppoptfile = /etc/ppp/options.l2tpd
    length bit = yes
    

     然后是LS的pppd配置文件如下

    #/etc/ppp/options.l2tpd
    ipcp-accept-local
    ipcp-accept-remote
    ms-dns 192.168.1.1
    ms-dns 192.168.1.3
    ms-wins 192.168.1.1
    ms-wins 192.168.1.3
    noccp
    #noauth
    auth
    crtscts
    idle 1800
    mtu 1200
    mru 1200
    # change line below to defaultroute to make all traffic go through the VPN
    nodefaultroute
    debug
    lock
    proxyarp
    connect-delay 5000
    

    再然后配置pppd的认证文件

    #/etc/ppp/chap-secrets
    "johnsnow"        *       "youknownothing"              192.168.1.0/24
    

     RS的l2tpd的配置文件如下

    ; Connect as a client to a server at 194.168.10.4
    [lac myl2tp]
    lns = 194.168.10.4
    require chap = yes
    refuse pap = yes
    ;require authentication = yes
    ; Name should be the same as the username in the PPP authentication!
    ppp debug = yes
    pppoptfile = /etc/ppp/options.l2tpd.client
    length bit = yes
    

     RS的pppd配置文件如下

    #/etc/ppp/options.l2tpd.client
    ipcp-accept-local
    ipcp-accept-remote
    refuse-eap
    noccp
    #noauth
    noauth
    crtscts
    idle 1800
    mtu 1200
    mru 1200
    #nodefaultroute
    defaultroute
    debug
    lock
    #proxyarp
    connect-delay 5000
    

    RS的pppd认证文件

    #/etc/ppp/chap-secrets
    "johnsnow"        *       "youknownothing"
    

     分别在LS和RS上执行

    l2tpd -c /etc/l2tpd/l2tpd.conf -D
    

     最后在RS上拨号

    echo "c myl2tp" >/var/run/l2tp-control
    

     最后用ifconfig看一下,多了一个ppp接口说明拨号成功了。整个配置过程不难,但是我在配置LS的pppd配置文件时候走了一些弯路,在我配置了auth之后总是拨号不成功,最后在认证文件里最后一列加上了地址(192.168.1.0/24)才能认证成功。我猜想在LS的pppd启动的时候RS的ppp0已经分到了一个192.168.1.0/24网段的地址,导致LS的pppd认证不通过,但是我不确定,非常不确定,有时间把代码看一下。

    这个配置仅仅使用了l2tp协议,并没有使用ipsec相关协议,在网络上还是明文传输的,如果要加密还需要配置ipsec。

  • 相关阅读:
    web动静分离
    vm采用NAT方式连接时,设置静态ip
    nginx实现tcp负载均衡
    读取文件
    线程池源码分析
    mongodb操作
    bind
    Xss攻击
    json和java对象相互转换
    静态资源默认加载路径
  • 原文地址:https://www.cnblogs.com/4a8a08f09d37b73795649038408b5f33/p/12012766.html
Copyright © 2011-2022 走看看