How to Assign a Hostname to an IP Address in Windows 11/10
Assigning a hostname to an IP address in Windows 11 or Windows 10 involves editing the Hosts file, a special system file that stores hostname-to-IP mappings locally on your computer.
Once you add an entry to the Hosts file, Windows checks this file before querying a DNS server. If a matching hostname exists in the file, Windows immediately redirects the hostname to the assigned IP address.
For example, if you add the following entry: 192.168.1.100 MyServer
Typing MyServer in supported applications or network tools will direct Windows to the IP address 192.168.1.100.
This method is commonly used for:
- Testing websites before DNS updates
- Accessing local servers
- Managing network devices
- Software development environments
- Troubleshooting network connections
- Creating easy-to-remember network names
The process is straightforward and requires only a few minutes.
Let’s learn exactly how to assign a hostname to an IP address in Windows 11 and Windows 10.
Hostnames and IP Addresses
An IP address acts like a house address on a network. It tells devices where information should be sent.
A hostname acts like a contact name. Instead of remembering a long numerical address, users can use a meaningful name.
For example:
IP Address: 192.168.1.25
Hostname: Printer-Room
Without hostname mapping, users must enter the numerical IP address every time they access the device. By assigning a hostname, accessing the device becomes simpler and more convenient.
Windows stores custom mappings inside the Hosts file, making it one of the easiest ways to create local hostname records.
Requirements Before You Begin
Before assigning a hostname, ensure the following requirements are met.
- You should know the correct IP address of the target device.
- You must have administrator privileges on your Windows computer.
- The target device should be reachable on your network.
- You should have permission to edit system files.
If these requirements are met, you can proceed with the configuration process.
How to Assign a Hostname to an IP Address in Windows 11/10

