Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-06-2009, 06:26 PM   #1
LQ Newbie
Registered: Jan 2009
Posts: 19

Rep: Reputation: 0
Looking a for bash command to display gateway address of eth0

I am looking for a bash command that will output only the gateway address for eth0. I have been looking around the forums and on the net but have not had any luck. The only thing I have found that comes close is using
netstat -r | grep default but the problem it display alot of extra stuff
Old 11-06-2009, 06:55 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,391
Blog Entries: 52

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
netstat -r | grep '^default.*eth0$' | awk '{print $2}'
might be what you want
Old 11-06-2009, 07:14 PM   #3
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
no need grep with awk
$ netstat -r |awk '$1=="default"{print $2}'
Old 11-07-2009, 01:01 AM   #4
LQ Newbie
Registered: Jan 2009
Posts: 19

Original Poster
Rep: Reputation: 0
Hey thank's that was just what I needed.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i find my gateway address on eth0? seth Linux - Networking 10 03-21-2010 03:42 AM
eth0 fixed IP. eth1 DHCP gateway. Need access to eth0 fopetesl Linux - Networking 69 02-01-2010 03:45 AM
How programatically in C do I get/set the default route or gateway address of eth0 jroberts5477 Linux - Networking 2 09-15-2006 01:11 PM
How do I set the ip address for eth0, eth1 and the default gateway? abefroman SUSE / openSUSE 5 05-19-2005 04:15 AM
finding gateway address on eth0 MHouse Linux - Newbie 9 03-05-2004 06:35 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration