LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-24-2012, 02:08 PM   #1
hfelix
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Rep: Reputation: Disabled
host host_name do not retrive IP - how to set a loopback?


Hello,

I've an CentOS 6.3 fresh installation where I want to install an application which has this requirement:
"TCP/IP and DNS must be installed; the command host host_name (where host_name is the name of your host) must return the IP address of the host"

I can set a static IP. I can access to internet. I dont know how to make the "host host_name" works as supposed. I tried some configurations and it never retrived the IP.

My static IP is 192.168.68.128 an the IP which should work to this application should be 172.16.8.57. On windows I used to resolve this situation with a loopback. On CentOS I'm a newbie and I dont know how to correctly define my loopback.

Can you help me?
 
Old 07-24-2012, 03:12 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
I'm confused... all you need to be able to do is resolve your hostname to an IP. This is configured for you by default.

Run the following:

Code:
host $(echo $HOSTNAME)
 
Old 07-24-2012, 03:15 PM   #3
hfelix
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi Kustom42,

Thank you.

The result to your command:
Code:
host $(echo $HOSTNAME)
is:
Code:
Host epagesdevlinux01 not found: 3(NXDOMAIN)
Regards,
Helio
 
Old 07-24-2012, 03:20 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Ok, so just add it to your etc hosts file.. it should have done that for you during the initial install but if you changed your hostname it wouldnt have updated.

Code:
sudo vi /etc/hosts
Find the line that has your external static IP on it. If there is not a line with it there add it. Syntax is as follows:

Code:
1.1.1.1    epagesdevlinux01 epagesdevlinux01.domain.com anyother.host.name
The IP comes first followed by your hostnames, they can be space or tab delimitted it does not matter. You should be good to re-run the host command and resolve it to your IP now.
 
Old 07-24-2012, 03:26 PM   #5
hfelix
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Adding it to hosts files I've this:
Code:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.91 epagesdevlinux01 epagesdevlinux01.domain.com anyother.host.name
"192.168.1.91" is my static IP on my local network.

Runing the host command again I get the same result
Code:
Host epagesdevlinux01 not found: 3(NXDOMAIN)
Is my hosts file right?
 
Old 07-24-2012, 03:29 PM   #6
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Yes your hosts file syntax is right but the epagesdevlinux01.domain.com anyother.host.name were provided as examples, you don't need these unless you want to add more domains.

You may have to restart networking or the server to get it to find the hosts file update but it is odd as usually the change is effective immediately
 
Old 07-24-2012, 03:33 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,273

Rep: Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656Reputation: 3656
Just put the name and none of that other stuff behind it.
 
Old 07-24-2012, 05:17 PM   #8
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
Hi,

host will do a dns lookup, as your host is local and not declared on the dns server, you will not be able to resolve it.

You can put whatever you want on /etc/hosts this will not change unless you put the right name.

Now if the application you want to install have to be used from internet, then you have to open the port and give the real internet name to your host.

The real name of your fresh centos should be equal to the result of :

host <external real internet ip>
 
Old 07-24-2012, 05:38 PM   #9
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Quote:
Originally Posted by Chirel View Post
Hi,

host will do a dns lookup, as your host is local and not declared on the dns server, you will not be able to resolve it.

You can put whatever you want on /etc/hosts this will not change unless you put the right name.

Now if the application you want to install have to be used from internet, then you have to open the port and give the real internet name to your host.

The real name of your fresh centos should be equal to the result of :

host <external real internet ip>

You are talking about PTR and DNS with your last few lines, this is not a factor in this equation as no external DNS is being served or being called upon, your /etc/hosts file is checked prior to DNS lookups. Your statement that it will not be able to resolve it is completely false.
 
Old 07-24-2012, 06:40 PM   #10
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by Kustom42 View Post
You are talking about PTR and DNS with your last few lines, this is not a factor in this equation as no external DNS is being served or being called upon, your /etc/hosts file is checked prior to DNS lookups. Your statement that it will not be able to resolve it is completely false.
The host command search in nameserve define in /etc/resolv.conf.
Is the server hostname is in DNS Server with host record and PTR record.
 
Old 07-24-2012, 06:50 PM   #11
hfelix
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
So, i adjusted the hosts file:
Code:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.91 epagesdevlinux01
I restarted the network service
Code:
sudo service network restart
And trying the host command... I get the same result.
I reboot the server and I get the same result.
Code:
Host epagesdevlinux01 not found: 3(NXDOMAIN)
Later I will use the MyServer.domain.com, but now, just for test purposes I'm using a local name (without domain).
I can use a hostname with domain and just define it on /etc/hosts, but the result will be the same as using a local name, right?
 
