Community discussions

MikroTik App
 
michalp49
just joined
Topic Author
Posts: 2
Joined: Fri Jan 14, 2022 5:45 pm

ping - missing routing-table

Sat Jan 15, 2022 3:00 pm

Hi,

in RouterOS 6 I have a running script that checks the status of the main and backup links. It works as follows (the script is quite complex, but it comes down to executing the command):
ping 8.8.8.8 interval=300ms routing-table=internet1
ping 8.8.8.8 interval=300ms routing-table=internet2

For proper operation, the following entries are necessary:
/ip route
add distance=1 gateway=172.16.0.1 routing-mark=internet1
add distance=2 routing-mark=internet1 type=blackhole
add distance=1 gateway=172.16.100.1 routing-mark=internet2
add distance=2 routing-mark=internet2 type=blackhole

add distance=1 gateway=172.16.0.1 comment="wan_monitoring: internet1" disabled=no
add distance=2 gateway=172.16.100.1 comment="wan_monitoring: internet2" disabled=yes
# the script switches the last two commands depending on which link is active

/ip firewall mangle
add action=mark-connection chain=input comment=WAN1_main in-interface=\
    WAN1_main new-connection-mark=MWAN1 passthrough=yes
add action=mark-routing chain=output connection-mark=MWAN1 new-routing-mark=\
    internet1 passthrough=no
add action=mark-connection chain=forward comment=WAN1PF connection-state=new \
    in-interface=WAN1_main new-connection-mark=PFMWAN1 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=PFMWAN1 \
    in-interface=bridge1 new-routing-mark=internet1 passthrough=yes

add action=mark-connection chain=input comment=WAN2_T-Mobile in-interface=\
    WAN2_T-Mobile new-connection-mark=MWAN2 passthrough=yes
add action=mark-routing chain=output connection-mark=MWAN2 new-routing-mark=\
    internet2 passthrough=no
add action=mark-connection chain=forward comment=WAN2PF connection-state=new \
    in-interface=WAN2_T-Mobile new-connection-mark=PFMWAN2 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=PFMWAN2 \
    in-interface=bridge1 new-routing-mark=internet2 passthrough=yes
***
After upgrading to RouterOS 7, this method no longer works because the ping command no longer has the: routing-table parameter. How in RouterOS 7 can I ping with two different internet connections - use the first one once, and then the second when the first or the second is active?
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: ping - missing routing-table

Sun Jan 16, 2022 10:41 pm

I don't know what's the correct, officially recommended solution, but it seems that you can add empty VRF:
/ip vrf add interfaces=none name=internet1
It will create routing table with same name, which you can use for creating routes, and then you can use vrf=internet1 for ping.
 
michalp49
just joined
Topic Author
Posts: 2
Joined: Fri Jan 14, 2022 5:45 pm

Re: ping - missing routing-table

Wed Jan 19, 2022 8:18 am

I fail, I don't quite understand it yet. Can You write to me how to specifically do this in RouterOS 7: two internet links (if the first ISP is active, the second ISP is disabled), and I'd like to be able to ping any address with each of them.
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: ping - missing routing-table

Sun Jan 23, 2022 3:15 am

As I wrote, I don't know what's the right way. Ping in v7 doesn't have routing-table parameter anymore, but it has vrf parameter. So I just came up with a quick way how to use that, and it seems to work. In v7 you have to manually create routing tables in "/routing table", but you can skip that and create them using VRF instead. That's the command I posted, which will create dynamic routing table (which can then be used same way as static one). And that's it. I'm not sure that I like it, and I don't know if there could be some unexpected problems with it. Hopefully someone more knowledgeable will comment on that.
 
fragtion
Member Candidate
Member Candidate
Posts: 257
Joined: Fri Nov 13, 2009 10:08 pm
Location: Johannesburg, South Africa

Re: ping - missing routing-table

Sun Jan 23, 2022 4:14 am

Here's my wan checking scripts updated to work with ros v7. It's not perfect (improvements welcome) and is going to need some adaptation, but maybe some of it helps you

pppoe
:global pppoe1up
:global pppoe1forceoff
:global pppoe1lastip1
:global pppoe1lastip2

