문제

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).

도움이 되었습니까?

해결책

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

route -n | cut -d" " -f10

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top