What happened with the
Code: Select all
/ip route check <address>
I was using it in a few scripts and they are broken on upgrade to 7.1beta1...
/ip route check <address>
Well, I use it in scripts to get the nexthop of the route to a given address or, using something global like 1.1.1.1, of "the internet". Something like:Check is not implemented in ROS v7.
What does check give you that "/routing route print" does not?
:local gateway ([/ip route check [:resolve my.vpn.server] once as-value]->"nexthop")
ip route get <host>
/ip route print detail where x.x.x.x in dst-address and active
DAd dst-address=0.0.0.0/0 routing-table=main pref-src="" gateway=10.155.101.1 immediate-gw=10.155.101.1%bridge
type=unicast distance=1 scope=30 target-scope=10
Cool! I was not aware of the use of "ipv4-address in ipv5-address" for the routing table. So this will be enough for what i'm doing:You can get route that resolves specified destination:
From there you can read immediate-gw which shows out interface and gateway IP.Code: Select all/ip route print detail where x.x.x.x in dst-address and active DAd dst-address=0.0.0.0/0 routing-table=main pref-src="" gateway=10.155.101.1 immediate-gw=10.155.101.1%bridge type=unicast distance=1 scope=30 target-scope=10
:put (([/ip route print detail as-value where 1.1.1.1 in dst-address and active]->0)->"gateway")
192.168.88.1
# or
:put (([/ip route print detail as-value where 1.1.1.1 in dst-address and active]->0)->"immediate-gw")
192.168.88.1%wan-bridge
It was working for the particular case when I asked but it does not work for all cases. A simple non-functional example follows.You can get route that resolves specified destination:
From there you can read immediate-gw which shows out interface and gateway IP.Code: Select all/ip route print detail where x.x.x.x in dst-address and active DAd dst-address=0.0.0.0/0 routing-table=main pref-src="" gateway=10.155.101.1 immediate-gw=10.155.101.1%bridge type=unicast distance=1 scope=30 target-scope=10
[admin@Mikrotik] > /routing/route/print detail where 192.168.1.1 in dst-address and active
Flags: X - disabled, I - inactive, F - filtered, U - unreachable, A - active;
c - connect, s - static, r - rip, b - bgp, o - ospf, d - dhcp, v - vpn, m - modem, a - ldp-address, l - ldp-mapping; + - ecmp
Av afi=ip4 contribution=active dst-address=0.0.0.0/0 routing-table=main pref-src="" gateway=movi immediate-gw=movi distance=1
scope=30 target-scope=10 belongs-to="VPN route"
debug.fwp-ptr=0x20242514
As afi=ip4 contribution=active dst-address=192.168.0.0/16 routing-table=main pref-src="" gateway=unreachable immediate-gw=""
distance=5 scope=250 target-scope=10 belongs-to="Static route"
debug.fwp-ptr=0x20242000
Ac afi=ip4 contribution=active dst-address=192.168.1.0/24 routing-table=main gateway=ether1 immediate-gw=ether1 distance=0
scope=10 belongs-to="Connected route" local-address=192.168.1.33%ether1
debug.fwp-ptr=0x20242578
:put ([/ip route check x.x.x.x as-value once ]->"interface")
default route is installed by this interface, that is the reason for having VPN flag.The pppoe-client interface is called "movi".
And regarding other routes it is obvious, that 192.168.1.0/24 will be used. More specific route is always preferred.
Cisco/Arista:
======
show ip route [address [mask] [longer-prefixes]] | [protocol [process-id]]
Juniper:
========
show route
<all>
<destination-prefix>
<logical-system (all | logical-system-name)>
[omitted extra options]
Linux:
======
testhost> ip route show to match 1.1.1.1
default via 2.2.2.2 dev ens5 proto dhcp src 2.2.2.24 metric 100
testhost> ip route get 1.1.1.1
1.1.1.1 via 2.2.2.2 dev ens5 src 2.2.2.24 uid 1000
cache
How do I check longer prefixes or resolve a shorter route? It would be nice to resolve 172.23.253.1 to a route in the table.What you have shown in your examples is exactly what routing/route/print does.
[olof@80003p-cpe002] /ip/route> print where dst-address=172.23.253.0/24
Flags: A - ACTIVE; s, y - COPY
Columns: DST-ADDRESS, GATEWAY, DISTANCE
# DST-ADDRESS GATEWAY DISTANCE
1 As 172.23.253.0/24 172.24.1.113 1
[olof@80003p-cpe002] /ip/route> print where dst-address=172.23.253.1
/ip/route/check gives you one answer. While "as-value" of the above "where <ip> in dst-adress" returns an array.As mentioned earlier in this topic "print where x.x.x.x in dst-address" returns all the routes that particular address can be resolved.
:global ipcheck
:set $ipcheck do={
:local ip2check [:toip $1]
:local typeip [:typeof $ip2check]
:if (typeip~"ip|ip6") do={
:local lookup [/ip/route/find where $ip2check in dst-address and active]
:local lastone ($lookup->([:len $lookup]-1))
:local rv [/ip/route/get $lastone immediate-gw]
:return $rv
} else={
:error "\$ipcheck requires an IP address/range as input"
}
}
# TEST
:put [$ipcheck 1.1.1.1]
:set [/ip/route/check] do={...}
I wasn't saying you didn't – Just saying it does do :nothing in v7, and did do something in v6. And, the OP wanted the routing decision from ROS POV, not all the possible ones.I know what "check" command does.
I'm sure he meant "ip route get" under Linux:What you have shown in your examples is exactly what routing/route/print does.
/ip route print detail where dst-address=8.8.8.0/24 # 1:25
/ip route print detail where dst-address=8.8.8.0/24 and active # 1:15
/ip route print detail where 8.8.8.8 in dst-address # 1:33
/ip route print detail where 8.8.8.8 in dst-address and active # 1:31
/routing route print detail where dst-address=8.8.8.0/24 # 1:42
/routing route print detail where dst-address=8.8.8.0/24 and active # 1:11
/routing route print detail where 8.8.8.8 in dst-address # 1:21
/routing route print detail where 8.8.8.8 in dst-address and active # 1:46