:if ([/interface/pppoe-client/get pppoe1 running]=true) do={
  :local ipfresh1 [/ip/address/get [/ip/address/find where interface=pppoe1] address]
  :local ipfresh2
  if ($pppoe1lastip1 != $ipfresh1) do={
    log error ("pppoe1 IP changed")
    :if ([ :typeof $ipfresh1 ] != nil ) do={
      :for i from=( [:len $ipfresh1] - 1) to=0 do={
        :if ( [:pick $ipfresh1 $i] = "/") do={
          :set ipfresh2 [:pick $ipfresh1 0 $i];
        }
      }
    }
    global pppoe1lastip1 $ipfresh1
    global pppoe1lastip2 $ipfresh2
  }
  :if ($pppoe1up != true && $pppoe1up != false) do={ :global pppoe1up true }
  :if ($pppoe1forceoff = true)  do={
    :if ($pppoe1up = true) do={
      :log error "pppoe1 MARKED OFFLINE!"
      :set pppoe1up false
      /ip/route/set [/ip/route/find where comment=pppoe1 disabled=no] disabled=yes
      /system/script/run flush_wanconn
    }
  } else={
    :local count [/ping address="1.1.1.1" interface="pppoe1" src-address="$pppoe1lastip2" size=28 interval=0.1 count=50]
    :if ($count < 30) do={
      :if ($pppoe1up = true) do={
        :log error "pppoe1 MARKED OFFLINE!"
        :set pppoe1up false
        /ip/route/set [/ip/route/find where comment=pppoe1 disabled=no] disabled=yes
        /system/script/run flush_wanconn
      }
    } else={
      :if ($pppoe1up = false) do={
        :log error "pppoe1 MARKED ONLINE!"
        :set pppoe1up true
        /ip/route/set [/ip/route/find where comment=pppoe1 disabled=yes] disabled=no
        /system/script/run flush_wanconn
      } else={
        :if ([/ip/route/find where comment=pppoe1 disabled=yes]) do={
          :log error "pppoe1 ONLINE BUT ROUTES DISABLED! RE-ENABLING..."
          /ip/route/set [/ip/route/find where comment=pppoe1 disabled=yes] disabled=no
        }
      }
    } 
  }
} else={
  :if ($pppoe1up = true) do={
    :log error "pppoe1 MARKED OFFLINE!"
    :set pppoe1up false
    /ip route set [/ip route find where comment=pppoe1 disabled=no] disabled=yes
    /system/script/run flush_wanconn
  }
}
External (routed) gateway:
:global lte1up
:global lte1forceoff

:if ([/interface/ethernet/get ether3_lte running]=true) do={
  :if ($lte1up != true && $lte1up != false) do={ :global lte1up true }
  :if ($lte1forceoff = true)  do={
    :if ($lte1up = true) do={
      :log error "lte1 MARKED OFFLINE!"
      :set lte1up false
      /ip/route/set [/ip/route/find where comment=lte1 disabled=no] disabled=yes
    /system/script/run flush_wanconn
    }
  } else={
    :local count [/ping address="1.1.1.1" interface="ether3_lte" src-address="192.168.8.2" size=28 interval=1 count=5]
    :if ($count < 2) do={
      :if ($lte1up= true) do={
        :log error "lte1 MARKED OFFLINE!"
        :set lte1up false
        /ip/route/set [/ip/route/find where comment=lte1 disabled=no] disabled=yes
        /system/script/run flush_wanconn
      }
    } else={
      :if ($lte1up= false) do={
        :log error "lte1 MARKED ONLINE!"
        :set lte1up true
        /ip/route/set [/ip/route/find where comment=lte1 disabled=yes] disabled=no
        /system/script/run flush_wanconn
      } else={
        :if ([/ip/route/find where comment=lte1 disabled=yes]) do={
          :log error "lte1 ONLINE BUT ROUTES DISABLED! RE-ENABLING..."
          /ip/route/set [/ip/route/find where comment=lte1 disabled=yes] disabled=no
        }
      }
    }
  } 
} else={
  :if ($lte1up= true) do={
    :log error "lte1 MARKED OFFLINE!"
    :set lte1up false
    /ip route set [/ip route find where comment=lte1 disabled=no] disabled=yes
    /system/script/run flush_wanconn
  }
}
The second type needs some additional config:
/routing/table add disabled=no fib name=check_lte1
/routing/rule add action=lookup disabled=no dst-address=1.1.1.1/32 src-address=192.168.8.2/32 table=check_lte1
/ip/route add comment="internet check" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=192.168.8.1 routing-table=check_lte1
Looking at how much code is needed to achieve this kind of functionality, I feel there should be an easier way to handle this. I know about netwatch, but netwatch does not let you choose the same host for multiple interfaces or have the same customizability of trigger conditions for the ping,,
 
sin3vil
newbie
Posts: 34
Joined: Sat May 26, 2018 10:05 pm

Re: ping - missing routing-table

Thu Feb 17, 2022 12:58 am

I don't know what's the correct, officially recommended solution, but it seems that you can add empty VRF:
/ip vrf add interfaces=none name=internet1
It will create routing table with same name, which you can use for creating routes, and then you can use vrf=internet1 for ping.
Holy flying spaghetti monster, thanks a lot for that.
It never occurred to me that you could use none as a VRF interface and setting it to anything complete moved all ingress traffic from that interface to the VRF.
Using none I've emulated ROS6-style simple routing-table functionality.
 
jonthorpe
just joined
Posts: 15
Joined: Mon Oct 27, 2014 3:25 am

Re: ping - missing routing-table

Wed Oct 25, 2023 7:03 am

Has anyone had success getting this working for a PPP interface such as those used for USB 4G modems that aren't able to use the LTE mode?
 
rplant
Member Candidate
Member Candidate
Posts: 287
Joined: Fri Sep 29, 2017 11:42 am

Re: ping - missing routing-table

Fri Oct 27, 2023 1:48 am

It seems like you can use

ping destination interface=xxxx

And it fails if it can't reach destination via that interface.
(traceroute tries, but will use whatever is available if doesn't work via interface though)
 
jonthorpe
just joined
Posts: 15
Joined: Mon Oct 27, 2014 3:25 am

Re: ping - missing routing-table

Wed Nov 01, 2023 12:10 am

It seems like you can use

ping destination interface=xxxx

And it fails if it can't reach destination via that interface.
(traceroute tries, but will use whatever is available if doesn't work via interface though)
That works - thanks!

Who is online

Users browsing this forum: No registered users and 21 guests