Reputation: 12369
I would like to use a short shell script to get my default gateway address. so that it would do
$> whatismygateway.sh
192.168.100.10
I have tried ifconfig eth0
, but it just does not contain any information about the gateway.
Upvotes: 1
Views: 397
Reputation: 29942
If eth0
is your interface, you could try something like this
cat /etc/sysconfig/network-scripts/ifcfg-eth0|grep GATEWAY|sed 's/^[A-Z].*=//'
output:
95.174.29.225
you can also use route
command
Upvotes: 1
Reputation: 1733
route | grep default
should give you what you're looking for, although if you have multiple interfaces you may need to filter the results further.
Upvotes: 1