Hosts entry not working on macbook pro

Joined
Oct 26, 2010
Messages
2
Reaction score
1
Points
3
Hello

I made an entry under /private/etc/hosts file to have a static mapping of IP to hostname..but it doesn't seem to work.


eg:

# sudo nano /private/etc/hosts

# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
10.21.9.3 Google




Every time i reach out Google it does name look up and goes out to internet.

Any idea?
i cleared cache using 'dscacheutil -flushcache' .. no luck.

Thanks all!
 

chscag

Well-known member
Staff member
Admin
Joined
Jan 23, 2008
Messages
65,248
Reaction score
1,833
Points
113
Location
Keller, Texas
Your Mac's Specs
2017 27" iMac, 10.5" iPad Pro, iPhone 8, iPhone 11, iPhone 12 Mini, Numerous iPods, Monterey
Moved to appropriate forum.
 
Joined
Jul 2, 2007
Messages
3,494
Reaction score
204
Points
63
Location
Going Galt...
Your Mac's Specs
MacBookAir5,2:10.13.6-iMac18,3:10.13.6-iPhone9,3:11.4.1
Well, my first question would be... "What are you trying to accomplish?"

You might try putting the entry in the format:

xxx.xxx.xxx.xxx hostname alias

and make sure you have an alias. Sometimes OS X gets freaked out without one.

Then try: lookupd -flushcache

I'll do some looking around if that doesn't work. It's been awhile since I messed with OS X hosts files.

Here's a useful snippet I found...

http://decoding.wordpress.com/2009/04/06/how-to-edit-the-hosts-file-in-mac-os-x-leopard/

"Also keep in mind, you can completely stop using /etc/hosts and use dscl to manage your hosts, which seems to be how Apple is moving forward in this regard. `man dscl` for more info.

To add a host with dscl, and skip /etc/hosts the syntax is pretty easy. This would create foobar.local and point it to 127.0.0.1

sudo dscl localhost -create /Local/Default/Hosts/foobar.local IPAddress 127.0.0.1

You can then flush the cache to have it take effect:

sudo dscacheutil -flushcache

And in case you were wondering what is in that cache, just to make sure it was cleared, or if you are having trouble, you can list the cache:

sudo dscacheutil -cachedump -entries Host

You can delete much the same:

sudo dscl localhost -delete /Local/Default/Hosts/foobar.local

And of course, if you want to list your entries:

dscl localhost -list /Local/Default/Hosts"
 
OP
S
Joined
Oct 26, 2010
Messages
2
Reaction score
1
Points
3
Excellent!!

Thank you very much XJ-Linux!!

"sudo dscl localhost -create /Local/Default/Hosts/foobar.local IPAddress 127.0.0.1" worked perfect.

What ever i do on /etc/hosts doesn't seem to change a thing for some reason.

Cheers
 
Joined
Jul 2, 2007
Messages
3,494
Reaction score
204
Points
63
Location
Going Galt...
Your Mac's Specs
MacBookAir5,2:10.13.6-iMac18,3:10.13.6-iPhone9,3:11.4.1
Good deal. It was an old link I had in my browser and I couldn't remember why I had it saved. Now I remember it had to do with getting to where I wanted within a clients firewall/router/etc. Glad it worked for you!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top