F5F Stay Refreshed Software Operating Systems The file C:\Windows\System32\drivers\etc\hosts isn't working and is being ignored?

The file C:\Windows\System32\drivers\etc\hosts isn't working and is being ignored?

The file C:\Windows\System32\drivers\etc\hosts isn't working and is being ignored?

Pages (3): Previous 1 2 3
D
DriveIn
Senior Member
739
10-19-2016, 06:31 PM
#21
I haven't spent much time refining this yet, but I'll get to it soon. In the past, I've handled this on local devices for roughly the past two decades. There hasn't been an active server or domain involved. The "hosts" file appears to be just a simple substitution macro. For instance, if you try "ping nas," you won't find any route and the ping will fail. Suppose you have a printer or another computer on the network with an address like "192.168.1.42." If you can reach that device by pinging its IP and receive a response, then you should be able to ping "nas" without needing DNS, provided this entry exists in the hosts file.

You can modify the hosts file by adding entries like:

192.168.1.42 nas

You may use various formats—spaces, tabs, or multiple lines—but none of them work. Every other machine should recognize it. Review your hosts file, locate an address you can ping, and enter it in the format: left with a dotted-decimal number and the alias you prefer (such as "testing"), then send a ping. It's essentially a substitution macro that happens before DNS is consulted. You could even assign an alias to your own machine, enabling you to ping it from within itself using "ping host" if it has the address "192.168.1.2."

It's simply a substitution macro—give it a try.
D
DriveIn
10-19-2016, 06:31 PM #21

I haven't spent much time refining this yet, but I'll get to it soon. In the past, I've handled this on local devices for roughly the past two decades. There hasn't been an active server or domain involved. The "hosts" file appears to be just a simple substitution macro. For instance, if you try "ping nas," you won't find any route and the ping will fail. Suppose you have a printer or another computer on the network with an address like "192.168.1.42." If you can reach that device by pinging its IP and receive a response, then you should be able to ping "nas" without needing DNS, provided this entry exists in the hosts file.

You can modify the hosts file by adding entries like:

192.168.1.42 nas

You may use various formats—spaces, tabs, or multiple lines—but none of them work. Every other machine should recognize it. Review your hosts file, locate an address you can ping, and enter it in the format: left with a dotted-decimal number and the alias you prefer (such as "testing"), then send a ping. It's essentially a substitution macro that happens before DNS is consulted. You could even assign an alias to your own machine, enabling you to ping it from within itself using "ping host" if it has the address "192.168.1.2."

It's simply a substitution macro—give it a try.

Y
YoloGeek22
Member
152
10-19-2016, 07:40 PM
#22
I anticipate that this should function directly without any issues. So far, no results...
I've also conducted some tests.
My HP Office Jet Pro 9015 is connected to the network with a static IP address of 192.168.1.102 (subnet 255.255.255.0).
Here is my modified hosts file with the substitution macro at the end.
# Copyright © 1993-2009 Microsoft Corp.
#
# This sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# Each entry must remain on its own line. The IP address should come first, followed by the host name.
# They should be separated by at least one space.
#
# Comments like these can appear individually or after a machine name (denoted by '#').
#
# For instance:
# 192.168.1.102 HPOfficeJet
# localhost name resolution is managed via DNS.
# 127.0.0.1 localhost
# ::1 localhost
Testing Substitution Macro
192.168.1.102 HPOfficeJet
#End of Test
= = = = Checking ping results through elevated PowerShell
Windows PowerShell
Copyright © Microsoft Corporation. All rights reserved.
Upgrade to the latest PowerShell for new features and enhancements!
https://aka.ms/PSWindows
Running from C:\WINDOWS\system32> ping 192.168.1.102
Sending 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 stats for 192.168.1.102:
Packets sent = 4, received = 4, lost = 0 (no loss),
Approximate round trip times: minimum 0ms, maximum 1ms, average 0ms
PS C:\WINDOWS\system32> ping HPOfficeJet
Failed to locate host HPOfficeJet. Please verify the name and retry.
PS C:\WINDOWS\system32>
= = = =
I experimented with several variations in the hosts file, all returning "could not find" errors.
For example, using "alias" as in Post 15.
I've discovered some more complex PowerShell scripts that encounter various issues—status pending.
It might be possible to create a function that resolves this.
The goal is for my computer (or any device on the network) to link a name with 192.168.1.102 and forward pings to that address when "ping HPOfficeJet" is issued. Or handle it in any way if needed.
A printer driver might be required somewhere?
My next attempt will focus on using Environment Variables.
Running
Get-ChildItem Env:
Perhaps I could set an environment variable named "HPOfficeJet" with the value 192.168.1.102.
It should restore itself if it gets lost.
It's okay to consider this idea aloud and share.
Y
YoloGeek22
10-19-2016, 07:40 PM #22

