Ferramentas para depurar tabelas de roteamento em uma máquina Linux?

8

Existe uma ferramenta que debuga tabelas de roteamento em uma máquina Linux?

Eu quero dizer um que eu possa usar inserindo um endereço ip nele, ele levará a tabela de roteamento existente em conta e gerará os resultados da tabela, para que eu possa ter uma idéia de onde os pacotes irão?

    
por leeand00 23.03.2015 / 16:37

2 respostas

24

Use ip route get . De Configurando o roteamento de rede :

The ip route get command is a useful feature that allows you to query the route on which the system will send packets to reach a specified IP address, for example:

# ip route get 23.6.118.140
23.6.118.140 via 10.0.2.2 dev eth0 src 10.0.2.15
cache mtu 1500 advmss 1460 hoplimit 64

In this example, packets to 23.6.118.140 are sent out of the eth0 interface via the gateway 10.0.2.2.

    
por 23.03.2015 / 20:16
2

Salve o seguinte script em algum lugar útil. Chame-o com o endereço IP que você deseja testar e ele informará a rota correspondente.

#!/bin/bash
#
# Find the appropriate routing entry for a given IP address
########################################################################

########################################################################
# Calculate the base network address for a given addres and netmask
#
baseNet() {
    local ADDRESS="$1" NETMASK="$2"
    ipcalc -nb "$ADDRESS" "$NETMASK" | awk '$1=="Network:"{print $2}'
}

########################################################################
# Go
#
for IPADDRESS in "$@"
do
    netstat -rn |
        tac |
        while read DESTINATION GATEWAY GENMASK FLAGS MSS WINDOW IRTT IFACE
        do
            NSBASENET=$(baseNet "$DESTINATION" "$GENMASK")
            IPBASENET=$(baseNet "$IPADDRESS" "$GENMASK")
            if test "X$NSBASENET" = "X$IPBASENET"
            then
                if test '0.0.0.0' = "$GATEWAY"
                then
                    echo "Matches $DESTINATION with netmask $GENMASK directly on $IFACE"
                else
                    echo "Matches $DESTINATION with netmask $GENMASK via $GATEWAY on $IFACE"
                fi
                break
            fi
        done
done

# All done
#
exit 0

Exemplo de uso

./what-route.sh 10.0.5.6
Matches 0.0.0.0 with netmask 0.0.0.0 via 10.0.2.2 on eth0
./what-route.sh 10.0.2.6
Matches 10.0.2.0 with netmask 255.255.255.0 directly on eth0
    
por 23.03.2015 / 19:18