How do i get the default gateway in LINUX given the destination?

前端 未结 15 2134
清酒与你
清酒与你 2020-12-13 07:02

I\'m trying to get the default gateway, using the destination 0.0.0.0

I used this command: netstat -rn | grep 0.0.0.0

And it return

15条回答
  •  一整个雨季
    2020-12-13 07:40

    There are a lot of answers here already. Some of these are pretty distro specific. For those who found this post looking for a way to find the gateway, but not needing to use it in code/batch utilization (as I did)... try:

    traceroute www.google.com
    

    the first hop is your default gateway.

提交回复
热议问题