Old 07-24-2012, 06:53 PM   #12
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
@ Kustom42
Sorry, but i really think that you are wrong, the host command will alway try to resolve via a dns lookup from /etc/resolv.conf - it will not check /etc/hosts.

the only way other way he can solve this problem is to install a personal bind server and setup /etc/resolv.conf with it.

You can put what you want into the /etc/hosts this will never change the host command behaviour.

host will not use /etc/nsswitch.conf to resolve host name, it will only use /etc/resolv.conf and nothing else.


For hfelix

the application you want to install check that you are using a host that is known from current dns server.
As you are using internet the real ip is the external ip with is the result of the command
Code:
curl icanhazip.com
And the host name that is associated is the result of
Code:
host $(curl icanhazip.com)
So if you want to install the application you have to simulate that you are this host and change your hostname to this.

Last edited by Chirel; 07-24-2012 at 07:04 PM.
 
Old 07-24-2012, 07:08 PM   #13
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by Chirel View Post
@ Kustom42
Sorry, but i really think that you are wrong, the host command will alway try to resolve via a dns lookup from /etc/resolv.conf - it will not check /etc/hosts.

the only way other way he can solve this problem is to install a personal bind server and setup /etc/resolv.conf with it.

You can put what you want into the /etc/hosts this will never change the host command behaviour.

host will not use /etc/nsswitch.conf to resolve host name, it will only use /etc/resolv.conf and nothing else.


For hfelix

the application you want to install check that you are using a host that is known from current dns server.
As you are using internet the real ip is the external ip with is the result of the command
Code:
curl icanhazip.com
And the host name that is associated is the result of
Code:
host $(curl icanhazip.com)
So if you want to install the application you have to simulate that you are this host and change your hostname to this.
It is DNS lookup utility. any how it will search the DNS where its domain name is defined. hence resolv.conf come into that picture.


below is man page of host.

HOST(1) BIND9 HOST(1)

NAME
host - DNS lookup utility

SYNOPSIS
host [-aCdlnrsTwv] [-c class] [-N ndots] [-R number] [-t type]
[-W wait] [-m flag] [-4] [-6] {name} [server]

DESCRIPTION
host is a simple utility for performing DNS lookups. It is normally
used to convert names to IP addresses and vice versa. When no arguments
or options are given, host prints a short summary of its command line
arguments and options.

name is the domain name that is to be looked up. It can also be a
dotted-decimal IPv4 address or a colon-delimited IPv6 address, in which
case host will by default perform a reverse lookup for that address.
server is an optional argument which is either the name or IP address
of the name server that host should query instead of the server or
servers listed in /etc/resolv.conf.
 
Old 07-25-2012, 02:22 AM   #14
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
Quote:
Originally Posted by sharadchhetri View Post
It is DNS lookup utility. any how it will search the DNS where its domain name is defined. hence resolv.conf come into that picture.


below is man page of host.

HOST(1) BIND9 HOST(1)

NAME
host - DNS lookup utility

SYNOPSIS
host [-aCdlnrsTwv] [-c class] [-N ndots] [-R number] [-t type]
[-W wait] [-m flag] [-4] [-6] {name} [server]

DESCRIPTION
host is a simple utility for performing DNS lookups. It is normally
used to convert names to IP addresses and vice versa. When no arguments
or options are given, host prints a short summary of its command line
arguments and options.

name is the domain name that is to be looked up. It can also be a
dotted-decimal IPv4 address or a colon-delimited IPv6 address, in which
case host will by default perform a reverse lookup for that address.
server is an optional argument which is either the name or IP address
of the name server that host should query instead of the server or
servers listed in /etc/resolv.conf.
That's exactly what i'm saying. So host command will ignore any change to /etc/hosts, that's what i'm trying to say to Kustom42.
 
Old 07-25-2012, 04:25 AM   #15
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by Chirel View Post
That's exactly what i'm saying. So host command will ignore any change to /etc/hosts, that's what i'm trying to say to Kustom42.
best practice is create a internal DNS server.
Ask your system admin to create a internal DNS.With A and PTR record for the application Server
put the internal DNS server ip in /etc/resolv.conf
 
  


Reply

Tags
centos, host, loopback, static


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
[SOLVED] problem with ethernet loopback test using loopback plug/stub: receiving socket not se mcha Linux - Kernel 3 08-26-2010 12:28 PM
If PPP the only access to 'net, need to set loopback on network card? Won't browse vaughancoveny Linux - Newbie 2 01-23-2010 06:32 PM
What is local host 127.0.0.1 loopback?? cousinlucky Linux - Newbie 12 12-25-2005 05:56 PM
How to set more than on loopback grub Linux - Software 2 02-12-2004 12:21 AM

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

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