为laravel安装了Valet,但是为什么dnsmasq解析不正确?

nwnhqdif  于 2023-01-14  发布在  其他
关注(0)|答案(4)|浏览(133)

我已经在我的Mac(Mojave)上安装了使用自制软件的laravel的代客服务。根据laravel的文档,我现在应该可以ping *. test,但是当我不断得到以下错误:
ping:无法解析foobar。测试:未知主机
这看起来像是dnsmasq的问题。我已经遵循了所有的建议here,但似乎没有任何帮助。

# Content of '/Users/<username>/.config/valet/dnsmasq.conf'

address=/.test/127.0.0.1
listen-address=127.0.0.1

我可以看到. test的解析器似乎设置良好。下面是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)

我还可以看到dnsmasq似乎运行正常。下面是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

我尝试过的其他方法:

  • 禁用我的防火墙以防它阻止请求。
  • 重新启动dnsmasq(多次),使用:sudo brew services restart dnsmasq
  • 使用valet install重新安装专用服务器
  • 检查/etc/hosts中是否存在冲突路径

有人有其他建议吗?
编辑: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)

编辑2:
我想我现在有进展了。我在www.example.com上查看了dnsmasq,我看到了错误信息: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
......这导致了here。原来我在cd /usr/local/var/run/中丢失了dnsmasq文件夹,所以我运行了sudo mkdir dnsmasq,现在ping实际上返回了以下响应:

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
...

我不知道这意味着什么,也不知道它现在是否有效。
当我在浏览器中进入foobar.test时,我得到消息This site can’t be reached,即使我已经用这个名称创建了一个项目,并使用valet link foobar链接它。
编辑3:
我现在关闭了隐形模式(如here所述),ping工作正常,但当我在浏览器中导航到foobar.test时,仍然得到This site can’t be reached
运行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

编辑4
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
0x6upsns

0x6upsns1#

Dnsmasq可以打破当你有一个VPN活动。

mzillmmw

mzillmmw2#

请验证是否有包含此行的/etc/resolver/test文件:nameserver 127.0.0.1
此外,通过取消注解并更改以下行来编辑/usr/local/etc/dnsmasq.conf文件:

#interface=

改为:

interface=lo0

然后使用sudo brew services restart dnsmasq重新启动该服务并重试。
这个想法是,在安装过程中,dnsmasq守护进程可能已经绑定到一些不再可用的接口。通过将其更改为lo0,您将强制它只服务于始终存在的环回接口。我猜您不需要它在任何面向外部的接口上运行,因为我猜这都是出于开发目的。然而,如果您这样做,您可以添加更多接口行,如下所示:

interface=lo0
interface=en0
i34xakig

i34xakig3#

确保在dnsmasq.conf的底部有指向您的Valet配置的以下行:

conf-file=/Users/urbycoz/.config/valet/dnsmasq.conf
iyfjxgzm

iyfjxgzm4#

如果您安装了Forticlient,它可能会破坏dnsmasq。
解决方法是:

  • 将条目手动添加到/etc/hosts文件中:127.0.0.1 localhost dirname1.test dirname2.test
  • 通过删除或移动/Library/LaunchDaemons/Library/LaunchAgents中的所有com.fortinet.forticlient.*条目禁用Forticlient启动守护程序/代理,然后重新启动Mac

相关问题