首页 > 其他分享 >openwrt l2tp支持设置本地静态ip地址

openwrt l2tp支持设置本地静态ip地址

时间:2023-11-17 17:14:17浏览次数:69  
标签:remote ip LNS accept l2tp local openwrt

设备使用4G网络,设备间需要通讯,又是短连接,必须要是静态ip,所以选择使用l2tp。然后LNS端通过/etc/ppp/chap-secrets为每个帐号绑定一个ip,每个设备使用一个帐号,LNS这端设备默认的隧道保活时间为60s。这时设备端(LAC)正常拨号时获取到的ip为LNS端绑定的,但是如果插拔一下网线,或者断电重启,即保活周期内未明确告知LNS端隧道断开,会导致LAC端拿到的IP不是LNS上绑定的那个,因此会导致设备间的短连接通讯会失败。

网络工程师告知可以通过在LAC端设置静态ip,来解决这个问题,并且在LNS端也不用麻烦的配置一堆的帐号和ip的绑定关系。分析l2tp网络建立的过程知道,隧道通了后会使用ppp来做接下来的工作,而ppp使用IPCP协议来协商网络参数,包括ip地址的分配,dns的分配等。既然是pppd在干活,那么肯定有参数设置,man pppd之,OPTIONS节第一个选项便是:

OPTIONS
       <local_IP_address>:<remote_IP_address>
              Set the local and/or remote interface IP addresses.  Either one may be omitted.  The IP addresses can be specified with a host  name  or  in  decimal  dot  notation  (e.g.
              150.234.56.78).   The default local address is the (first) IP address of the system (unless the noipdefault option is given).  The remote address will be obtained from the
              peer if not specified in any option.  Thus, in simple cases, this option is not required.  If a local and/or remote IP address is specified with this option, pppd will not
              accept a different value from the peer in the IPCP negotiation, unless the ipcp-accept-local and/or ipcp-accept-remote options are given, respectively.

      <本地ip地址>:<远程ip地址>
              设置本地/远程接口IP地址。这两个地址均可省略。IP地址可以指定为一个域名或者点分十进制格式(x.x.x.x)。默认的本地地址是系统网络接口的原本IP地址(即建立隧道的那个网络接口)(除非指定了noipdefault选项)。如果参      
              数里面远程ip地址未指定,则远程地址将从对端获取。因此,简单来说,此选项不是必须的(因为前面提到了local和remote都有默认值)。如果本地/远程IP地址通过此选项指定了,需要对应的设置`ipcp-accept-local`或者 
              `ipcp-accept-remote`选项,否则pppd将不会接受和对端IPCP协商的值。

按照这里的介绍,在/etc/ppp/options.xl2tpd里面配置即可,也可以通过/lib/netifd/proto/l2tp.sh脚本里面使用xl2tpd-config传参的方式实现。大致按照如下方式改动即可

+       local usestaticip localip
+       json_get_vars usestaticip  localip
+       [ "$usestaticip" = "1" ] && {
+               localaddr="${localip:+local ip=$localip}"
+       }
 
-       xl2tpd-control add l2tp-${interface} pppoptfile=${optfile} lns=${server} || {
+       xl2tpd-control add l2tp-${interface} pppoptfile=${optfile} lns=${server} ${localaddr} || {

标签:remote,ip,LNS,accept,l2tp,local,openwrt
From: https://www.cnblogs.com/thammer/p/17839196.html

相关文章

  • python包管理pip常用
    python包管理pip常用 1、pip安装包指定源pipinstall[package]-ihttps://pypi.douban.com/simple 2、pip常用命令 Commandspip常用Commands install  Installpackages download  Downloadpackagesuninstall Uninstallpackagesfreeze Ou......
  • java zip 压缩密码
    在Java开发中,Zip文件是一种常见的文件压缩格式。有时候我们需要给Zip文件添加密码保护,以确保文件的安全性。本文将指导你如何使用Java代码来实现Zip文件的添加密码功能。流程概述下面是实现“JavaZip添加密码”的整个流程:步骤描述步骤1创建一个Zip文件步骤2向Zi......
  • centos执行pip3 install etcd3报错
    centos执行pip3installetcd3报错   File"/usr/lib64/python3.6/os.py",line800,infsencode    filename=fspath(filename) #Doestype-checkingof`filename`.  TypeError:expectedstr,bytesoros.PathLikeobject,notlist这个错误通常是......
  • 2020 NOIP 补题
    P7113[NOIP2020]排水系统拓扑排序,但是\(\_\_int128\)。#include<bits/stdc++.h>usingnamespacestd;#defineendl'\n'#defineinlinline#defineebemplace_back#definepbpop_back#definemid(l+r>>1)#definelsp<<1#definersp......
  • JavaScript之splice()
    参考:https://blog.csdn.net/weixin_45726044/article/details/120151153概述splice()方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组。一个参数splice(index)——>从index的位置开始,删除之后的所有元素(包括......
  • VMware+CentOS7 网络及静态IP配置
     设置“虚拟机网络编辑”打开VMware: 在工具栏的“编辑”选项里有一个“虚拟网络编辑器”,打开:   点击“更改设置”  首先选中VMnet8,下面会显示VMnet信息。我们选择NAT模式;然后将“使用本地DHCP服务奖IP地址分配给虚拟机”的勾选取消掉,因为我们要使用静态IP;最后......
  • mediapipe包实现简单的手势识别
    前言  一开始我还是java和c++的忠实用户,对python多少有点轻视,但很快就发现我错了,python没有java和c++那样严格的各种语法和格式要求,可以说是非常简易的。而且python有着大量的第三方库,可以轻轻松松用十几行代码实现各种各样的功能,代码写起来还是比c++和java轻松许多的。最近也......
  • 关于 Angular SSR 应用 index.html 中的 serverApp-state script 元素
    首先,我们需要了解AngularSSR(Server-SideRendering)以及SSRTransferState。AngularSSR是Angular应用程序的服务端渲染技术,它允许Angular应用程序在服务器上渲染其组件,并生成静态HTML页面,再发送给客户端。这种方法可以提高首次加载速度,提升SEO效果。而SSRTransfe......
  • Dapper QueryMultiple throws "No columns were selected"
    调试存储过程发现某字段NULL,拼成的SQL最后啥也没有了。。。原因是存储过程没有执行到查询SQL语句QueryAsyncthrows"Nocolumnswereselected"whenstoredprocdoesn'tperformaselectstatement #591Closed  toannguyen83 openedthisissue onAug27,20......
  • Angular SSR 应用中 serverApp-state script 的工作原理介绍
    <scriptid="serverApp-state"type="application/json">元素是在服务器端渲染(Server-SideRendering,SSR)Angular应用中用于传递状态数据的重要组成部分。它被称为"SSRTransferState"机制的一部分,其作用是在服务器端生成的HTML页面中嵌入初始数据,以便客户端可以在应用初始......