Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  47] [ 0]  / answers: 1 / hits: 91104  / 1 Year ago, sat, february 18, 2023, 4:53:34

I'm very new to Ubuntu and I want to know: what is the exact use of /etc/hosts?



Lets say I'm adding this into it :



127.0.x.x mydomain


What does that mean?


More From » filesystem

 Answers
7

Purpose


The hosts file is one of several system facilities that assists in addressing network nodes in a computer network. It is a common part of an operating system's Internet Protocol (IP) implementation, and serves the function of translating human-friendly hostnames into numeric protocol addresses, called IP addresses, that identify and locate a host in an IP network.
In some operating systems, the hosts file's content is used preferentially to other methods, such as the Domain Name System (DNS), but many systems implement name service switches (e.g., nsswitch.conf for Linux and Unix) to provide customization. Unlike the DNS, the hosts file is under the direct control of the local computer's administrator


File content


The hosts file contains lines of text consisting of an IP address in the first text field followed by one or more host names. Each field is separated by white space (blanks or tabulation characters). Comment lines may be included; they are indicated by a hash character (#) in the first position of such lines. Entirely blank lines in the file are ignored. For example, a typical hosts file may contain the following:


# This is an example of the hosts file

127.0.0.1 localhost loopback
::1 localhost

This example only contains entries for the loopback addresses of the system and their host names, a typical default content of the hosts file. The example illustrates that an IP address may have multiple host names, and that a host name may be mapped to several IP addresses.



Wikipedia




This is invalid (?):


127.0.x.x mydomain

Wildcards are * so it should be 127.0.*.* but I hardly see anything else than 127.0.0.1 ;)




What this means is that you can use mydomain as a name for that IP address. It is easier to use www.google.com than to remember the IP address (74.125.132.106) that Google uses for their searchengine. The same works locally (localhost) on your machine. If you run your own Apache instance you can set a local IP address to a name and use that name in a browser.




The ::1 in the example is the IP v6 version for IP addresses.


[#35810] Sunday, February 19, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
biryanrownies

Total Points: 396
Total Questions: 90
Total Answers: 106

Location: Saint Lucia
Member since Sun, Sep 5, 2021
3 Years ago
biryanrownies questions
Wed, Sep 7, 22, 18:13, 2 Years ago
Fri, Dec 3, 21, 02:50, 2 Years ago
Sat, Feb 12, 22, 16:02, 2 Years ago
Sat, Apr 15, 23, 09:22, 1 Year ago
;