I've installed valet for laravel using homebrew on my mac (Mojave). According to laravel's documentation I should now be able to ping *.test, but when I keep getting the following error:
ping:cannot resolve foobar.test: Unknown host
It looks like an issue with dnsmasq. I've followed all the suggestions here, but nothing seems to help.
# Content of '/Users/<username>/.config/valet/dnsmasq.conf'
address=/.test/127.0.0.1
listen-address=127.0.0.1
I can see that the resolver for .test seems to be set up ok. Below is the output from scutil --dns
DNS configuration
resolver #1
search domain[0] : default
nameserver[0] : 192.168.1.1
if_index : 6 (en0)
flags : Request A records
reach : 0x00020002 (Reachable,Directly Reachable Address)
resolver #2
domain : local
options : mdns
timeout : 5
flags : Request A records
reach : 0x00000000 (Not Reachable)
order : 300000
resolver #3
domain : 254.169.in-addr.arpa
options : mdns
timeout : 5
flags : Request A records
reach : 0x00000000 (Not Reachable)
order : 300200
resolver #4
domain : 8.e.f.ip6.arpa
options : mdns
timeout : 5
flags : Request A records
reach : 0x00000000 (Not Reachable)
order : 300400
resolver #5
domain : 9.e.f.ip6.arpa
options : mdns
timeout : 5
flags : Request A records
reach : 0x00000000 (Not Reachable)
order : 300600
resolver #6
domain : a.e.f.ip6.arpa
options : mdns
timeout : 5
flags : Request A records
reach : 0x00000000 (Not Reachable)
order : 300800
resolver #7
domain : b.e.f.ip6.arpa
options : mdns
timeout : 5
flags : Request A records
reach : 0x00000000 (Not Reachable)
order : 301000
resolver #8
domain : test
nameserver[0] : 127.0.0.1
flags : Request A records, Request AAAA records
reach : 0x00030002 (Reachable,Local Address,Directly Reachable Address)
DNS configuration (for scoped queries)
resolver #1
search domain[0] : default
nameserver[0] : 192.168.1.1
if_index : 6 (en0)
flags : Scoped, Request A records
reach : 0x00020002 (Reachable,Directly Reachable Address)
I can also see that dnsmasq seems to be running ok. Here's the output from brew services list
:
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
httpd started root /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
mysql started root /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
nginx started root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
php@7.1 started root /Library/LaunchDaemons/homebrew.mxcl.php@7.1.plist
php@7.2 started root /Library/LaunchDaemons/homebrew.mxcl.php@7.2.plist
Other things I've tried:
sudo brew services
restart dnsmasq
valet install
Anyone got any other suggestions?
EDIT: Output of sudo brew services restart --verbose dnsmasq
`Stopping `dnsmasq`... (might take a while)
==> Successfully stopped `dnsmasq` (label: homebrew.mxcl.dnsmasq)
==> Generated plist for dnsmasq:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.dnsmasq</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/dnsmasq/sbin/dnsmasq</string>
<string>--keep-in-foreground</string>
<string>-C</string>
<string>/usr/local/etc/dnsmasq.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
/bin/launchctl enable system/homebrew.mxcl.dnsmasq
/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
==> Successfully started `dnsmasq` (label: homebrew.mxcl.dnsmasq)
EDIT 2:
I think I'm getting somewhere now. I checked in console.app for dnsmasq and I saw the error message:
failed to open pidfile /usr/local/var/run/dnsmasq/dnsmasq.pid: No such file or directory
...which led me here. It turns out I was missing the dnsmasq
folder in cd /usr/local/var/run/
so I ran sudo mkdir dnsmasq
and now the ping actually returns the following response:
PING foobar.test (127.0.0.1): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
Request timeout for icmp_seq 7
...
I'm not sure what this means or whether it is now working.
When I go to foobar.test in my browser I get the message This site can’t be reached
even though I have created a project with that name and linked it using valet link foobar
.
EDIT 3:
I've got ping working properly now by turning off stealth mode (as described here) but I still get This site can’t be reached
when I navigate to foobar.test in my browser.
I get the following error when I run curl foobar.test --verbose
* Rebuilt URL to: foobar.test/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to foobar.test (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: foobar.test
> User-Agent: curl/7.54.0
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
EDIT 4
Output of cat /usr/local/etc/dnsmasq.conf | grep -i interface
:
# 10.1.2.3 to 192.168.1.1 port 55 (there must be an interface with that
# specified interfaces (and the loopback) give the name of the
# interface (eg eth0) here.
# Repeat the line for more than one interface.
#interface=
# Or you can specify which interface _not_ to listen on
#except-interface=
# If you want dnsmasq to provide only DNS service on an interface,
#no-dhcp-interface=
# even when it is listening on only some interfaces. It then discards
# working even when interfaces come and go and change address. If you
# want dnsmasq to really bind only the interfaces it is listening on,
#bind-interfaces
# that these two Ethernet interfaces will never be in use at the same
# Always give the InfiniBand interface with hardware address
"Once Valet is installed, try pinging any *.test domain on your terminal using a command such as ping foobar.test. If Valet is installed correctly you should see this domain responding on 127.0.0.1."
$ valet domain
indeed is test
? It's configurable. There might be some older config residing in ~/.config/valet
valet domain
it returns 'test'. ~/Code/
what this does is then sets every folder inside that one as a domain, so ~/Code/myproject
becomes accessible at myproject.test there's some info here for you to take a look at. cd /Users/urbycoz/development/php-valet
then valet park
valet restart
or restarting your computer, something may have just gone a bit skew-iff. valet restart
but still the same. Dnsmasq can break when you have a VPN active.
Make sure that at the bottom of your dnsmasq.conf
has the following line pointing to your Valet config:
conf-file=/Users/urbycoz/.config/valet/dnsmasq.conf
/usr/local/etc/dnsmasq.conf
, but not in /Users/urbycoz/.config/valet/dnsmasq.conf
/Users/urbycoz/.config/valet/dnsmasq.conf
? address=/.test/127.0.0.1 listen-address=127.0.0.1
Please verify that you have a /etc/resolver/test
file containing this row: nameserver 127.0.0.1
Also, edit your /usr/local/etc/dnsmasq.conf
file by uncommenting and changing this line:
#interface=
to this:
interface=lo0
Then restart the service again with sudo brew services restart dnsmasq
and try again.
The idea is that during the installation the dnsmasq
daemon might have got bound to some interface which is not available anymore.
By changing it to lo0
you would force it to only serve your loopback interface which is always present. And I guess you won't need it operating on any of your external-facing interfaces as I guess that's all for development purposes. Yet if you do, you could add more interface rows like this:
interface=lo0
interface=en0
ps aux | grep dnsmasq
you should have a line looking like this: usr/local/opt/dnsmasq/sbin/dnsmasq --keep-in-foreground -C /usr/local/etc/dnsmasq.conf
We're interested in the config file path in this line (in my case that's /usr/local/etc/dnsmasq.conf
). Then do cat /usr/local/etc/dnsmasq.conf | grep "conf-file"
and please provide the output. ps aux | grep dnsmasq
. All I see is 1 line saying urbycoz 1394 0.0 0.0 4267932 344 s000 R+ 11:32am 0:00.00 grep dnsmasq
cat /usr/local/etc/dnsmasq.conf | grep "conf-file"
: #conf-file=/etc/dnsmasq.more.conf conf-file=/Users/urbycoz/.config/valet/dnsmasq.conf
dnsmasq
proccess via ps aux | grep dnsmasq
. Could give us the output of sudo brew services restart --verbose dnsmasq
sudo lsof -i:53 -P -n
and also cat /var/log/system.log | grep -i dnsmasq
sudo lsof -i:53 -P -n
is nothing. When I run /var/log/system.log | grep -i dnsmasq
I get: May 24 10:16:11 Urbycozs-MacBook-Pro com.apple.xpc.launchd[1] (homebrew.mxcl.dnsmasq[18157]): Service exited with abnormal code: 2 May 24 10:16:11 Urbycozs-MacBook-Pro com.apple.xpc.launchd[1] (homebrew.mxcl.dnsmasq): Service only ran for 0 seconds. Pushing respawn out by 10 seconds
repeated about 50 times. dnsmasq
service seems to not be able to start at all. Try reloading the service like this: sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist && sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
and try again. cat /usr/local/etc/dnsmasq.conf | grep -i interface
. /usr/local/etc/dnsmasq.conf
, please try this and I hope it works. cat /var/log/system.log | grep -i dnsmasq
? Do you still keep getting the ... Service exited with abnormal code: 2 ...
errors, or is there another error message? If you have Forticlient installed, it can break dnsmasq.
The workaround is either:
Add the entries manually to your /etc/hosts
file: 127.0.0.1 localhost dirname1.test dirname2.test
Disable the Forticlient launch daemons/agents by deleting or moving all com.fortinet.forticlient.*
entries in /Library/LaunchDaemons
and /Library/LaunchAgents
, then restart your mac