Static routes

    Netifd supports static IP route declarations which are required to implement basic routing.

    Static IPv4 routes can be defined on specific interfaces using route sections. As for aliases, multiple sections can be attached to an interface. The route sections are stored in the uci file /etc/config/network.

    A minimal example looks like this:

    config route 'route_example_1'
            option interface 'lan'
            option target '172.16.123.0'
            option netmask '255.255.255.0'
            option gateway '172.16.123.100'
    • lan is the logical interface name of the parent interface
    • 172.16.123.0 is the network address of the route
    • 255.255.255.0 specifies the route netmask

    Another example, creating a default route for table 100 with the gateway 10.72.197.110:

    config route 'route_example_2'
            option interface 'vpn'
            option target '0.0.0.0/0'
            option table '100'
            option gateway '10.72.197.110'
    • vpn is the logical interface name of the parent interface
    • 0.0.0.0/0 is the subnet address all includes all IPs, because we use a subnet we don't need to use netmask
    • 100 is the specific table number, if you want it to be shown as a name, add it to /etc/iproute2/rt_tables

    This is a persistent equivalent to the runtime command:

    ip route add default via 10.72.197.110 table 100
    NameTypeRequiredDefaultDescription
    interfacestringyes(none)Specifies the logical interface name of the parent (or master) interface this route belongs to; must refer to one of the defined interface sections
    targetip addressyes(none)Network address
    netmasknetmaskno(none)Route netmask. If omitted, 255.255.255.255 is assumed which makes target a host address
    gatewayip addressno(none)Network gateway. If omitted, the gateway from the parent interface is taken if any, otherwise creates a link scope route; if set to 0.0.0.0 no gateway will be specified for the route
    metricnumberno0Specifies the route metric to use
    mtunumbernointerface MTUDefines a specific MTU for this route
    tablerouting tablenomainDefines the table ID to use for the route. The ID can be either a numeric table index ranging from 0 to 65535 or a symbolic alias declared in /etc/iproute2/rt_tables. The special aliases local (255), main (254) and default (253) are recognized as well
    sourceip addressno(none)The preferred source address when sending to destinations covered by the target
    onlinkbooleanno0When enabled gateway is on link even if the gateway does not match any interface prefix
    typestringnounicastOne of the types outlined in the routing types table below
    protorouting protocolnostaticDefines the protocol ID to use for the route. The ID can be either a numeric value ranging from 0 to 255 or a symbolic alias declared in /etc/iproute2/rt_protos.
    disabledbooleanno0Specifies if the static route should be set or not, available since OpenWrt >= 21.02.

    IPv6 routes can be specified as well by defining one or more route6 sections.

    A minimal example looks like this:

    config route6
            option interface 'lan'
            option target '2001:0DB8:100:F00:BA3::1/64'
            option gateway '2001:0DB8:99::1'
    • lan is the logical interface name of the parent interface
    • 2001:0DB8:100:F00:BA3::1/64 is the routed IPv6 subnet in CIDR notation
    • 2001:0DB8:99::1 specifies the IPv6 gateway for this route
    NameTypeRequiredDefaultDescription
    interfacestringyes(none)Specifies the logical interface name of the parent (or master) interface this route belongs to; must refer to one of the defined interface sections
    targetipv6 addressyes(none)IPv6 network address
    gatewayipv6 addressno(none)IPv6 gateway. If omitted, the gateway from the parent interface is taken
    metricnumberno0Specifies the route metric to use
    mtunumbernointerface MTUDefines a specific MTU for this route
    tablerouting tablenomainDefines the table ID to use for the route. The ID can be either a numeric table index ranging from 0 to 65535 or a symbolic alias declared in /etc/iproute2/rt_tables. The special aliases local (255), main (254) and default (253) are recognized as well
    sourceip addressno(none)The route source address in source-address dependent routes. It's called “from” in the ip command.
    onlinkbooleanno0When enabled gateway is on link even if the gateway does not match any interface prefix
    typestringnounicastOne of the types outlined in the Routing Types table below
    protorouting protocolnostaticDefines the protocol ID to use for the route. The ID can be either a numeric value ranging from 0 to 255 or a symbolic alias declared in /etc/iproute2/rt_protos.
    disabledbooleanno0Specifies if the static route should be set or not, available since OpenWrt >= 21.02.

    Routing types

    TypeDescription
    unicastthe route entry describes real paths to the destinations covered by the route prefix.
    localthe destinations are assigned to this host. The packets are looped back and delivered locally.
    broadcastthe destinations are broadcast addresses. The packets are sent as link broadcasts.
    multicasta special type used for multicast routing. It is not present in normal routing tables.
    unreachablethese destinations are unreachable. Packets are discarded and the ICMP message host unreachable is generated. The local senders get an EHOSTUNREACH error.
    prohibitthese destinations are unreachable. Packets are discarded and the ICMP message communication administratively prohibited is generated. The local senders get an EACCES error.
    blackholethese destinations are unreachable. Packets are discarded silently. The local senders get an EINVAL error.
    anycastthe destinations are anycast addresses assigned to this host. They are mainly equivalent to local with one difference: such addresses are invalid when used as the source address of any packet.
    This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
    • Last modified: 2023/05/05 08:25
    • by vgaetera