0

I have a gRPC client (works on top of HTTP2). I want to route the connection via different interfaces at different times. I generally create an instance of the client and set a route to force gRPC to use a particular interface (by resolving hostname and executing ip route add commands) and then I connect to the client hoping it will be routed via particular interface (eth0 or wlan0).

However, it is not working.

I tired following commands

# To Route via WiFi
ip route del A.B.C.D
ip route add A.B.C.D dev wlan0

# To Route via Ethernet
ip route del A.B.C.D
ip route add A.B.C.D dev eth0

However, this works for me,

# To Route via WiFi
ip route del A.B.C.D
ip route add A.B.C.D dev wlan0 via GATEWAY_IP_ADDR

I don't want to use Gateway's IP address in my scripts as I will to update the script if my device connects to different WiFi or Ethernet Network.

Please help. I am looking for something which could automatically route the connection via the default gateway of the interface.

5
  • Even your default route requires the use of "via gateway". What makes you think it's optional? It's needed for link layer address resolution (layer 3 IPv4 to layer 2 Ethernet MAC, using ARP). You can have your script use the correct value.
    – A.B
    Commented Mar 15, 2020 at 17:03
  • How can I get a gateway for a interface? What if a interface is ppp?
    – abhiarora
    Commented Mar 15, 2020 at 17:38
  • 1
    Well ppp is layer 3 and doesn't really need a gateway, since there's no link layer address resolution needed. about the 1st question in the comment: when you type "ip route", don't you get the gateway?
    – A.B
    Commented Mar 15, 2020 at 17:39
  • I need to parse it then using awk. I was thinking about something ip route add A.B.C.D via default dev eth0. Looks like it is not possible. I thought may be ip will automatically figure out gateway depending upon the interface passed.
    – abhiarora
    Commented Mar 15, 2020 at 18:00
  • ip has a json output that can be parsed by jq. Anyway I realize that only you can know what interface to use at a given time.
    – A.B
    Commented Mar 15, 2020 at 18:22

0

You must log in to answer this question.

Browse other questions tagged .