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 - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2006, 05:55 PM   #1
bullfrog1870
LQ Newbie
 
Registered: Nov 2006
Posts: 14

Rep: Reputation: 0
ping myself w/o knowing my own address


I've been presented with a challenge to:
ping myself (eth0)
ping a peer
ping a gateway

Each to be done with a single command and no previous knowledge of the network. I say it can't be done.

Did I win the bet?

FC5
 
Old 12-01-2006, 06:52 PM   #2
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Hmm,

you can ping yourself by
Code:
# ping -c1 `hostname`
then you could cheat and ping the entire network
Code:
# ping -c1 -b ` ifconfig | grep Bcast | cut -d : -f 3 | awk '{print $1}' `
or ping the default gateway
Code:
ping -c1 ` netstat -r | awk '/^default/ {print $2}' `

Last edited by dxqcanada; 12-01-2006 at 07:09 PM.
 
Old 12-01-2006, 07:13 PM   #3
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Sooo, you may have lost the bet.

What did I win ??
 
Old 12-02-2006, 11:55 AM   #4
bullfrog1870
LQ Newbie
 
Registered: Nov 2006
Posts: 14

Original Poster
Rep: Reputation: 0
QUOTE=dxqcanada]Sooo, you may have lost the bet.

What did I win ??[/QUOTE]

How do I get my hostname from the commandline and pair it up with the ping command?
 
Old 12-02-2006, 11:58 AM   #5
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Code:
# ping -c1 `hostname`
The hostname command outputs the configured hostname for your workstation ... and the ping command uses that as an argument.
Note that the command is enclosed with the "`" character.
 
Old 12-02-2006, 12:02 PM   #6
bullfrog1870
LQ Newbie
 
Registered: Nov 2006
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bullfrog1870
QUOTE=dxqcanada]Sooo, you may have lost the bet.

What did I win ??
How do I get my hostname from the commandline and pair it up with the ping command?[/QUOTE]


NEVER MIND!

I misunderstood when you put the single quotes around the hostname. I'm guessing that items inside the single quotes gets interpreted as a command.

Thanks so much - I guess I'll have to share lunch now.
 
Old 12-02-2006, 12:07 PM   #7
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Not a singlequote ... it is a backquote.
Makes a big difference as it is used for command substitution.

same as the new syntax of using $( ... )

Code:
# ping -c1 $(hostname)
 
  


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
can't ping domain name, but can ping ip address dtra Linux - Networking 4 04-03-2013 05:02 PM
can't ping local IP address but can ping remote hosts rob_xx17 Linux - Networking 4 12-02-2006 08:39 AM
knowing remote ip address slack66 Slackware 8 09-14-2006 01:58 PM
windows 98 m/c ping to ip address of red hat server but fails to ping hostname ravilohot Linux - Networking 2 09-07-2004 04:57 AM
knowing a mail server address juanb Linux - General 1 02-06-2003 07:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:36 PM.

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