Question C:\\Windows\System32\drivers\etc\hosts is not functioning, being ignored ?

I have a new installation of a Windows 10 Pro installed, fully updated (given to me by a friend who is closing down some of his shop inventory he doesn't use). It works quite well, except I am trying to add some aliases for local network devices. The file in the title is not corrupt, and it has correct permissions. I can ping the dotted-decimal address I've added to a NAS there, but I wanted to simply refer to it as "nas" sometimes instead of memorizing the IP address. Can't do it. I've even gone so far as to load the file in an editor which shows hidden characters, e.g., tabs, newline, carriage return, so on. The file has been restored and reedited with different editors (run as administrator). The regular user can read that file. The same edits work on other Windows 10 machines, and I have many times rebooted and flushed DNS cache.

If the file is not corrupt, and if permissions are correct, and if syntax is correct, and if DNS cache is not the problem, then what setting would need to change to enable the "C:\\Windows\System32\drivers\etc\hosts" file?
 
No, it is definitely at the full path listed, not SystemWOW64. I was not even aware of SystemWOW64. Is there some secondary location the file needs to be other than:
C:\\Windows\System32\drivers\etc\hosts
typo in path? extra \ character in path.
should be
c:\windows\system32\drivers\etc\hosts

note: old bug in cmd.exe strips out leading \ characters.

ie c:\\\\windows\system32\drivers\etc\hosts
is the same. but some of these old bugs might be turned off because of a optional flag setting in new versions of windows.
 
typo in path? extra \ character in path.
should be
c:\windows\system32\drivers\etc\hosts

note: old bug in cmd.exe strips out leading \ characters.

ie c:\\\\windows\system32\drivers\etc\hosts
is the same. but some of these old bugs might be turned off because of a optional flag setting in new versions of windows.
No, the path is correct. Also, I didn't manually type it in to edit the file, that's just how it shows up. "C:\" is the "C" drive; the root of the path starts with "\", and naming the drive plus the start of an absolute path is "C:\\".

Browsers substitute a forward slash, but put this in your browser to try it out:
file://c:\

You will find the browser translates it to "http" URL syntax, but this is the root of the C drive.

Regardless, my editor opened this file from Windows file explorer, and the comments which are at the top of the default file were in fact there. No mistake. I just do not know why edits are ignored. Some bug no doubt, but I have no idea what it would be. I've probably edited this on a dozen windows 10 systems and none have ever been ignored (until now).
 
That's absolutely weird.

Try HostsMan ?


You can also setup a local DNS like Technitium DNS
I tend to not trust third party apps. Even so, I really want to know what is wrong with this hosts file rather than finding a workaround. I've never had a hosts file do this before and I've been using that for a very very long time.
 
If you can't solve hosts file issue, I don't know how you can solve naming issue without using a DNS server.

What's your NAS brand/model and can it run a DNS service, server, docker or VM?
 
Last edited:
If you can't solve hosts file issue, I don't know how you can solve naming issue without using a DNS server.

What's your NAS brand/model and can it run a DNS service, server, docker or VM?
It isn't that I can't ping or reach the NAS. I can do with the dotted decimal address. Also the printer and three other computers on the network via dotted decimal. Google, a lot of others by name work perfectly.
 
I didn't say your DNS setting is not working. However the DNS server most uses use are public DNS severs that only resolve computer names on the internet, not LAN devices/computers.

If your hosts file doesn't work, you need a local DNS to work for you.
 
I didn't say your DNS setting is not working. However the DNS server most uses use are public DNS severs that only resolve computer names on the internet, not LAN devices/computers.

If your hosts file doesn't work, you need a local DNS to work for you.
This is what the hosts file is for. Local aliases without the overhead of a custom DNS setup. There is no need for local DNS if I can give an alias to dotted=decimal addresses. It is the very purpose of the hosts file.
 
Of course I know what hosts file is and it's purpose and if it works then you don't need a burden of a DNS,

You also think your hosts file path is absolutely correct with double back slash.

Hope other members can help.
 
I am not sure that I completely understand the requirement.

FYI:

https://serverfault.com/questions/377623/how-to-set-local-alias-for-a-machine

Note the mention of CNAME.

However, aliases can be created.

https://learn.microsoft.com/en-us/w.../create-an-alias-cname-record-in-dns-for-web1

From the link:

"You can use this procedure to add an Alias canonical name (CNAME) resource record for your Web server to a zone in DNS on your domain controller. With CNAME records, you can use more than one name to point to a single host, making it easy to do such things as host both a File Transfer Protocol (FTP) server and a Web server on the same computer."

That said, if aliases are required then Powershell can do such things.

Not something that I have worked with (full disclosure). However, the following links may prove helpful.

https://techcommunity.microsoft.com...-aliases-in-place-of-dns-cname-records/259064

https://www.commandinline.com/cheat-sheet/resolve-dnsname/

That all said, I next stumbled on to this old link:

https://superuser.com/questions/319566/how-do-i-alias-a-hostname-in-windows

From the link:

"HOSTS is only for giving names to IP addresses. So you can so something like:

10.1.1.2 Computer.domain.com Alias1 Alias99


Instead of 10.1.1.2 you would use the NAS Static IP address.
 
@Ralston18

What you mentioned in the beginning was a in business environment where there is a Windows server domain controller running Active Directory and of course the DNS that comes along with it. It's even more complex,
 
@cruisetung

Fair point. Thanks.

"Beginning" meaning the use of Powershell cmdlet(s) etc. - correct?

I did some additional searching (Google) and found some other links.

For example:

https://www.bing.com/search?q=How+t...efig=EED9F59461C644A2A071C0D39D62D1CD&pc=U711

From the link:

"To assign a network alias in PowerShell, you can use the New-NetIPAddress cmdlet to configure an IP address and alias for a network adapter. However, if you're specifically referring to assigning a "network alias" (like a hostname or DNS alias), you would typically modify the system's hosts file or configure DNS settings."

Also:

https://learn.microsoft.com/en-us/powershell/scripting/learn/shell/using-aliases?view=powershell-7.5

= = = =

Again not sure about the overall environment and requirements - including DNS etc.

E.g.:

"DNS works fine. Just a custom alias for the nas and printer I'm trying to create fails. Everything else works."

"If the file is not corrupt, and if permissions are correct, and if syntax is correct, and if DNS cache is not the problem, then what setting would need to change to enable the "C:\\Windows\System32\drivers\etc\hosts" file?

"It works quite well, except I am trying to add some aliases for local network devices."

= = = =

I am not one to question requirements per se but I wondered about need for aliases - especially if in a non-business environment. Useful during transistions and so forth but I do not see aliases being particularily helpful in a small network environment. Likely to become confusing due to changes and inconsistencies.

Assign a static IP address to the named NAS or Printer or other device - keep it simple. Use the device(s) macs as necesary.

Overall somewhat out of my comfort zones because I have not (full disclosure) worked with Powershell and the use of aliases per the requirements.

However, Powershell can be quite surprising. OP and/or others may discover some way to make it all work.

The links may prove helpful via additional insights, cmdlet use, syntax, examples.

For fun, google "Need an alias name for my network storage" - then filter to "past year".
 
The alias you mentioned is for Powershell cmdlet only, it has nothing to do computer name alias at all. It's just a shortcut for Powershell cmdlets

View: https://www.youtube.com/watch?v=0Rl_V079HEw

==

PC must have an IP number to communicate with each and does not require a name. A computer name or alias are only for human being to easy to remember/recognize/identify, just like people would like to call his friends just looking up names in address book instead dialing phone numbers directly if possible.

The problem with LAN network is that there is no server that can records all the computer names on the network and store computer names in a database, all computers on the network have to broadcast their names all the time so computer can store those IP <--> name pairs info in cache, but once you reboot those info are gone and have to start over, and that where DNS server comes in, if you can host one on your network, then it became a central database that every PC can query againt if you point the DNS to it.

If you can't host a DNS server then you can modify hosts file so it contains IP address and any number of computer aliases like

192,168.1.10 www www.homelab.net nas mediaserver plex

when you add an entry like the above in the hosts file, then you can refer to the same 192.168.1.10 PC using 5 different names anywhere a Windows app that support computer name.

The problem with hosts file is that you have to modify it on each PC.

As suggested by @johnbl it could be antivirus thing preventing OP from modifying hosts file. Only he can find out.
 
Should have been this link:

https://www.bing.com/search?q=power...efig=1C175E5CA35E4C72A7D2B8421EBC6A14&pc=U711

From the link:

"In PowerShell, a "network alias" typically refers to creating an alternate name for a computer or network resource, often used for convenience or to simplify access. While PowerShell itself doesn't have a direct "network alias" command, you can achieve similar functionality using DNS, hosts file modifications, or PowerShell scripts to manage network configurations.

Here are three approaches to handle network aliases in PowerShell:"


[My underline.]

From the link (Approach 1):

$hostsPath = "$env:SystemRoot\System32\drivers\etc\hosts"
$aliasEntry = "192.168.1.100 myalias.local"

# Check if the alias already exists
if (-not (Get-Content $hostsPath | Select-String -Pattern "myalias.local")) {
Add-Content -Path $hostsPath -Value $aliasEntry
Write-Host "Alias added to hosts file."
} else {
Write-Host "Alias already exists in hosts file."
}


Seems to be in accord with the "old link" referenced in Post #15.

= = = =

Not sure how I mixed up the links. Apologies.

As for hosts file, agree. It should be posted.
 
@Ralston18

What you mentioned in the beginning was a in business environment where there is a Windows server domain controller running Active Directory and of course the DNS that comes along with it. It's even more complex,
I haven't had time to work on this more, but will soon. So far as previous use goes I've done this on home machines for about the last 20 years. No active server or domain. The "hosts" file, if you look at it, is nothing more than a substitution macro. For example, if you "ping nas", then you will find no route to it and ping will fail. Let's say you have a printer or a second computer on the network, and its address is "192.168.1.42". If you can "ping 192.168.1.42" and see a response, then you can also "ping nas" without any DNS if this line is in the hosts file:
192.168.1.42 nas
(you can actually use multiple spaces or single spaces, a tab, or multiple tabs; I've check all formats and none work)

Every other machine this works on. Check your hosts file and find any address you can ping. Give it a dotted-decimal address on the left, and the alias you want (such as "testing") and ping it. It's just a substitution macro and it occurs before DNS is ever consulted. You could even give an alias to your own machine, so if you talk about your machine as "host", and if it has the address "192.168.1.2", then this allows you to ping it (from itself) via "ping host":
192.168.1.2 host

It's purely substitution macro. Try it.
 
Thanks.

I would expect that that (or something similar) would work just at face value. Thus far no success...

I have been doing some testing as well.

I have a HP Office Jet Pro 9015 printer on my network with a Static IP address 192.168.1.102 (subnet 255.255.255.0)

Here is my hosts file with the substitution macro at the end.

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

#Testing Substitution Macro

192.168.1.102 HPOfficeJet

#End of Test


= = = = Ping results via elevated PS>

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\WINDOWS\system32> ping 192.168.1.102

Pinging 192.168.1.102 with 32 bytes of data:
Reply from 192.168.1.102: bytes=32 time<1ms TTL=64
Reply from 192.168.1.102: bytes=32 time=1ms TTL=64
Reply from 192.168.1.102: bytes=32 time=1ms TTL=64
Reply from 192.168.1.102: bytes=32 time=1ms TTL=64

Ping statistics for 192.168.1.102:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
PS C:\WINDOWS\system32> ping HPOfficeJet
Ping request could not find host HPOfficeJet. Please check the name and try again.
PS C:\WINDOWS\system32>

= = = =

I have tried a couple of variations in hosts with the same "could not find" results.

For examle using/including "alias" as in Post 15.

Only posting the preceeding "code" in hopes that there may be some error of omission or commision on my part.

I have found a couple of PS scripts that are much more involved but fail with various errors - TBD.

Possibly a function could be made to work.

The requirement being to make my computer (or any computer on my network) that when given a name then associate that name with 192.168.1.102 and go forward with ping to 192.168.1.102 when "ping HPOfficeJet" is used. Or do whatever if/when "HPOfficeJet" is appropriately used.

Printer mac may be needed somewhere ???

My next experiment is going to be with Environmental Variables.

Run Get-ChildItem Env:

Maybe (thinking out of the box a bit) create an Environment variable "HPOfficeJet" value "192.168.1.102"

And will climb back in if I fall out as tends to happen... :)

No harm in thinking out loud and sharing.
 
@Ralston18

The whole thing really has nothing to do with Powershell, you are making it unnecessarily complex.

Hosts file can easily modified by any txt editor with admin rights

I have a brother laser printer with static IP 192.168.1.15 and added an entry in hosts file

Code:
192.168.1.15 brother laser
and I can easily ping both names

Code:
C:\Windows\System32>ping brother

Pinging brother [192.168.1.15] with 32 bytes of data:
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255

Ping statistics for 192.168.1.15:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\Windows\System32>ping laser

Pinging brother [192.168.1.15] with 32 bytes of data:
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255
Reply from 192.168.1.15: bytes=32 time<1ms TTL=255

Ping statistics for 192.168.1.15:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

No idea why it wouldn't work for you?
 
Last edited: