LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-06-2009, 06:26 PM   #1
Bone11409
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
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

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

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

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:57 AM.

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