你的浏览器无法正常显示内容,请更换或升级浏览器!

RouterOS V7.x下一键创建VPN并指定路由

tenfei
tenfei
发布于2023-10-17 15:39 阅读842次
RouterOS V7.x下一键创建VPN并指定路由
Mikrotik的RouterOS已更新到v7版本,其中有不少的改进,特别是在wireguard提升不少,但同时也带来一些与v6.x不同的操作,这里主要记录一下在ros v7.x下一键添加VPN并进行路由标记的方法。同时也会注明与v6.x的不同之处。 脚本一键创建多VPN,默认创建为l2tp的模式,其中不同于v6.x的是需要单独先在/routing table创建出路由名称,之后才能在/ip firewall mangle和/ip route中指定路由,否则会创建失败,手动的时候表示为找不到路由名称,创建方法:/routing table 路由名称 fib.注意需要指定为fib形式。 ``` :local vpncount :local vpnName :local ips #指定一次创建多少条VPN :set vpncount 1 :set vpnName "vpn" :set ips "172.16." #ros v7.x路由表需要先在/routing table中添加路由表名 指定为fib形式 :for i from=1 to=$vpncount do={ /interface l2tp-client add name=("$vpnName"."$i") disabled=yes connect-to="1" user="vpn" password="vpn" use-ipsec=yes ipsec-secret="1" /routing table add name=("$vpnName"."$i"."-r") fib /ip firewall mangle add chain=prerouting src-address=("$ips"."$i".".0/24") action="mark-routing" new-routing-mark=("$vpnName"."$i"."-r") passthrough=yes /ip route add gateway=("$vpnName"."$i") routing-table=("$vpnName"."$i"."-r") } #全数据伪装转发 /ip firewall nat add chain=srcnat action=masquerade #禁止部分IP段走本地网络 /ip firewall filter add chain="forward" src-address="IP地址段" out-interface="本地WAN口" action=drop ```

3

0

文章点评
暂无任何评论
Copyright © from 2021 by namoer.com
458815@qq.com QQ:458815
蜀ICP备2022020274号-2