I anticipate that this should function directly without any issues. So far, no results...
I've also conducted some tests.
My HP Office Jet Pro 9015 is connected to the network with a static IP address of 192.168.1.102 (subnet 255.255.255.0).
Here is my modified hosts file with the substitution macro at the end.
# Copyright © 1993-2009 Microsoft Corp.
#
# This sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# Each entry must remain on its own line. The IP address should come first, followed by the host name.
# They should be separated by at least one space.
#
# Comments like these can appear individually or after a machine name (denoted by '#').
#
# For instance:
# 192.168.1.102 HPOfficeJet
# localhost name resolution is managed via DNS.
# 127.0.0.1 localhost
# ::1 localhost
Testing Substitution Macro
192.168.1.102 HPOfficeJet
#End of Test
= = = = Checking ping results through elevated PowerShell
Windows PowerShell
Copyright © Microsoft Corporation. All rights reserved.
Upgrade to the latest PowerShell for new features and enhancements!
https://aka.ms/PSWindows
Running from C:\WINDOWS\system32> ping 192.168.1.102
Sending 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 stats for 192.168.1.102:
Packets sent = 4, received = 4, lost = 0 (no loss),
Approximate round trip times: minimum 0ms, maximum 1ms, average 0ms
PS C:\WINDOWS\system32> ping HPOfficeJet
Failed to locate host HPOfficeJet. Please verify the name and retry.
PS C:\WINDOWS\system32>
= = = =
I experimented with several variations in the hosts file, all returning "could not find" errors.
For example, using "alias" as in Post 15.
I've discovered some more complex PowerShell scripts that encounter various issues—status pending.
It might be possible to create a function that resolves this.
The goal is for my computer (or any device on the network) to link a name with 192.168.1.102 and forward pings to that address when "ping HPOfficeJet" is issued. Or handle it in any way if needed.
A printer driver might be required somewhere?
My next attempt will focus on using Environment Variables.
Running
Get-ChildItem Env:
Perhaps I could set an environment variable named "HPOfficeJet" with the value 192.168.1.102.
It should restore itself if it gets lost.
It's okay to consider this idea aloud and share.

I
IPS10
Senior Member
623
10-19-2016, 09:12 PM
#23
The entire situation isn't related to PowerShell, you're adding unnecessary complexity.
The hosts file is simple enough to be changed with any text editor that has admin privileges.
I own a brother's laser printer with a static IP address of 192.168.1.15 and I added an entry in the 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

I also ping my brother's printer [192.168.1.15] and it works perfectly.
No idea why this wouldn't function for you?
I
IPS10
10-19-2016, 09:12 PM #23

The entire situation isn't related to PowerShell, you're adding unnecessary complexity.
The hosts file is simple enough to be changed with any text editor that has admin privileges.
I own a brother's laser printer with a static IP address of 192.168.1.15 and I added an entry in the 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

I also ping my brother's printer [192.168.1.15] and it works perfectly.
No idea why this wouldn't function for you?

C
CatNinjaXD
Member
208
10-19-2016, 10:55 PM
#24
If the host file isn't working, try formatting the drive and reinstalling Windows from scratch. It's possible the earlier setup has restrictions.
C
CatNinjaXD
10-19-2016, 10:55 PM #24

If the host file isn't working, try formatting the drive and reinstalling Windows from scratch. It's possible the earlier setup has restrictions.

Z
zebracraft01
Junior Member
8
10-20-2016, 12:32 AM
#25
Delayed update:
@cruisetung
Still unsure but everything seems to be functioning properly now.
I opened Notepad as admin to modify the hosts file, replacing "HPOfficeJet" with "denprinter".
The ping worked correctly after that change.
Earlier, I faced an issue when saving files because Windows said I lacked the required admin permissions. That was quickly resolved.
But during the initial edit of the hosts file, there were no problems saving changes.
Gremlins....
Thanks.
Z
zebracraft01
10-20-2016, 12:32 AM #25

Delayed update:
@cruisetung
Still unsure but everything seems to be functioning properly now.
I opened Notepad as admin to modify the hosts file, replacing "HPOfficeJet" with "denprinter".
The ping worked correctly after that change.
Earlier, I faced an issue when saving files because Windows said I lacked the required admin permissions. That was quickly resolved.
But during the initial edit of the hosts file, there were no problems saving changes.
Gremlins....
Thanks.

Pages (3): Previous 1 2 3