Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 10-20-2010, 08:14 AM   #1
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

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
Senior Member
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,631
Blog Entries: 11

Rep: Reputation: 217Reputation: 217Reputation: 217
host=`host $(hostname)`
IP=$(echo $host | cut -d " " -f 4)
Old 10-20-2010, 08:46 AM   #3
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
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
Senior Member
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
IP=`host | 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


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 16 09-16-2015 08:36 PM
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

All times are GMT -5. The time now is 01:09 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration