92
There are several ways - here are two:
cat /etc/resolv.conf
-or-
scutil --dns
65
/private/etc/hosts seems to be working normally for me in Yosemite (version 10.10.1). It's not necessary to flush the cache or reset discoveryd (the DNS resolver in Yosemite); sudo fs_usage | grep private/etc/hosts shows discoveryd reading the file immediately after I save changes to it.
[Update: discoveryd was only used in OS X versions 10.10.0 - 10.10.3. ...
47
This question seems a bit old, but I'm going to answer it anyways as I had a similar problem:
Yes, this works.
Your first problem is that you obviously have the wrong IP (8.8.8.8 instead of 203.12.160.35) in /etc/resolver/apple.com. Verify that the contents of this file is really:
nameserver 203.12.160.35
Then scutil --dns should have an entry like this:
...
24
Since discoveryutil was replaced by its predecessor mDNSResponder in 10.10.4 use sudo killall -HUP mDNSResponder again (like in Lion/Mountain Lion/Mavericks) to flush the DNS cache.
21
I have discovered another wrinkle with this issue.
In order to fix the problem I was having, I had to ADD IPv6 style hosts file entries.
It seems that Safari will overlook IPv4 entries IF you have an IPv6 network configuration setup.
You must add duplicate entries that resolve to IPv6 localhost address in /etc/hosts.
IPv4 entry
127.68.56.101 facebook.com
...
19
According to the the hosts(5) manual page, the /etc/hosts file is used by mDNSResponder. Your attempts are correctly flushing the computer wide cache but you also need to flush the browser's private cache.
After each edit of /etc/hosts reset the mDNSResponder cache using this Apple technical note, OS X: How to reset the DNS cache:
sudo dscacheutil -...
19
sudo dscacheutil -flushcache does nothing useful related to DNS cache entries - at least in non-LDAP environments and 10.9-10.13.
sudo killall -HUP mDNSResponder sends a hang up to mDNSResponder, launchd will restart the daemon and the DNS cache will be cleared as spillover effect.
This can easily be tested with the following command sequence:
sudo ...
18
Since 10.10.1, the simplest way to fix this is to add --AlwaysAppendSearchDomains to ProgramArguments in plist file /System/Library/LaunchDaemons/com.apple.discoveryd.plist
Then restart com.apple.discoveryd.plist with:
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.discoveryd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple....
18
Check your hosts file, because probably it's malformed. It should look similar to this one:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 youtube.com
127.0.0.1 www.youtube.com
255.255.255.255 broadcasthost
::1 ...
17
For me it's in the file
/etc/pulse-hosts.bak
You have to edit this file to customize your hosts directives
When you are going to reconnect/connect using the Pulse Secure VPN, it's going to merge the directives from the
/etc/pulse-hosts.bak
with the content from Pulse directives and creates the
/etc/hosts
2018 Update
With the newer version of ...
17
How can I set up my DNS servers to be configured differently for each wireless network?
Set and Change in Network Preferences
You can set your own custom DNS settings on a location basis by defining a "Location" in Network Preferences
You would then enter your preferred DNS settings (click "Advanced") under the DNS tab:
After you create set the ...
16
I was able to fix this issue by explicitly setting the HostName using scutil to be the same value as LocalHostName:
$ scutil --set HostName $(scutil --get LocalHostName)
Now:
$ sudo scutil --set HostName MacBook-Pro
$ time python -c 'import socket; print(socket.getfqdn())'
MacBook-Pro
python -c 'import socket; print(socket.getfqdn())' 0.01s user 0.00s ...
16
If using a third-party utility is not an issue for you, then I recommend giving these a try:
arp-scan (available via Homebrew)
brew install arp-scan
arp-scan --localnet
fing (download and install the "Desktop Embedded CLI" package from fing.com or via Homebrew brew cask install fing)
sudo fing -r 1 -d true -o table,text
Both utilities have a number of ...
15
I had the same problem on my Mac, and after fixing it I have figured out that it was caused by FortiClient (VPN client). Even when FortiClient was disconnected - it's DNS still appeared in the scutil.
The solution for me was:
scutil
> list ".*DNS"
This will show you a list of all DNS configs, that will look something like:
subKey [0] = State:/Network/...
14
You can flush the local DNS cache with the following command:
dscacheutil -flushcache
How long a DNS entry is cached typically depends on the TTL of that DNS record, which is configured by the DNS admin of the relevant hostname.
You can find out the (remaining) TTL of any given DNS record with the dig command:
dig apple.stackexchange.com
In the answer ...
14
If you are using Juno Pulse VPN client, /etc/hosts gets over-written by /etc/jnpr-pulse-hosts.bak
14
Had this same issue. I think the local DNS cache had bad data from my previous testing. It was quickly fixed by:
sudo killall -HUP mDNSResponder
11
Yep. You can do this, /etc/resolver is your friend.
$ man 5 resolver:
domain
Domain name associated with this resolver configuration.
This option is normally not required by the Mac OS X DNS search system when the resolver configuration is read from a file in the /etc/resolver directory. In that case the file name is used as the domain name.
...
11
As a tool to help you find the culprit, here is a dtrace oneliner which prints the pid and name of any process which opens a file for writing, together with the filename:
dtrace -qn 'syscall::open*:entry /arg1&3/ { printf("%d %s %s\n", pid, execname, copyinstr(arg0)); }'
It needs to be run as root (e.g., with sudo). Pipe it into grep hosts to avoid ...
11
It took a LOT of Googling and digging to get this, but I finally found a solution that works. DHCP overrides the LocalHostName system property, but not the HostName property. By default the HostName is not set in macOS Sierra, so you can set it as well as LocalHostName and ComputerName using scutil:
sudo scutil --set HostName yourcomputername
sudo scutil --...
10
Using resolver files is actually not the recommended way of doing that.
Instead you should create DNS resolver with scutil.
To see all DNS queries on interface en0, open a Terminal and run:
sudo tcpdump -n -i en0 port 53
Open another Terminal window and run:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
ping apple.stackexchange.com -c1
...
9
in OSX Mavericks (10.9 - actually 10.6.3 up, I believe) if you want to see the active DNS configuration:
scutil --dns
The -first- entry (resolver #1) is reportedly the active configuration...though I've seen plenty of cases where that's not the case.
from man scutil
The --dns option reports the current DNS configuration. The first listed
resolver(5) ...
9
I have solved the problem by restoring my Hosts file (it was empty):
But before, you have to check your hosts file.
cat /etc/hosts
If nothing is shown, that means your hosts file is empty.
Then just copy and paste this over the existing hosts file then save it as plain text to restore it.
##
# Host Database
#
# localhost is used to configure the ...
9
Build your own VPN using OpenVPN & easy-rsa on a digital ocean cloud server ($5/mo for cheapest VM & 2TB monthly transfer), configure VPN to tunnel/forward all traffic, set up Cloudflare 1.1.1.1 on VPN, then use Apple Configurator to set an always on VPN connection.
Can confirm this is how I do it, I set up Ubuntu 16.04 server instance and the ...
9
This was a huge hassle to figure out, so I wrote up a little guide in hopes that others would find it helpful:
How to convince macOS to do IPv6 DNS lookups when your only IPv6 address is via a VPN or tunnel of some sort
The Problem
macOS's domain name resolver will only return IPv6 addresses (from AAAA records) when it thinks that you have a valid ...
9
tl;dr make sure you start dnsmasq as root.
To diagnose this problem, I used Console.app, and searched for dnsmasq.
My first problem revealed in the logs:
failed to create listening socket for 127.0.0.1: Address already in use
FAILED to start up
To fix this, make sure dnsmasq is stopped:
brew services stop dnsmasq
then use Activity Monitor.app to kill ...
9
To clean DNS cache on macOS, the following command should be used. (commands used to clean caches seems to be different on different version of macOS)
sudo killall -HUP mDNSResponder
Clean the DNS cache in Safari. Open Safari, Preferences -> Advanced. Check "Show develop menu in menu bar". Then go to menu bar, Develop -> Empty Caches. The shortcut is ⌥⌘E. (...
8
Do you use Cisco's AnyConnect VPN client? If so, you need to edit /etc/hosts.ac instead, and let it copy that to the live file. See this MacOSXHints article, and these previous questions.
EDIT: I can't find anything specifically about Janos Pulse, but Juniper's Network Connect messes with /etc/hosts, and I suspect Pulse may do the same thing. According to ...
answered Jul 18 '13 at 21:26
Gordon Davisson
27.8k44 gold badges5757 silver badges7474 bronze badges
8
A long shot, but do you use a Bonjour account with Adium? https://trac.adium.im/ticket/16827
An update from the OP indicates this was the issue:
Turns out the issue was leaving bonjour messaging enabled in Adium. To fix this I unloaded/loaded discoveryd, went into Adium, disabled bonjour then restarted with no problem. If you want bonjour, load/unload ...
8
There are three different hostnames that macOS/OS X uses:
ComputerName
HostName
LocalHostName
Each of these values can be found in /Library/Preferences/SystemConfiguration/preferences.plist
ComputerName
scutil --get ComputerName
This is Apple "friendly" name for the computer and can be found in System Preferences >> Sharing >> Computer Name. According ...
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
dns × 500network × 254
macos × 225
wifi × 51
vpn × 34
hosts × 31
ios × 27
macbook-pro × 23
osx-server × 23
safari × 22
bonjour × 22
airport × 21
internet × 19
terminal × 18
server.app × 18
iphone × 14
mojave × 12
security × 12
google-chrome × 12
ssh × 11
mac × 10
command-line × 10
high-sierra × 10
catalina × 9
snow-leopard × 9