Table of Contents

Rotas estáticas

O Netifd suporta declarações estáticas de rota IP, necessárias para implementar o roteamento básico.

Rotas IPv4

Rotas estáticas IPv4 podem ser definidas em interfaces específicas usando seções route. Quanto aos aliases, várias seções podem ser anexadas a uma interface. As seções route são armazenadas no arquivo uci /etc/config/network.

Um exemplo mínimo se parece com isto:

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'

Outro exemplo: criando uma rota padrão para a tabela 100 com o 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'

Este é um equivalente persistente ao comando de tempo de execução:

ip route add default via 10.72.197.110 tabela 100

Opções para rotas IPv4

Name Type Required Default Description
interface string yes (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
target ip address yes (none) Network address
netmask netmask no (none) Route netmask. If omitted, 255.255.255.255 is assumed which makes target a host address
gateway ip address no (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
metric number no 0 Specifies the route metric to use
mtu number no interface MTU Defines a specific MTU for this route
table routing table no main Defines 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
source ip address no (none) The preferred source address when sending to destinations covered by the target
onlink boolean no 0 When enabled gateway is on link even if the gateway does not match any interface prefix
type string no unicast One of the types outlined in the routing types table below
proto routing protocol no static Defines the protocol ID 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. i.e. kernel, boot, ra, redirect, static
disabled boolean no 0 Specifies if the static route should be set or not, available since OpenWrt >= 21.02.

Rotas IPv6

Rotas IPv6 também podem ser especificadas definindo uma ou mais seções route6.

Um exemplo mínimo seria este:

config route6
        option interface 'lan'
        option target '2001:0DB8:100:F00:BA3::1/64'
        option gateway '2001:0DB8:99::1'

Opções para rotas IPv6

Name Type Required Default Description
interface string yes (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
target ipv6 address yes (none) IPv6 network address
gateway ipv6 address no (none) IPv6 gateway. If omitted, the gateway from the parent interface is taken
metric number no 0 Specifies the route metric to use
mtu number no interface MTU Defines a specific MTU for this route
table routing table no main Defines 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
source ip address no (none) The route source address in source-address dependent routes. It's called “from” in the ip command.
onlink boolean no 0 When enabled gateway is on link even if the gateway does not match any interface prefix
type string no unicast One of the types outlined in the Routing Types table below
proto routing protocol no static Defines the protocol ID 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. i.e. kernel, boot, ra, redirect, static
disabled boolean no 0 Specifies if the static route should be set or not, available since OpenWrt >= 21.02.

Tipos de roteamento

Type Description
unicast the route entry describes real paths to the destinations covered by the route prefix.
local the destinations are assigned to this host. The packets are looped back and delivered locally.
broadcast the destinations are broadcast addresses. The packets are sent as link broadcasts.
multicast a special type used for multicast routing. It is not present in normal routing tables.
unreachable these destinations are unreachable. Packets are discarded and the ICMP message host unreachable is generated. The local senders get an EHOSTUNREACH error.
prohibit these destinations are unreachable. Packets are discarded and the ICMP message communication administratively prohibited is generated. The local senders get an EACCES error.
blackhole these destinations are unreachable. Packets are discarded silently. The local senders get an EINVAL error.
anycast the 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.