What command can you use to find the Gateway IP Address (ie. home router address) for eth0 in Linux?
I need to get the IP address from a command line app to use in a shell script.
|
feedback
|
|
To print out only the default gw IP:
To print out route information on all interfaces:
or
| |||||||||||||
feedback
|
|
You can get the system's default gateway from the output of | |||
|
feedback
|
is my entry :) | |||||
feedback
|
The 0.0.0.0 is your default gateway, pointing to 192.168.1.254 at my place. | |||
|
feedback
|
|
The output from route -n or netstat -rn, and search for the destination 0.0.0.0. | |||
|
feedback
|
|
I prefer the iproute package:
| |||||||||
feedback
|
|
Are you looking for the external IP address of the router? In the past I've used a screen scraping script to get that sort of thing from the router setup pages. Most home routers have a browser based setup that is easy to access from the inside. It's hard to give a general solution but you can use curl or wget to fetch the page and then use grep & awk to get the IP address. | |||||
feedback
|
|
this will cleanly print the gateway IP. (what would linux scripting be without awk?) | |||
feedback
|
|
anyone shorter than this? =)
| |||||||||||
feedback
|
| ||||
|
feedback
|