Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»What is the /etc/hosts file in Linux

    What is the /etc/hosts file in Linux

    RahulBy RahulJune 26, 20222 Mins ReadUpdated:June 27, 2022

    What is /etc/hosts?

    /etc/hosts is a text file on a computer that maps hostnames to IP addresses. It is used for static name resolution, which is not updated automatically like the Domain Name System (DNS) records.

    /etc/hosts are usually the first file checked when resolving a domain name, so it can be used to block websites or redirect users to different websites. The default /etc/hosts look like below:

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

    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

    /etc/hosts is a powerful tool that can be used for various purposes, and it is important to understand how it works to use it effectively.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Angular CLI on Ubuntu 22.04
    Next Article How to Install Ionic Framework on Ubuntu 22.04

    Related Posts

    How to Import GPG Keys on Ubuntu & Debian (without apt-key)

    2 Mins Read

    Running a Cron job every Sunday (Weekly)

    2 Mins Read

    Scheduling a Python Script with Crontab

    2 Mins Read

    Running cron job every 12 hours (twice a day)

    Updated:August 2, 20221 Min Read

    (Resolved) Key is stored in legacy trusted.gpg Keyring

    Updated:August 9, 20222 Mins Read

    How to list all collections in MongoDB database

    1 Min Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Import GPG Keys on Ubuntu & Debian (without apt-key)
    • How To Install Google Chrome On macOS
    • How to Install Minecraft on Ubuntu 22.04 & 20.04
    • Running a Cron job every Sunday (Weekly)
    • Running Multiple Commands At Once in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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