LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-20-2010, 08:14 AM   #1
hussain.s
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Rep: Reputation: 0
How to get the ip address of host in linux with using of host and nslookup command


hi,
HOW TO GET THE IP ADDRESS OF HOST IN LINUX WITH USING OF HOST AND NSLOOKUP COMMAND and after getting the ip address how to assign it in the variable
 
Old 10-20-2010, 08:27 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
host=`host $(hostname)`
IP=$(echo $host | cut -d " " -f 4)
Cheers
 
Old 10-20-2010, 08:46 AM   #3
hussain.s
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks for your solution but one problem is coming when iam writing echo $IP it is not displaying the ip address of host
for this problem what is the solution
 
Old 10-20-2010, 09:00 AM   #4
djsmiley2k
Member
 
Registered: Feb 2005
Location: Coventry, UK
Distribution: Home: Gentoo x86/amd64, Debian ppc. Work: Ubuntu, SuSe, CentOS
Posts: 343
Blog Entries: 1

Rep: Reputation: 72
rofl, best fix ever ;D

Try ifconfig

Oh and stop pasting your homework ;D

Wait, with, or without?
 
Old 10-23-2010, 10:12 PM   #5
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
IP=`host test.com | sed "s/^.* \([0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}\).*/\1/"`

echo $IP



If it's homework.... I wouldn't use my suggestion without understanding it fully... If i were the teacher I would ask you to explain it
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] nslookup, host, dig not resolving entries in /etc/hosts MensaWater Linux - Networking 27 09-22-2022 10:02 AM
Dig, host, nslookup? gsibble Arch 2 01-25-2015 04:36 AM
[SOLVED] ping / nslookup / host not working j66788 Linux - Networking 5 10-07-2009 06:52 PM
Inconsistent results using ping, dig, nslookup, whois, host steelaz Linux - Networking 3 04-05-2009 08:50 AM
(nslookup) vs (dig and host) emailssent Linux - Networking 7 10-06-2004 09:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:06 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