LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   host host_name do not retrive IP - how to set a loopback? (https://www.linuxquestions.org/questions/linux-newbie-8/host-host_name-do-not-retrive-ip-how-to-set-a-loopback-4175418443/)

hfelix 07-24-2012 01:08 PM

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?

Kustom42 07-24-2012 02:12 PM

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)

hfelix 07-24-2012 02:15 PM

Hi Kustom42,

Thank you.

The result to your command:
Code:

host $(echo $HOSTNAME)
is:
Code:

Host epagesdevlinux01 not found: 3(NXDOMAIN)
Regards,
Helio

Kustom42 07-24-2012 02:20 PM

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.

hfelix 07-24-2012 02:26 PM

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?

Kustom42 07-24-2012 02:29 PM

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

jefro 07-24-2012 02:33 PM

Just put the name and none of that other stuff behind it.

Chirel 07-24-2012 04:17 PM

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>

Kustom42 07-24-2012 04:38 PM

Quote:

Originally Posted by Chirel (Post 4737054)
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.

sharadchhetri 07-24-2012 05:40 PM

Quote:

Originally Posted by Kustom42 (Post 4737065)
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.

hfelix 07-24-2012 05:50 PM

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?

Chirel 07-24-2012 05:53 PM

@ 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.

sharadchhetri 07-24-2012 06:08 PM

Quote:

Originally Posted by Chirel (Post 4737108)
@ 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.

Chirel 07-25-2012 01:22 AM

Quote:

Originally Posted by sharadchhetri (Post 4737112)
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.

sharadchhetri 07-25-2012 03:25 AM

Quote:

Originally Posted by Chirel (Post 4737353)
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

hfelix 07-25-2012 05:48 AM

Thank you for all your answers.

So, it's not possible do redirect the requests into the same server with some self server configuration.
The solution is to create an internal DNS.

And about the other possible scenario: have the public IP, and then an internal (local ip) with loopback where the application I install will be assigned to this local IP. I have just to set a new loopback interface (i.e. "ifcfg-lo:1") with has the loopback ip and redirect to eth0?

Regards,
Helio


All times are GMT -5. The time now is 05:50 PM.