Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  15] [ 0]  / answers: 1 / hits: 21846  / 1 Year ago, thu, march 23, 2023, 6:13:12

I read This manual and I'm a little confused.
This is what I don't undetstand:



When your system tries to resolve a hostname to an IP address or determine the
ostname for an IP address, it refers to the /etc/hosts file before using the
name servers


So:



1)When DOES the system tries to resolve a hostname? To my understanding its when a datagrams's header specifies a hostname, am I right?



2)Why does it refer to hosts before resolv.conf?



3)After the hostname is resolved, the system turns to the routing table?


More From » hosts

 Answers
7

1) Normally your system would use the DNS server on your 'resolv.conf'. If you visit www.yahoo.com your system will contact the DNS, the DNS returns the IP address of that address and your systems then knows what IP address corresponds the address www.yahoo.com.



2) It uses hosts before trying to resolve an address because hosts file is used to override any address you are trying to resolve. ie: you already have probably an entry there, 127.0.0.1 localhost tells the system that if you are trying to contact the host with the name "localhost" it will do so by using the address 127.0.0.1, in this case its your lopback interface on your eth0.



3) After the system knows an address of a host either looking directly on your hosts or by contacting the DNS servers in 'resolv.conf' it will look at the routing table to see which of the rules explains what to do with the traffic with destination to the IP address obtained.



Ie: Imagine you have 2 computers on your network with hostnames of "Ubuntu-One" and "Ubuntu-Two", each computer will probably have this assigned at the host file:



127.0.0.1 localhost Ubuntu-One for computer Ubuntu-One
127.0.0.1 localhost Ubuntu-Two for computer Ubuntu-Two



This is done automatic and its the reason you can resolve 'localhost' and 'Ubuntu-One" and "Ubuntu-Two" on each respective terminals.



Try to ping Ubuntu-Two from Ubuntu-One and Ubuntu-One will contact the DNS servers at your resolv.conf file, the servers will say "I dont know any IP related to that address" and you PC will reply "Unknown hostname". Add the line <IPADDRESSFROMUBUNTU-TWO Ubuntu-Two to the hosts file of Ubuntu-One and one you try to ping again the system will see that on the hosts file the IP address from Ubuntu-Two is x.x.x.x, will then check your routing table to see which rule applies to that IP or IP range and will contact the host using the specified gateway (or none). Thats is why hosts is ever before resolv.conf.


[#43191] Saturday, March 25, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itagde

Total Points: 241
Total Questions: 113
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
2 Years ago
itagde questions
Thu, Jun 10, 21, 21:24, 3 Years ago
Sat, Aug 13, 22, 22:41, 2 Years ago
Thu, May 20, 21, 11:52, 3 Years ago
Tue, Aug 23, 22, 06:19, 2 Years ago
;