Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Understanding the /etc/hosts File

    Understanding the /etc/hosts File

    By RahulDecember 25, 20223 Mins Read

    The `/etc/hosts` file is a simple text file that maps hostnames to IP addresses. It is used to resolve hostnames to IP addresses on a local system, without the need for external DNS (Domain Name System) lookups.

    Advertisement

    The `/etc/hosts` file contains one line for each hostname-to-IP address mapping, with the fields being separated by white space. The fields in the `/etc/hosts` file are as follows:

    • IP address: The IP address of the host.
    • Hostname: The hostname of the host.

    Here is an example of a `/etc/hosts` file entry:

    1
    127.0.0.1     localhost

    In this example, the IP address is “127.0.0.1” and the hostname is “localhost”. This entry maps the hostname “localhost” to the IP address “127.0.0.1”, which is the loopback address for the local system.

    What is /etc/hosts file
    Default /etc/hosts file

    The `/etc/hosts` file is used by the system’s networking tools and services to resolve hostnames to IP addresses. When a hostname is entered into a web browser or other networking tool, the system first checks the `/etc/hosts` file to see if there is an entry for the hostname. If there is an entry, the system uses the corresponding IP address instead of performing an external DNS lookup.

    Adding New Entry in /etc/hosts

    You can also use `/etc/hosts` to resolve domain names that are not in the global DNS, such as local development servers or intranet servers. This can be done by adding entries for those servers in /etc/hosts with their corresponding IP addresses. For example:

    What is /etc/hosts file
    Local domain binding with /etc/hosts
    • Here demo.example.com is mapped to 192.168.1.210 IP address
    • local.example.com is mapped with 127.0.0.1 (localhost).

    Blocking Website with /etc/hosts

    We can also use this file to prevent access to any domain. That can be helpful for parents to control website access to their loved ones. For example, If someone wants to block all traffic to facebook.com, they can add an entry in /etc/hosts that points facebook.com to 127.0.0.1, which is the loopback address and will not resolve to any actual website.

    What is /etc/hosts file
    Blocking a domain access with /etc/hosts

    The `/etc/hosts` file can be edited by the root user to add, modify, or delete hostname-to-IP address mappings. This can be useful for testing purposes, or to override the DNS resolution of specific hostnames. However, the `/etc/hosts` file should not be used as the primary source of hostname-to-IP address mappings, as it can become difficult to manage as the number of entries grows. Instead, it is generally recommended to use a centralized DNS server for hostname resolution.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    What is Media Access Control (MAC) Address?

    SQL Queries to Change Domain Name for WordPress Site

    How To Block Specific Keywords Using Squid Proxy Server

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Setting and Getting the Default Timezone in Python
    • What is Media Access Control (MAC) Address?
    • What is Cross-Site Scripting (XSS)?
    • What is Content Security Policy (CSP)?
    • A User’s Guide to Understanding Redirection Operators in Bash
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.