Como tornar o wlan sempre a rota padrão? (lista de rota do ip)

8

Sempre que eu adiciono meu modem 4G ao meu framboesa, ele fica em cima das rotas padrão ou ip route list , no entanto, quero que tudo passe por wlan e use somente o modem 4G para receber conexões SSH.

Encontrei esta resposta sobre como desativar as rotas padrão.

no entanto, após a reinicialização, o modem 4G volta ao topo.

Como faço com que wlan0 seja sempre a primeira regra a ser padronizada?

ATUALIZAÇÃO:

Aqui está a saída do dmesg quando eu conecto o dongle USB:

[426102.910168] usb 1-1.5.1: new full-speed USB device number 6 using dwc_otg
[426103.046670] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426103.056674] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[426103.056693] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[426103.056704] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426103.056714] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426103.056724] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[426103.121355] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[426103.122875] scsi host0: usb-storage 1-1.5.1:1.0
[426103.987177] usb 1-1.5.1: USB disconnect, device number 6
[426105.470211] usb 1-1.5.1: new full-speed USB device number 7 using dwc_otg
[426105.606666] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426105.615673] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[426105.615692] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[426105.615703] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426105.615713] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426105.766297] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[426105.766768] scsi host0: usb-storage 1-1.5.1:1.2
[426105.855053] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[426105.855593] usbcore: registered new interface driver cdc_ether
[426106.785653] scsi 0:0:0:0: Direct-Access     HUAWEI   TF CARD Storage  2.31 PQ: 0 ANSI: 2
[426106.803758] sd 0:0:0:0: Attached scsi generic sg0 type 0
[426106.820687] sd 0:0:0:0: [sda] Attached SCSI removable disk

Aqui está o ip addr

eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 0c:5b:8f:27:9a:64 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::584f:751f:bb3e:e26b/64 scope link 
       valid_lft forever preferred_lft forever

UPDATE 2

Anexei mais algumas vezes até mostrar a rota eth1 :

[10787.229141] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
[10787.363515] usb 1-1.5: New USB device found, idVendor=05e3, idProduct=0606
[10787.363533] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10787.363544] usb 1-1.5: Product: USB Hub 2.0
[10787.363555] usb 1-1.5: Manufacturer: ALCOR
[10787.365166] hub 1-1.5:1.0: USB hub found
[10787.369831] hub 1-1.5:1.0: 4 ports detected
[10797.419094] usb 1-1.5.1: new full-speed USB device number 8 using dwc_otg
[10797.555636] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10797.565759] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[10797.565777] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10797.565789] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10797.565799] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10797.565808] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[10797.630477] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[10797.631101] scsi host0: usb-storage 1-1.5.1:1.0
[10798.472745] usb 1-1.5.1: USB disconnect, device number 8
[10799.469081] usb 1-1.5.1: new full-speed USB device number 9 using dwc_otg
[10799.630768] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10799.646891] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[10799.646909] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10799.646920] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10799.646930] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10799.814489] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[10799.815008] scsi host0: usb-storage 1-1.5.1:1.2
[10799.897788] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[10799.898127] usbcore: registered new interface driver cdc_ether
[10800.889652] scsi 0:0:0:0: Direct-Access     HUAWEI   TF CARD Storage  2.31 PQ: 0 ANSI: 2
[10800.910585] sd 0:0:0:0: Attached scsi generic sg0 type 0
[10800.923297] sd 0:0:0:0: [sda] Attached SCSI removable disk

Aqui está o route -n

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 wlan0
0.0.0.0         192.168.8.1     0.0.0.0         UG    207    0        0 eth1
0.0.0.0         192.168.1.1     0.0.0.0         UG    303    0        0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U     202    0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     204    0        0 docker0
169.254.0.0     0.0.0.0         255.255.0.0     U     206    0        0 veth4557ad2
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     303    0        0 wlan0
192.168.8.0     0.0.0.0         255.255.255.0   U     207    0        0 eth1

Veja que eu fiz ifmetric wlan0 para poder usar o wlan0 to ssh em meu framboesa

ATUALIZAÇÃO 09/10:

allow-hotplug wlan0
iface wlan0 inet manual
    up ifmetric wlan0 0
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Isso não fará meu wlan0 ter métrica 0. O que estou fazendo de errado?

    
por Guerlando OCs 04.07.2018 / 14:09

4 respostas

4

Para alterar a prioridade de roteamento de uma interface, você altera as métricas.

Por padrão, todos são 0, que é a prioridade mais alta. Então, você pode fazer:

allow-hotplug eth1
iface eth1 inet dhcp
    up ifmetric eth1 30

Para usar ifmetric no Debian, você precisa instalá-lo:

sudo apt-get install ifmetric

ifmetric

Set routing metrics for a network interface

ifmetric is a Linux tool for setting the metrics of all IPv4 routes attached to a given network interface at once. This may be used to change the priority of routing IPv4 traffic over the interface. Lower metrics correlate with higher priorities.

The metric 0 means the highest priority route and is the default one. The larger metric value means lower priority routes. The IP address of the active interface with the lowest metric value becomes the originating one. See ifmetric(8).

    
por 20.07.2018 / 01:20
1

Este é o bom e velho problema de como substituir uma rota padrão.

A maneira mais fácil para o IPv4 não é tentar alterar a métrica / prioridade, mas dividir a rota:

ip route add 0.0.0.0/1 via wlan0-gw
ip route add 128.0.0.0/1 via wlan0-gw

A razão pela qual isso funciona é que as pesquisas na tabela de roteamento são realizadas usando uma pesquisa com prefixo de correspondência mais longa. As métricas de rota entram em cena somente quando há duas rotas equivalentes. Nesse caso, essas duas rotas têm um prefixo de 1 bit que é maior que o prefixo de 0 bits da rota padrão (0.0.0.0/0) e será consultado primeiro. Como essas duas rotas cobrem o total de 0.0.0.0/0, elas sempre terão preferência sobre a rota padrão.

Uma abordagem alternativa é usar uma tabela de roteamento separada com a rota padrão que você preferir e adicionar uma regra para enviar todo o tráfego para lá. Eu nunca vi nenhuma automação que mexesse com regras de ip, então não importa quais outras rotas eles adicionam. O problema aqui é que sua automação não poderá inserir rotas adicionais.

Então, tl; dr:

iface wlan0 inet manual
    up ip route add 0.0.0.0/1 via wlan0-gw
    up ip route add 128.0.0.0/1 via wlan0-gw
    ....

Ou (mas você também precisará adicionar todas as outras rotas à "tabela 5"):

iface wlan0 inet manual
    up ip rule add to 0.0.0.0/0 table 5
    up ip route add default via wlan0-gw table 5
    ....
    
por 14.10.2018 / 01:12
0

Uma forma de persistir o ip route add/del no debian é escrevê-lo em /etc/network/interfaces , como abaixo:

allow-hotplug eth1
iface eth1 inet dhcp
    post-up ip route del default
    post-up ip route add default via <gateway IP> dev wlan0
    
por 18.07.2018 / 11:49
0

Eu acho que o assunto no gateway padrão. Aqui está o tutorial.

Explico brevemente os passos. Primeiro, você precisa excluir o gateway padrão e adicionar aquele que deseja adicionar. Em seguida, edite "/ etc / network / interfaces" para alteração permanente. Finalmente, você reinicia o serviço.

link

    
por 20.07.2018 / 03:39