To assign a hostname to an IP address in Windows 11 or Windows 10:
- Open Notepad as Administrator.
- Navigate to C:\Windows\System32\drivers\etc.
- Open the Hosts file.
- Add a new line containing the IP address followed by the hostname.
- Save the file.
- Flush the DNS cache using Command Prompt.
- Test the hostname using the Ping command.
After saving the Hosts file, Windows will resolve the hostname to the specified IP address whenever it is accessed from that computer.
Step 1: Find the IP Address You Want to Associate
The first step is identifying the IP address that will be linked to a hostname.
If the device is already connected to your network, you can find its IP address in several ways.
For another Windows computer, open Command Prompt and type:
ipconfig
Press Enter and look for the IPv4 Address.
For routers, printers, NAS devices, or servers, the IP address is usually displayed in the device’s network settings or management dashboard.
Write down the IP address carefully because even a small mistake will prevent the hostname from working correctly.
For example:
192.168.1.100
This is the address we’ll use throughout this guide.
Step 2: Open Notepad with Administrator Privileges
The Hosts file is a protected system file.
Because of this, Windows does not allow regular users to modify it directly.
Click the Start button and type Notepad into the search box.
When Notepad appears in the search results, right-click it and select Run as administrator.
If prompted by User Account Control (UAC), click Yes.
Opening Notepad with administrative privileges is essential. Without administrator rights, you may be able to edit the file, but you will not be able to save your changes.
Once Notepad launches, keep it open and move to the next step.
Step 3: Open the Hosts File
Now you need to access the Hosts file.
- In Notepad, click File and then select Open.
- Navigate to the following location: C:\Windows\System32\drivers\etc
- At first, you may not see any files because Notepad is filtering for text documents.
- Locate the file type drop-down menu near the bottom-right corner of the Open window.
- Change Text Documents (*.txt) to All Files (.).
- The Hosts file should now appear.
- Select hosts and click Open.
You will see a text file containing comments and sample entries beginning with the # symbol.
These lines provide information about how the file works.
Do not remove existing entries unless you are certain they are no longer needed.
Step 4: Add the Hostname and IP Address Mapping
Scroll to the bottom of the Hosts file.
Create a new blank line beneath any existing entries.
Enter the IP address followed by one or more spaces and then the hostname. Example: 192.168.1.100 MyServer
You can also create multiple mappings. Example:
192.168.1.100 MyServer
192.168.1.101 DatabaseServer
192.168.1.102 BackupServer
The format is simple: IP Address Hostname
Make sure there are no special characters in the hostname. Most administrators use letters, numbers, and hyphens for compatibility.
Avoid spaces inside hostnames because Windows may not interpret them correctly. After adding your desired mapping, review the entry carefully for typing errors.
Even a single incorrect digit can cause connection failures.
Step 5: Save the Hosts File
After entering the hostname mapping, save the file.
Click File and then choose Save.
Because Notepad was opened with administrator privileges, the file should save successfully.
If Windows displays a permission error, close Notepad and repeat the previous steps while ensuring that you launched Notepad as an administrator.
Once saved, the hostname assignment becomes part of your computer’s local network configuration.
However, Windows may still be using cached DNS information.
For that reason, the next step is important.
Step 6: Flush the DNS Cache
Windows stores DNS information in memory to speed up network access.
Sometimes the system continues using old records even after the Hosts file has been updated.
Flushing the DNS cache forces Windows to reload hostname information.
Click Start, type Command Prompt, and choose Run as administrator.
In the Command Prompt window, enter: ipconfig /flushdns
Press Enter.
You should see a confirmation message indicating that the DNS Resolver Cache was successfully flushed.
This step helps ensure that your newly created hostname becomes active immediately.
Step 7: Test the Hostname
Now it’s time to verify that everything is working.
- Open Command Prompt.
- Type the following command: ping MyServer
- Replace MyServer with your actual hostname.
- Press Enter.
If the configuration is correct, Windows should resolve the hostname to the assigned IP address.
You may see output similar to: Pinging MyServer [192.168.1.100]
This confirms that Windows successfully translated the hostname into the correct IP address.
You can also test the hostname in:
- File Explorer
- Remote Desktop Connection
- Network applications
- Web browsers
- SSH clients
Database management tools
If the hostname resolves correctly, the setup is complete.
Step 8: Verify the Hosts File Entry if Problems Occur
Sometimes the hostname may not work immediately.
- If that happens, review your Hosts file entry carefully.
- Ensure the IP address is correct.
- Ensure the hostname contains no spaces.
- Ensure the entry is on its own line.
- Ensure the file was saved correctly.
- Ensure the DNS cache was flushed.
You can also restart the computer to force Windows to reload networking components.
Many hostname issues are caused by simple typing mistakes, so double-check every character.
Common Uses for Hostname-to-IP Mapping
- Developers often use custom hostnames for local web servers.
- Network administrators use hostnames for routers, switches, and servers.
- IT professionals use hostname mappings during troubleshooting.
- Home lab users assign easy names to NAS devices and media servers.
- Organizations use custom mappings for testing before deploying DNS changes.
Because the Hosts file operates locally, it provides a quick and reliable method for hostname resolution without requiring access to a dedicated DNS server.
Advantages of Using the Hosts File
Using the Hosts file offers several benefits.
- It is built into Windows.
- No additional software is required.
- Changes take effect quickly.
- It works even when DNS servers are unavailable.
- It is useful for development and testing environments.
- It provides complete control over hostname resolution on the local machine.
These advantages make the Hosts file a valuable networking tool for both beginners and advanced users.
Limitations You Should Know About
Although the Hosts file is useful, it does have limitations.
- Changes apply only to the local computer.
- Other devices on the network cannot use the hostname unless they have the same Hosts file entry.
- Managing large numbers of devices becomes difficult.
- Manual updates are required whenever IP addresses change.
- For larger environments, a dedicated DNS server is generally a better solution.
However, for small networks and testing scenarios, the Hosts file remains one of the simplest methods available.
FAQs
What is a hostname in Windows?
A hostname is a human-readable name assigned to a device. It allows users to identify and access devices more easily than using numerical IP addresses.
Does assigning a hostname change the device’s actual name?
No. Editing the Hosts file only creates a local mapping on your computer. It does not rename the target device.
Where is the Hosts file located in Windows?
The Hosts file is located at:
C:\Windows\System32\drivers\etc\hosts
Do I need administrator rights to edit the Hosts file?
Yes. Administrative privileges are required because the Hosts file is a protected system file.
Can I assign multiple hostnames to one IP address?
Yes. You can create multiple hostname entries pointing to the same IP address.
Example:
192.168.1.100 MyServer
192.168.1.100 FileServer
Why is my hostname not working?
Common causes include incorrect IP addresses, typing errors, DNS cache issues, or failure to save the Hosts file properly.
Is the Hosts file available in Windows 11 and Windows 10?
Yes. Both Windows 11 and Windows 10 include the Hosts file and support hostname-to-IP mapping.
Can I remove a hostname later?
Yes. Simply delete the corresponding line from the Hosts file, save the file, and flush the DNS cache again.
