netifd lets OpenWrt define static IP routes in /etc/config/network. Unlike a temporary ip route add, a route or route6 section is managed by UCI and can be reloaded with its interface.1
Scope: This is about static routes, not dynamic routing protocols. Before applying a route, know which interface reaches the next hop and keep a console or SSH recovery path in case management traffic loses its return route.
1. Basic IPv4 routes
An IPv4 route is a route section attached to a logical interface. The source's minimal example is:
| |
Here lan is the interface carrying the route, 172.16.123.0 is the destination network, and 255.255.255.0 is the netmask. Replace these values with the actual topology; they are not universal defaults.
A default route in table 100 can be declared as follows:
| |
vpn is the logical interface, 0.0.0.0/0 covers all IPv4 destinations, and table 100 is a separate routing table. Define an alias in /etc/iproute2/rt_tables if a symbolic name is preferred. The UCI declaration is the persistent equivalent of:
| |
2. route options
| Option | Type | Required | Default | Meaning |
|---|---|---|---|---|
interface | string | Yes | — | Parent logical interface; it must match a config interface. |
target | IP address | Yes | — | Destination network address. |
netmask | netmask | No | 255.255.255.255 | If omitted, target is treated as a host address. |
gateway | IP address | No | — | Network gateway; if omitted, the parent interface gateway is used when available, otherwise a link-scope route is created; 0.0.0.0 means no gateway. |
metric | number | No | 0 | Route metric. |
mtu | number | No | Interface MTU | Per-route MTU. |
table | routing table | No | main | ID 0–65535 or an alias in /etc/iproute2/rt_tables; special aliases include local 255, main 254, and default 253. |
source | IP address | No | — | Preferred source address for destinations covered by the route. |
onlink | boolean | No | 0 | Treat the gateway as on-link even when it does not match an interface prefix. |
type | string | No | unicast | Route type; see the table below. |
proto | routing protocol | No | static | Numeric ID 0–255 or an alias in /etc/iproute2/rt_protos, such as kernel, boot, ra, redirect, or static. |
disabled | boolean | No | 0 | Disable the route section when enabled; available since OpenWrt >= 21.02. |
Multiple route sections can be attached to one interface. In a real configuration I use names such as route_lan_iot or route_vpn_default so that I do not accidentally edit an existing route.
3. IPv6 routes
IPv6 uses a route6 section:
| |
lan is the logical interface, 2001:0DB8:100:F00:BA3::1/64 is the routed IPv6 subnet in CIDR notation, and 2001:0DB8:99::1 is the IPv6 gateway. 2001:0DB8::/32 is a documentation prefix; use the real prefix in a live network.
4. route6 options
| Option | Type | Required | Default | Meaning |
|---|---|---|---|---|
interface | string | Yes | — | Parent logical interface. |
target | IPv6 address | Yes | — | Destination IPv6 network. |
gateway | IPv6 address | No | — | IPv6 gateway; if omitted, the parent interface gateway is used. |
metric | number | No | 0 | Route metric. |
mtu | number | No | Interface MTU | Per-route MTU. |
table | routing table | No | main | Numeric table or symbolic alias. |
source | IP address | No | — | Source address in a source-dependent route; it is called from by the ip command. |
onlink | boolean | No | 0 | Treat the gateway as on-link outside the interface prefix. |
type | string | No | unicast | Route type from the route-types table. |
proto | routing protocol | No | static | Numeric protocol ID or an alias in /etc/iproute2/rt_protos. |
disabled | boolean | No | 0 | Disable the route; available since OpenWrt >= 21.02. |
5. Routing types
The source also lists the meanings of the type values:
| Type | Meaning |
|---|---|
unicast | The route describes a real path to destinations in the prefix. |
local | Destinations are assigned to this host; packets loop back and are delivered locally. |
broadcast | Destinations are broadcast addresses; packets are sent as link broadcasts. |
multicast | A type for multicast routing, normally absent from ordinary routing tables. |
unreachable | Packets are discarded and ICMP host unreachable is generated; local senders receive EHOSTUNREACH. |
prohibit | Packets are discarded and ICMP administratively prohibited is generated; local senders receive EACCES. |
blackhole | Packets are discarded silently; local senders receive EINVAL. |
anycast | Destinations are anycast addresses assigned to this host; unlike local, they cannot be used as a packet source. |
6. Check the result on the router
After editing /etc/config/network, I inspect UCI and both route tables before closing the management session:
| |
If the route is absent, re-check interface, target, gateway, table, and disabled. Do not add a default route to main merely for testing; a wrong default route can remove the return path for LuCI or SSH.
Conclusion
OpenWrt static routing has three pieces that must agree: the logical interface, the destination/prefix, and the gateway/table. Use route for IPv4 and route6 for IPv6; options such as metric, mtu, source, onlink, type, proto, and disabled matter only when the topology needs them. I keep UCI as the source of truth and use ip route show and ip -6 route show to verify the result.
Sources
OpenWrt Wiki – Static routes , updated 2025-07-07. This is an independent adaptation of the official documentation. ↩︎


Góp Ý / Bình Luận / Đánh giá