Previous: , Up: IP Library   [Contents][Index]


3.3 Route

The (ip route) module introduces procedures to access and modify the network routes on your machine. They are equivalent to the ip route family of commands, from iproute2.

Scheme Procedure: route-add dest [#:ipv6? #f] [#:device #f] [#:table RT_TABLE_MAIN] [#:protocol #f] [#:scope RT_SCOPE_LINK] [#:type RTN_UNICAST] [#:priority #f] [#:src #f] [#:via #f]

Add the route described by the argmuents. dest is the destination network, in cidr notation (addr/prefix) or the string "default".

#:device is the name or index of a network link. #:table is the index of a routing table, one of RT_TABLE_COMPAT, RT_TABLE_DEFAULT, RT_TABLE_MAIN or RT_TABLE_LOCAL, as defined in (netlink constant).

If it is set, #:protocol must be the routing protocol, RTPROT_*, as defined in (netlink constant).

#:scope must be the scope of the route, one of RT_SCOPE_*, as defined in (netlink constant).

#:type must be the type of route, one of RTN_*, as defined in (netlink constant).

If set, #:priority is a number specifying the priority of the rule when the kernel is looking for a matching rule. This is also known as the metric of the route.

If set, #:src is the source address in cidr notation, or as a single address.

If set, #:via is the gateway address. This is not in cidr notation, as the gateway is a single address, not a network.

(route-add "default" #:device "enp1s0" #:via "192.0.2.1")
(route-add "192.0.2.0/24" #:device "enp1s0" #:src "192.0.2.15")

If you wish to add an IPv6 route instead, set #:ipv6 to #t, as in the following example.

(addr-add "2001:db8::/64" #:device "enp1s0" #:src "2001:db8::1a4c" #:ipv6? #t)

Note that using the wrong ip type with the wrong value for the #:ipv6? flag will result in a Bad address exception from inet-pton.

Scheme Procedure: route-del dest [#:ipv6? #f] [#:device #f] [#:table RT_TABLE_MAIN] [#:protocol #f] [#:scope #f] [#:type #f] [#:priority #f] [#:src #f] [#:via #f]

Delete the route given in arguments. The arguments follow the same structure as route-add. By specifying more arguments, you can narrow down the search for the rule to delete further. Each call will only remove one route, so being more precise ensures you target the rule you wish to delete. It is not clear which route is deleted if multiple routes match your query.

Scheme Procedure: route-show [#:table RT_TABLE_MAIN] [#:family AF_UNSPEC]

Print the list of routes on standard output. Note that, contrary to ip route show, we show both IPv4 and IPv6 routes. To narrow down the number of routes displayed, you can specify the family as in this example.

(route-show #:family AF_INET6)

Previous: Addr, Up: IP Library   [Contents][Index]