How do I redirect a domain name to the desired IP address locally for my PC?

Local domain redirection to a given IP does not require much knowledge.

What should I do to make the domain name to IP redirection work?

You need to open the hosts file with any text editor, add a line in the format below and save:
IP Your_Domain.net

Where to find the hosts file for different operating systems

Windows OS:
//WINDOWS/system32/drivers/etc/hosts

Linux OS:
/etc/hosts

Mac OS:
System folder: Preferences or just in the system folder

Mac OS X and iPhone OS:
/private/etc/hosts or /etc/hosts

Symbian OS:
C:\private\10000882\hosts (or C:\system\data\hosts)

Android OS:
/system/etc/hosts

Please note! It is advisable to leave at least one empty line at the end of the file.
This is enough to redirect the domain to the specified IP address. Now, you just type the domain in the browser and access your resource without waiting for the DNS to update. Your PC does not send a request to DNS, but takes the IP address for the specified domain from the hosts file.

When do I need to redirect a domain through the hosts file?

Most often, domain redirection to an email address through hosts is used in website development. For example, when you need to install and configure Wordpress on a hosting account or another website or CMS (for example, Joomla, Drupal, etc.), but you have not yet bought a domain name. Or, for example, your site is already working and you are transferring it to a new vps or regular website hosting, but before redirecting the domain name to a new server, you need to check that everything works. Or, you have registered new ns records for the domain and do not want to wait for DNS updates for 12-24 hours, but want to see how your site works right away. In such cases, this is exactly what redirects through the hosts file are used for.

That is, when using a domain name, your PC always checks the hosts file first. If the domain is not registered there, the system makes a request to the DNS server. When you have registered a domain in the hosts file, the system immediately receives from it the IP address of the server where you need to connect using the specified domain. This is how redirection through the hosts file works, and the browser directly, without a request to the DNS, accesses the server and loads the site from the specified IP.

The browser does not take into account whether the domain is registered with the registrar or not.