The /etc/hosts file defines the Internet Protocol (IP) name and address of the local host and specifies the names and addresses of remote hosts.
The /etc/hosts file contains the Internet Protocol (IP) host names and addresses for the local host and other hosts in the Internet network. This file is used to resolve a name into an address (that is, to translate a host name into its Internet address). When your system is using a name server, the file is accessed only if the name server cannot resolve the host name.
Entry format:
Address HostName
Address is an IP address specified in either dotted decimal or octal format, and HostName is the name of a host specified in either relative or absolute domain name format.
Entry example:
142.251.40.174 google.com
How to edit the /etc/hosts file
You have to change the permissions.
Example:
sudo chmod 777 /etc/hosts
The default file permissions for /etc/hosts
If you changed the permissions you can switch it back.
sudo chmod 644 /etc/hosts