I have three interfaces connected to my machine. How can I get the gateway IP of one non default interface? I'm using Debian 9


"Gateways" are part of the routing. (Actually, the routing algorithm just wants to know where to send a particular packet (next hop), it doesn't care if the next hop is something you'd call a "gateway", or just a normal host).

So use ip route to see your routing table. If you don't know the address ranges, use ip addr to see them. All routes that have next hops in the address range of some interface will be "gateway" candidates.

You can also use ip route get to see to which next hop a packet with this final destination will be sent. This might be more convenient.


Just in case, a short reminder of what happens behind the scenes:

When a host connects to a LAN segment, and can send out a DHCP broadcast to acquire an IP address. ("Hello, I'm new here, what IP address should I use?"). The DHCP server in the LAN segment (e.g. your home router) then answers "Welcome, use this IP address, and by the way, if you want to reach the internet from this segment, please use this gateway address as next hop."

The typical reaction to this gateway address announcement is that the host sets the default route to this address.

If you are connected to three LAN segments, each with their own DHCP server, and each with a connection to the internet via a gatway (which shouldn't happen in a professionally designed network), then the host will receive three DHCP answers with different gateways, will set the default route each time, and the last wins. Note that there is no "default interface".

So if your situation is not that you are part of a corporate network with different next hops in each segment on each interface, but you are accidentally connected to three standard home networks, where no one has bothered to set up the right infrastructure for such a case, and you want to know the announced gateway in the DHCP answers, you can (1) look in the logs for DHCP answers, (2) disconnect all three interfaces, re-connect each in turn, get a new DHCP answer and write down the default route, (3) use a tool to debug DHCP requests, so you can send out an additional one.

Note that this information will be of no use to you: You can only use one default route, and you can't use different gateways into the internet to somehow get faster speeds etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.