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
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
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
User contributions licensed under CC BY-SA 3.0