AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 425924
Accepted
rsuarez
rsuarez
Asked: 2018-02-23 07:29:04 +0800 CST2018-02-23 07:29:04 +0800 CST 2018-02-23 07:29:04 +0800 CST

No Linux, qual métrica tem uma rota sem métrica?

  • 772

Se você tiver (no Linux) essas duas rotas:

default via 192.168.1.1 dev enp58s0f1
default via 192.168.16.1 dev wlp59s0  proto static  metric 600

Eu esperaria que o primeiro fosse usado, mas não é o caso: o segundo é usado em seu lugar.

Se eu mudar isso para isso:

default via 192.168.1.1 dev enp58s0f1  proto static  metric 100 
default via 192.168.16.1 dev wlp59s0  proto static  metric 600

Então funciona como esperado. Parece que "nenhuma métrica" ​​é uma métrica pior (mais alta) do que qualquer número, em vez da métrica 0.

O que está acontecendo? É específico para Linux ou um padrão de rede?

Desde já, obrigado.

linux networking
  • 3 3 respostas
  • 46791 Views

3 respostas

  • Voted
  1. Best Answer
    Patrick Mevzek
    2018-03-18T13:54:17+08:002018-03-18T13:54:17+08:00

    Você tem certeza sobre sua primeira observação? O que faz ip route showou route -nmostra então? O resultado muda se você adicionar proto staticno primeiro caso?

    Eu encontrei pelo menos dois recursos que dizem explicitamente que 0é o valor padrão no Linux:

    • http://0pointer.de/lennart/projects/ifmetric/ : A métrica padrão para uma rota no kernel do Linux é 0, significando a prioridade mais alta.
    • http://www.man7.org/linux/man-pages/man8/route.8.html : Se esta opção não for especificada, a métrica para a família de endereços inet6 (IPv6) assume como padrão '1', para inet (IPv4) o padrão é '0'. (então sugere que o padrão pode ser diferente ao usar iproute2, mas a análise dessas fontes não mostra o que é)

    Um hacker de kernel do Linux certamente seria necessário para resolver isso.

    Além disso, qualquer padrão escolhido é claramente específico do sistema operacional. Este artigo ( https://support.microsoft.com/en-us/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes ), por exemplo, mostra que o Windows escolhe a métrica padrão com base na largura de banda do link.

    • 10
  2. noobish
    2018-11-28T15:47:11+08:002018-11-28T15:47:11+08:00

    Como essas rotas estão em sub-redes diferentes, há mais coisas envolvidas aqui do que apenas a métrica. Se o tráfego de origem estiver na sub-rede 192.168.1.1, por exemplo, e houver uma rota não padrão correspondente em sua tabela de roteamento, essa rota corresponderá por meio da correspondência de prefixo mais longa antes que a métrica seja considerada.

    Supondo que uma rota não padrão não corresponda, não ter nenhuma métrica deve ser interpretado pelo kernel como tendo uma métrica de 0 e, portanto, a rota de prioridade mais alta. Embora seja uma visão simplista, porque alguns daemons de roteamento traduzirão posteriormente essa métrica padrão em outro valor como 1024. Espero que seja isso que está acontecendo com você e sua distro sem nome.

    Se ip routenão mostrar nenhuma métrica, você pode confirmar que é realmente 0 usando o route -ncomando mais antigo do pacote net-tools ou cat /proc/net/route. No entanto, essa saída não corresponde necessariamente ao que o daemon de roteamento usará internamente quando encontrar um valor de métrica 0.

    Além disso, como você cria a rota também é importante. ip routeusa a API netlink, enquanto routeusa ioctl. O código de como as métricas padrão são criadas entre as duas abordagens resulta em valores de métricas diferentes. Por exemplo: criar uma rota padrão IPv6 via ip routeresultará em um valor métrico de 1024 no RHEL 7, enquanto criar a mesma rota via routeresultará em uma métrica de 1.

    De RedHat :

    • se nada for passado para o comando de rota como métrica de rota, o valor 1 é usado pelo próprio comando.
    • Se nada for passado para o comando ip como métrica de rota, o atributo não será criado e o kernel o entenderá como 0, que posteriormente é traduzido como 1024 como padrão.
    • 8
  3. Elliptical view
    2020-06-09T00:37:48+08:002020-06-09T00:37:48+08:00

    O gerenciador de rede define as métricas por padrão por tipo de dispositivo, caso não sejam definidas de outra forma. Veja man 5 nm-configurações. Aqui está um trecho, você pode procurar a palavra 'métrica'. Observe também que eles diferem dependendo do ip v4 vs v6. não tenho certeza se isso irá ajudá-lo ou não.

    configuração ipv4 Configurações
    IPv4.

       ┌───────────────────┬───────────────────┬───────────────┬────────────────────────┐
    
       │Key Name           │ Value Type        │ Default Value │ Value Description      │  
       ├───────────────────┼───────────────────┼───────────────┼────────────────────────┤
    
       ...  
       ├───────────────────┼───────────────────┼───────────────┼────────────────────────┤
    
       │route-data         │ array of vardict  │               │ Array of IPv4 routes.  │  
       │                   │                   │               │ Each route dictionary  │  
       │                   │                   │               │ contains at least      │  
       │                   │                   │               │ 'dest' and 'prefix'    │  
       │                   │                   │               │ entries, containing    │  
       │                   │                   │               │ the destination IP     │  
       │                   │                   │               │ address as a string,   │  
       │                   │                   │               │ and the prefix length  │  
       │                   │                   │               │ as a uint32. Most      │  
       │                   │                   │               │ routes will also have  │  
       │                   │                   │               │ a 'gateway' entry,     │  
       │                   │                   │               │ containing the gateway │  
       │                   │                   │               │ IP address as a        │  
       │                   │                   │               │ string. If the route   │  
       │                   │                   │               │ has a 'metric' entry   │  
       │                   │                   │               │ (containing a uint32), │  
       │                   │                   │               │ that will be used as   │  
       │                   │                   │               │ the metric for the     │  
       │                   │                   │               │ route (otherwise NM    │  
       │                   │                   │               │ will pick a default    │  
       │                   │                   │               │ value appropriate to   │  
       │                   │                   │               │ the device).           │  
       │                   │                   │               │ Additional attributes  │  
       │                   │                   │               │ may also exist on some │  
       │                   │                   │               │ routes.                │  
       ├───────────────────┼───────────────────┼───────────────┼────────────────────────┤
    
       │route-metric       │ int64             │ -1            │ The default metric for │  
       │                   │                   │               │ routes that don't      │  
       │                   │                   │               │ explicitly specify a   │  
       │                   │                   │               │ metric. The default    │  
       │                   │                   │               │ value -1 means that    │  
       │                   │                   │               │ the metric is chosen   │  
       │                   │                   │               │ automatically based on │  
       │                   │                   │               │ the device type. The   │  
       │                   │                   │               │ metric applies to      │  
       │                   │                   │               │ dynamic routes, manual │  
       │                   │                   │               │ (static) routes that   │  
       │                   │                   │               │ don't have an explicit │  
       │                   │                   │               │ metric setting,        │  
       │                   │                   │               │ address prefix routes, │  
       │                   │                   │               │ and the default route. │  
       │                   │                   │               │ Note that for IPv6,    │  
       │                   │                   │               │ the kernel accepts     │  
       │                   │                   │               │ zero (0) but coerces   │  
       │                   │                   │               │ it to 1024 (user       │  
       │                   │                   │               │ default). Hence,       │  
       │                   │                   │               │ setting this property  │  
       │                   │                   │               │ to zero effectively    │  
       │                   │                   │               │ mean setting it to     │  
       │                   │                   │               │ 1024. For IPv4, zero   │  
       │                   │                   │               │ is a regular value for │  
       │                   │                   │               │ the metric.            │  
       ├───────────────────┼───────────────────┼───────────────┼────────────────────────┤
    
       │route-table        │ uint32            │ 0             │ Enable policy routing  │  
       │                   │                   │               │ (source routing) and   │  
       │                   │                   │               │ set the routing table  │  
       │                   │                   │               │ used when adding       │  
       │                   │                   │               │ routes. This affects   │  
       │                   │                   │               │ all routes, including  │  
       │                   │                   │               │ device-routes, IPv4LL, │  
       │                   │                   │               │ DHCP, SLAAC,           │  
       │                   │                   │               │ default-routes and     │  
       │                   │                   │               │ static routes. But     │  
       │                   │                   │               │ note that static       │  
       │                   │                   │               │ routes can             │  
       │                   │                   │               │ individually overwrite │  
       │                   │                   │               │ the setting by         │  
       │                   │                   │               │ explicitly specifying  │  
       │                   │                   │               │ a non-zero routing     │  
       │                   │                   │               │ table. If the table    │  
       │                   │                   │               │ setting is left at     │  
       │                   │                   │               │ zero, it is eligible   │  
       │                   │                   │               │ to be overwritten via  │  
       │                   │                   │               │ global configuration.  │  
       │                   │                   │               │ If the property is     │  
       │                   │                   │               │ zero even after        │  
       │                   │                   │               │ applying the global    │  
       │                   │                   │               │ configuration value,   │  
       │                   │                   │               │ policy routing is      │  
       │                   │                   │               │ disabled for the       │  
       │                   │                   │               │ address family of this │  
       │                   │                   │               │ connection. Policy     │  
       │                   │                   │               │ routing disabled means │  
       │                   │                   │               │ that NetworkManager    │  
       │                   │                   │               │ will add all routes to │  
       │                   │                   │               │ the main table (except │  
       │                   │                   │               │ static routes that     │  
       │                   │                   │               │ explicitly configure a │  
       │                   │                   │               │ different table).      │  
       │                   │                   │               │ Additionally,          │  
       │                   │                   │               │ NetworkManager will    │  
       │                   │                   │               │ not delete any         │  
       │                   │                   │               │ extraneous routes from │  
       │                   │                   │               │ tables except the main │  
       │                   │                   │               │ table. This is to      │  
       │                   │                   │               │ preserve backward      │  
       │                   │                   │               │ compatibility for      │  
       │                   │                   │               │ users who manage       │  
       │                   │                   │               │ routing tables outside │  
       │                   │                   │               │ of NetworkManager.     │  
       ├───────────────────┼───────────────────┼───────────────┼────────────────────────┤
    
       │routes             │ array of array of │ []            │ Deprecated in favor of │  
       │                   │ uint32            │               │ the 'route-data'       │  
       │                   │                   │               │ property, but this can │  
       │                   │                   │               │ be used for            │  
       │                   │                   │               │ backward-compatibility │  
       │                   │                   │               │ with older daemons.    │  
       │                   │                   │               │ Note that if you send  │  
       │                   │                   │               │ this property the      │  
       │                   │                   │               │ daemon will ignore     │  
       │                   │                   │               │ 'route-data'.  Array   │  
       │                   │                   │               │ of IPv4 route          │  
       │                   │                   │               │ structures.  Each IPv4 │  
       │                   │                   │               │ route structure is     │  
       │                   │                   │               │ composed of 4 32-bit   │  
       │                   │                   │               │ values; the first      │  
       │                   │                   │               │ being the destination  │  
       │                   │                   │               │ IPv4 network or        │  
       │                   │                   │               │ address (network byte  │  
       │                   │                   │               │ order), the second the │  
       │                   │                   │               │ destination network or │  
       │                   │                   │               │ address prefix (1 -    │  
       │                   │                   │               │ 32), the third being   │  
       │                   │                   │               │ the next-hop (network  │  
       │                   │                   │               │ byte order) if any,    │  
       │                   │                   │               │ and the fourth being   │  
       │                   │                   │               │ the route metric. If   │  
       │                   │                   │               │ the metric is 0, NM    │  
       │                   │                   │               │ will choose an         │  
       │                   │                   │               │ appropriate default    │  
       │                   │                   │               │ metric for the device. │  
       │                   │                   │               │ (There is no way to    │  
       │                   │                   │               │ explicitly specify an  │  
       │                   │                   │               │ actual metric of 0     │  
       │                   │                   │               │ with this property.)   │  
       └───────────────────┴───────────────────┴───────────────┴────────────────────────┘
    
      ipv6 setting  
       IPv6 Settings.  
    
       ┌───────────────────┬───────────────────────────┬───────────────┬────────────────────────────────────────────────────┐
    
       │Key Name           │ Value Type                │ Default Value │ Value Description                                  │  
       ├───────────────────┼───────────────────────────┼───────────────┼────────────────────────────────────────────────────┤
    
       ...  
       ├───────────────────┼───────────────────────────┼───────────────┼────────────────────────────────────────────────────┤
    
       │route-data         │ array of vardict          │               │ Array of IPv6 routes. Each route dictionary        │  
       │                   │                           │               │ contains at least 'dest' and 'prefix' entries,     │  
       │                   │                           │               │ containing the destination IP address as a string, │  
       │                   │                           │               │ and the prefix length as a uint32. Most routes     │  
       │                   │                           │               │ will also have a 'next-hop' entry, containing the  │  
       │                   │                           │               │ next hop IP address as a string. If the route has  │  
       │                   │                           │               │ a 'metric' entry (containing a uint32), that will  │  
       │                   │                           │               │ be used as the metric for the route (otherwise NM  │  
       │                   │                           │               │ will pick a default value appropriate to the       │  
       │                   │                           │               │ device). Additional attributes may also exist on   │  
       │                   │                           │               │ some routes.                                       │  
       ├───────────────────┼───────────────────────────┼───────────────┼────────────────────────────────────────────────────┤
    
       │route-metric       │ int64                     │ -1            │ The default metric for routes that don't           │  
       │                   │                           │               │ explicitly specify a metric. The default value -1  │  
       │                   │                           │               │ means that the metric is chosen automatically      │  
       │                   │                           │               │ based on the device type. The metric applies to    │  
       │                   │                           │               │ dynamic routes, manual (static) routes that don't  │  
       │                   │                           │               │ have an explicit metric setting, address prefix    │  
       │                   │                           │               │ routes, and the default route. Note that for IPv6, │  
       │                   │                           │               │ the kernel accepts zero (0) but coerces it to 1024 │  
       │                   │                           │               │ (user default). Hence, setting this property to    │  
       │                   │                           │               │ zero effectively mean setting it to 1024. For      │  
       │                   │                           │               │ IPv4, zero is a regular value for the metric.      │  
       ├───────────────────┼───────────────────────────┼───────────────┼────────────────────────────────────────────────────┤
    
       │route-table        │ uint32                    │ 0             │ Enable policy routing (source routing) and set the │  
       │                   │                           │               │ routing table used when adding routes. This        │  
       │                   │                           │               │ affects all routes, including device-routes,       │  
       │                   │                           │               │ IPv4LL, DHCP, SLAAC, default-routes and static     │  
       │                   │                           │               │ routes. But note that static routes can            │  
       │                   │                           │               │ individually overwrite the setting by explicitly   │  
       │                   │                           │               │ specifying a non-zero routing table. If the table  │  
       │                   │                           │               │ setting is left at zero, it is eligible to be      │  
       │                   │                           │               │ overwritten via global configuration. If the       │  
       │                   │                           │               │ property is zero even after applying the global    │  
       │                   │                           │               │ configuration value, policy routing is disabled    │  
       │                   │                           │               │ for the address family of this connection. Policy  │  
       │                   │                           │               │ routing disabled means that NetworkManager will    │  
       │                   │                           │               │ add all routes to the main table (except static    │  
       │                   │                           │               │ routes that explicitly configure a different       │  
       │                   │                           │               │ table). Additionally, NetworkManager will not      │  
       │                   │                           │               │ delete any extraneous routes from tables except    │  
       │                   │                           │               │ the main table. This is to preserve backward       │  
       │                   │                           │               │ compatibility for users who manage routing tables  │  
       │                   │                           │               │ outside of NetworkManager.                         │  
       ├───────────────────┼───────────────────────────┼───────────────┼────────────────────────────────────────────────────┤
    
       │routes             │ array of legacy IPv6      │ []            │ Deprecated in favor of the 'route-data' property,  │  
       │                   │ route struct (a(ayuayu))  │               │ but this can be used for backward-compatibility    │  
       │                   │                           │               │ with older daemons. Note that if you send this     │  
       │                   │                           │               │ property the daemon will ignore 'route-data'.      │  
       │                   │                           │               │ Array of IPv6 route structures.  Each IPv6 route   │  
       │                   │                           │               │ structure is composed of an IPv6 address, a prefix │  
       │                   │                           │               │ length (1 - 128), an IPv6 next hop address (which  │  
       │                   │                           │               │ may be zeroed out if there is no next hop), and a  │  
       │                   │                           │               │ metric. If the metric is 0, NM will choose an      │  
       │                   │                           │               │ appropriate default metric for the device.         │  
       ├───────────────────┼───────────────────────────┼───────────────┼────────────────────────────────────────────────────┤
    
       │token              │ string                    │               │ Configure the token for                            │  
       │                   │                           │               │ draft-chown-6man-tokenised-ipv6-identifiers-02     │  
       │                   │                           │               │ IPv6 tokenized interface identifiers. Useful with  │  
       │                   │                           │               │ eui64 addr-gen-mode.                               │  
       └───────────────────┴───────────────────────────┴───────────────┴────────────────────────────────────────────────────┘  
    
    • 0

relate perguntas

  • Inicie/pare o serviço systemd usando o atalho de teclado [fechado]

  • Roteador estranho funciona com centos 6 [fechado]

  • Necessidade de algumas chamadas de sistema

  • astyle não altera a formatação do arquivo de origem

  • Passe o sistema de arquivos raiz por rótulo para o kernel do Linux

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Como exportar uma chave privada GPG e uma chave pública para um arquivo

    • 4 respostas
  • Marko Smith

    ssh Não é possível negociar: "nenhuma cifra correspondente encontrada", está rejeitando o cbc

    • 4 respostas
  • Marko Smith

    Como podemos executar um comando armazenado em uma variável?

    • 5 respostas
  • Marko Smith

    Como configurar o systemd-resolved e o systemd-networkd para usar o servidor DNS local para resolver domínios locais e o servidor DNS remoto para domínios remotos?

    • 3 respostas
  • Marko Smith

    Como descarregar o módulo do kernel 'nvidia-drm'?

    • 13 respostas
  • Marko Smith

    apt-get update error no Kali Linux após a atualização do dist [duplicado]

    • 2 respostas
  • Marko Smith

    Como ver as últimas linhas x do log de serviço systemctl

    • 5 respostas
  • Marko Smith

    Nano - pule para o final do arquivo

    • 8 respostas
  • Marko Smith

    erro grub: você precisa carregar o kernel primeiro

    • 4 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Martin Hope
    rocky Como exportar uma chave privada GPG e uma chave pública para um arquivo 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add retorna com: "Erro ao conectar ao agente: nenhum arquivo ou diretório" 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll status systemctl mostra: "Estado: degradado" 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim Como podemos executar um comando armazenado em uma variável? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S Por que /dev/null é um arquivo? Por que sua função não é implementada como um programa simples? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 Como ver as últimas linhas x do log de serviço systemctl 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - pule para o final do arquivo 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla Por que verdadeiro e falso são tão grandes? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya Por que o Linux usa LF como caractere de nova linha? 2017-12-20 05:48:21 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve