Pregunta

I have found a way to get default gateway in Linux with the following command:

grep -i "gateway" /etc/network/interfaces | awk print $2

Output:

192.168.14.1

This will not work if the system is in DHCP mode.

I need a way to get only 'gateway' which works on all platforms (Linux / Windows / Mac).

¿Fue útil?

Solución

This will work for Linx(your host may be dhcp or static)

route -n | cut -d" " -f10

Output : x.x.x.x(gateway address)

Otros consejos

How to Find Default Gateway IP Address on Linux? Here's the solution:

  1. Click the Settings icon on the left side bar.

  2. On the settings side bar, scroll down, and click Network option. Select connection settings icon.

  3. Find your gateway IP address listed next to Default Route. You're done.

Reference:

https://www.lifewire.com/how-to-find-your-default-gateway-ip-address-2626072 https://www.purevpn.com/what-is-my-ip/default-gateway https://www.noip.com/support/knowledgebase/finding-your-default-gateway/

For Windows using Control Panel:

Step 1: Type Control Panel in the Windows search box (usually located at the bottom left of the screen), and hit Enter when it appears.

Step 2: Click the Network and Internet.

Step 3: Click the Network and Sharing Center.

Step 4: Under the Network and Sharing Center window, click Ethernet.

Step 5: Click Details.

Step 6: Find your gateway IP address listed next to IPv4 Default Gateway.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top