Rotas estáticas

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

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'
  • lan é o nome da interface lógica da interface pai
  • 172.16.123.0 é o endereço de rede da rota
  • 255.255.255.0 especifica a máscara de rede da rota

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'
  • vpn é o nome da interface lógica da interface pai
  • 0.0.0.0/0 é o endereço da sub-rede e inclui todos os IPs. Como usamos uma sub-rede, não precisamos usar máscara de rede.
  • 100 é o número da tabela específica. Se você quiser que ele seja exibido como um nome, adicione-o a /etc/iproute2/rt_tables

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

ip route add default via 10.72.197.110 tabela 100
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 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'
  • lan é o nome da interface lógica da interface pai
  • 2001:0DB8:100:F00:BA3::1/64 é a sub-rede IPv6 roteada em notação CIDR
  • 2001:0DB8:99::1 especifica o gateway IPv6 para esta rota
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.
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: 2025/07/07 18:29
  • by marcomangini