Network configuration: resolv.conf and hosts

316

Solution 1

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.

Solution 2

It needs to at least resolve the hostname to an IP whenever you want to connect to anything. It uses settings from /etc/hosts first because it's local to your system. If you haven't provided it, then it will look it up from your DNS servers, which are defined in resolv.conf.

Share:
316

Related videos on Youtube

c11ada
Author by

c11ada

Updated on September 18, 2022

Comments

  • c11ada
    c11ada over 1 year

    Im creating a web application which is used a reporting application. so far I have managed to create an application which queries a Interbase database and stores the result of the query into a dataset which looks like

    NAME | GP   | ORD_GP | EXP   | TOTAL GP | TARGET
    a      206     48      -239     15         1600
    b      0       27       0        27        1520
    

    this data is then used to create some column charts. which like these

    enter image description here

    what I now need to be able to do is create another chart which will show an hourly line graph of the TOTAL GP, the problem is the web application queries the database every three minutes to get new data and store it in a dataset and then display the new column graph.

    can someone please advice how I might be able to create a line graph for the TOTAL GP taking into account that this data is constantly changing.

    • DarkSquirrel42
      DarkSquirrel42 almost 13 years
      mhh... sorry, i don't really understand your problem. where are you stuck? what have you tried so far? what did not work as you expected?
    • c11ada
      c11ada almost 13 years
      I haven't actually tried anything so far I wanted advice on how I should go about creating a line graph which is updated every hour. the issue is at the moment the data is pulled from a database every 3 mins and the TOTAL GP is calculated on the fly, because of this the TOTAL GP isnt actually stored anywhere. so how would I go about creating a line graph which will show an hourly update of the TOTAL GP for each person ? hope this makes sense now