ROS公司出了一个新需求,pppoe-client拨号失败的时候,同时ip-pool要更新相应的地址池给用户pptp使用
保证用户下次拨号进来的时候,能有网络可用。
#定义一个局部变量ippool
:local ippool
#进入到pppoe拨号接口下
/interface pppoe-client
#查找当前接口下,拨号是成功running的接口,同时把这个接口编号取出来,取第9位到第11位,拼成IP地址172.22.22.*,并复制给变量ippool,注意这个变量是数组,我用tostr转换数组为字符串失败。我也不知道为啥
:foreach i in [find] do={:if [get $i running ] do={:set ippool {$ippool . "172.22.22." . [:pick [get $i name] 9 11] . ","}}}
#进入到/ip pool拨号接口下
/ip pool
#设置范围为ippool,注意ippool是数组,所以这边取数组的第一个值
set pptp ranges=[:pick $ippool 0]
#打印变量ippool
:log error [:pick $ippool 0]
:log error "ip pool set ok!!!"
路由器完整的配置如下
/interface bridge add name=bridge1-lan add name=bridge2-wan /interface vlan add interface=bridge2-wan name=vlan821 vlan-id=821 add interface=bridge2-wan name=vlan822 vlan-id=822 add interface=bridge2-wan name=vlan823 vlan-id=823 add interface=bridge2-wan name=vlan824 vlan-id=824 add interface=bridge2-wan name=vlan825 vlan-id=825 /interface vrrp add interface=vlan821 name=vrrp35 vrid=35 add interface=vlan821 name=vrrp36 vrid=36 add interface=vlan821 name=vrrp37 vrid=37 add interface=vlan821 name=vrrp38 vrid=38 add interface=vlan822 name=vrrp39 vrid=39 add interface=vlan822 name=vrrp40 vrid=40 add interface=vlan822 name=vrrp41 vrid=41 add interface=vlan822 name=vrrp42 vrid=42 add interface=vlan823 name=vrrp43 vrid=43 add interface=vlan823 name=vrrp44 vrid=44 add interface=vlan823 name=vrrp45 vrid=45 add interface=vlan823 name=vrrp46 vrid=46 add interface=vlan824 name=vrrp47 vrid=47 add interface=vlan824 name=vrrp48 vrid=48 add interface=vlan824 name=vrrp49 vrid=49 add interface=vlan824 name=vrrp50 vrid=50 add interface=vlan825 name=vrrp51 vrid=51 add interface=vlan825 name=vrrp52 vrid=52 add interface=vlan825 name=vrrp53 vrid=53 add interface=vlan825 name=vrrp54 vrid=54 /interface pppoe-client ......................<br>20个拨号 /ip pool add name=pptp ranges="172.22.22.1,172.22.22.2,172.22.22.3,172.22.22.4,172.22.2\ 2.5,172.22.22.6,172.22.22.7,172.22.22.8,172.22.22.9,172.22.22.10,172.22.22\ .12,172.22.22.13,172.22.22.14,172.22.22.15,172.22.22.16,172.22.22.17,172.2\ 2.22.18,172.22.22.19,172.22.22.20" /ppp profile set *FFFFFFFE dns-server=223.5.5.5,223.6.6.6 idle-timeout=1h local-address=\ 172.22.22.254 on-up=":log error (\$\"user\".\"/\".\$\"local-address\".\"/\ \".\$\"remote-address\".\"/\".\$\"caller-id\".\"/\".\$\"called-id\".\"/\".\ \$\"interface\")\r\ \n:log error (\$\"remote-address\")\r\ \n:global aaa [:pick \$\"remote-address\" 10 13]\r\ \n:log error \$aaa\r\ \n/interface pppoe-client enable (\"pppoe-out\".\$aaa)" only-one=no \ remote-address=pptp /interface bridge port add bridge=bridge1-lan interface=ether12 add bridge=bridge1-lan interface=ether11 add bridge=bridge1-lan interface=ether10 add bridge=bridge1-lan interface=ether9 add bridge=bridge2-wan interface=ether1 add bridge=bridge2-wan interface=ether2 add bridge=bridge2-wan interface=ether3 add bridge=bridge2-wan interface=ether4 add bridge=bridge2-wan interface=ether5 add bridge=bridge2-wan interface=ether6 add bridge=bridge2-wan interface=ether7 add bridge=bridge2-wan interface=ether8 /interface pptp-server server set enabled=yes /ip address add address=192.168.64.201/24 interface=bridge1-lan network=192.168.64.0 add address=12.12.1.1 interface=vlan821 network=12.12.1.1 add address=12.12.1.2 interface=vlan822 network=12.12.1.2 add address=12.12.1.3 interface=vlan823 network=12.12.1.3 add address=12.12.1.4 interface=vlan824 network=12.12.1.4 add address=12.12.1.5 interface=vlan825 network=12.12.1.5 add address=12.12.2.5 interface=vrrp35 network=12.12.2.5 add address=12.12.2.6 interface=vrrp36 network=12.12.2.6 add address=12.12.2.7 interface=vrrp37 network=12.12.2.7 add address=12.12.2.8 interface=vrrp38 network=12.12.2.8 add address=12.12.2.9 interface=vrrp39 network=12.12.2.9 add address=12.12.2.10 interface=vrrp40 network=12.12.2.10 add address=12.12.2.11 interface=vrrp41 network=12.12.2.11 add address=12.12.2.12 interface=vrrp42 network=12.12.2.12 add address=12.12.2.13 interface=vrrp43 network=12.12.2.13 add address=12.12.2.14 interface=vrrp44 network=12.12.2.14 add address=12.12.2.15 interface=vrrp45 network=12.12.2.15 add address=12.12.2.16 interface=vrrp46 network=12.12.2.16 add address=12.12.2.17 interface=vrrp47 network=12.12.2.17 add address=12.12.2.18 interface=vrrp48 network=12.12.2.18 add address=12.12.2.19 interface=vrrp49 network=12.12.2.19 add address=12.12.2.20 interface=vrrp50 network=12.12.2.20 add address=12.12.2.21 interface=vrrp51 network=12.12.2.21 add address=12.12.2.22 interface=vrrp52 network=12.12.2.22 add address=12.12.2.23 interface=vrrp53 network=12.12.2.23 add address=12.12.2.24 interface=vrrp54 network=12.12.2.24 /ip dns set servers=223.5.5.5 /ip firewall address-list add address=192.168.0.0/16 list=lanip add address=172.16.0.0/16 list=lanip add address=10.0.0.0/8 list=lanip /ip firewall mangle add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp1 passthrough=no src-address=172.22.22.1 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp2 passthrough=no src-address=172.22.22.2 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp3 passthrough=no src-address=172.22.22.3 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp4 passthrough=no src-address=172.22.22.4 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp5 passthrough=no src-address=172.22.22.5 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp6 passthrough=no src-address=172.22.22.6 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp7 passthrough=no src-address=172.22.22.7 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp8 passthrough=no src-address=172.22.22.8 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp9 passthrough=no src-address=172.22.22.9 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp10 passthrough=no src-address=172.22.22.10 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp11 passthrough=no src-address=172.22.22.11 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp12 passthrough=no src-address=172.22.22.12 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp13 passthrough=no src-address=172.22.22.13 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp14 passthrough=no src-address=172.22.22.14 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp15 passthrough=no src-address=172.22.22.15 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp16 passthrough=no src-address=172.22.22.16 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp17 passthrough=no src-address=172.22.22.17 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp18 passthrough=no src-address=172.22.22.18 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp19 passthrough=no src-address=172.22.22.19 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp20 passthrough=no src-address=172.22.22.20 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp21 passthrough=no src-address=172.22.22.21 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp22 passthrough=no src-address=172.22.22.22 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp23 passthrough=no src-address=172.22.22.23 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp24 passthrough=no src-address=172.22.22.24 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp25 passthrough=no src-address=172.22.22.25 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp26 passthrough=no src-address=172.22.22.26 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp27 passthrough=no src-address=172.22.22.27 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp28 passthrough=no src-address=172.22.22.28 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp29 passthrough=no src-address=172.22.22.29 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp30 passthrough=no src-address=172.22.22.30 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp31 passthrough=no src-address=172.22.22.31 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp32 passthrough=no src-address=172.22.22.32 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp33 passthrough=no src-address=172.22.22.33 add action=mark-routing chain=prerouting dst-address-list=!lanip \ new-routing-mark=pptp34 passthrough=no src-address=172.22.22.34 /ip firewall nat add action=masquerade chain=srcnat out-interface=all-ppp add action=masquerade chain=srcnat out-interface=bridge1-lan /ip route add distance=1 gateway=pppoe-out1 routing-mark=pptp1 add distance=1 gateway=pppoe-out2 routing-mark=pptp2 add distance=1 gateway=pppoe-out3 routing-mark=pptp3 add distance=1 gateway=pppoe-out4 routing-mark=pptp4 add distance=1 gateway=pppoe-out5 routing-mark=pptp5 add distance=1 gateway=pppoe-out6 routing-mark=pptp6 add distance=1 gateway=pppoe-out7 routing-mark=pptp7 add distance=1 gateway=pppoe-out8 routing-mark=pptp8 add distance=1 gateway=pppoe-out9 routing-mark=pptp9 add distance=1 gateway=pppoe-out10 routing-mark=pptp10 add distance=1 gateway=pppoe-out11 routing-mark=pptp11 add distance=1 gateway=pppoe-out12 routing-mark=pptp12 add distance=1 gateway=pppoe-out13 routing-mark=pptp13 add distance=1 gateway=pppoe-out14 routing-mark=pptp14 add distance=1 gateway=pppoe-out15 routing-mark=pptp15 add distance=1 gateway=pppoe-out16 routing-mark=pptp16 add distance=1 gateway=pppoe-out17 routing-mark=pptp17 add distance=1 gateway=pppoe-out18 routing-mark=pptp18 add distance=1 gateway=pppoe-out19 routing-mark=pptp19 add distance=1 gateway=pppoe-out20 routing-mark=pptp20 add distance=1 dst-address=10.0.0.0/8 gateway=192.168.64.254 add distance=1 dst-address=172.16.0.0/16 gateway=192.168.64.254 add distance=1 dst-address=192.168.0.0/16 gateway=192.168.64.254 /ppp secret add name=xxxxxx password=xxxxx profile=default-encryption service=pptp /system clock set time-zone-name=Asia/Shanghai /system clock manual set dst-delta=+08:00 time-zone=+08:00 /system scheduler add interval=1m name=pppoe-ip-pool on-event=ippool policy=\ ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \ start-date=jul/21/2022 start-time=13:19:15 /system script add dont-require-permissions=no name=ippool owner=admin policy=\ ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\ \B6\A8\D2\E5\D2\BB\B8\F6\BE\D6\B2\BF\B1\E4\C1\BFippool\r\ \n:local ippool\r\ \n#\BD\F8\C8\EB\B5\BDpppoe\B2\A6\BA\C5\BD\D3\BF\DA\CF\C2\r\ \n/interface pppoe-client\r\ \n#\B2\E9\D5\D2\B5\B1\C7\B0\BD\D3\BF\DA\CF\C2\A3\AC\B2\A6\BA\C5\CA\C7\B3\ \C9\B9\A6running\B5\C4\BD\D3\BF\DA\A3\AC\CD\AC\CA\B1\B0\D1\D5\E2\B8\F6\BD\ \D3\BF\DA\B1\E0\BA\C5\C8\A1\B3\F6\C0\B4\A3\AC\C8\A1\B5\DA9\CE\BB\B5\BD\B5\ \DA11\CE\BB\A3\AC\C6\B4\B3\C9IP\B5\D8\D6\B7172.22.22.*\A3\AC\B2\A2\B8\B4\ \D6\C6\B8\F8\B1\E4\C1\BFippool\A3\AC\D7\A2\D2\E2\D5\E2\B8\F6\B1\E4\C1\BF\ \CA\C7\CA\FD\D7\E9\r\ \n:foreach i in [find] do={:if [get \$i running ] do={:set ippool {\$ippo\ ol . \"172.22.22.\" . [:pick [get \$i name] 9 11] . \",\"}}}\r\ \n#\BD\F8\C8\EB\B5\BD/ip pool\B2\A6\BA\C5\BD\D3\BF\DA\CF\C2\r\ \n/ip pool\r\ \n#\C9\E8\D6\C3\B7\B6\CE\A7\CE\AAippool\A3\AC\D7\A2\D2\E2ippool\CA\C7\CA\ \FD\D7\E9\A3\AC\CB\F9\D2\D4\D5\E2\B1\DF\C8\A1\CA\FD\D7\E9\B5\C4\B5\DA\D2\ \BB\B8\F6\D6\B5\r\ \nset pptp ranges=[:pick \$ippool 0]\r\ \n#\B4\F2\D3\A1\B1\E4\C1\BFippool\r\ \n:log error [:pick \$ippool 0]\r\ \n:log error \"ip pool set ok!!!\""