我在 ubuntu 20.04 上,我正在尝试在本地开发 php 项目。我想要的是能够批量虚拟主机本地项目,当我创建项目并将其添加.local
到项目名称时,始终解析为 127.0.0.1。到目前为止我已经尝试过:
禁用并停止
systemd-resolved
。sudo systemctl stop systemd-resolved sudo systemctl disable systemd-resolved
删除符号链接
resolv.conf
sudo rm /etc/resolv.conf
在其中创建了一个新
resolv.conf
文件/etc/
并添加了nameserver 8.8.8.8
已安装
dnsmasq
在
/etc/NetworkManager/NetworkManager.conf
我有以下内容:[main] dns=dnsmasq plugins=ifupdown,keyfile [ifupdown] managed=false [device] wifi.scan-rand-mac-address=no
在
/etc/NetworkManager/dnsmasq.d
我创建了一个local.conf
文件,其中包含:address=/local/127.0.0.1
重新加载网络管理器,但每次我这样做时它都会重置我
resolv.conf
的,127.0.1.1
所以我必须将名称服务器重置为8.8.8.8
.
输出sudo netstat -anlp | grep 53
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 39737/dnsmasq
tcp6 0 0 :::53 :::* LISTEN 39737/dnsmasq
tcp6 0 0 2600:8800:86ac:2::53030 2606:4700::6810:5f4:443 ESTABLISHED 4802/chrome --type=
tcp6 0 0 2600:8800:86ac:2::53936 2a04:fa87:fffe::c00:443 ESTABLISHED 4802/chrome --type=
tcp6 0 0 2600:8800:86ac:2::57530 2600:1f1c:a99:832c::443 ESTABLISHED 4802/chrome --type=
udp 0 0 0.0.0.0:53 0.0.0.0:* 39737/dnsmasq
udp 0 0 224.0.0.251:5353 0.0.0.0:* 4759/chrome
udp 0 0 224.0.0.251:5353 0.0.0.0:* 4802/chrome --type=
udp 0 0 0.0.0.0:5353 0.0.0.0:* 1109/avahi-daemon:
udp6 0 0 :::53 :::* 39737/dnsmasq
udp6 0 0 2600:8800:86ac:2::35397 2607:f8b0:4007:803::443 ESTABLISHED 4802/chrome --type=
udp6 0 0 2600:8800:86ac:2::53965 2607:f8b0:400e:c09::443 ESTABLISHED 4802/chrome --type=
udp6 0 0 :::5353 :::* 1109/avahi-daemon:
udp6 0 0 2600:8800:86ac:2::38534 2607:f8b0:4007:80f::443 ESTABLISHED 4802/chrome --type=
unix 2 [ ACC ] STREAM LISTENING 75311 3037/Xorg @/tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 75312 3037/Xorg /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 40653 1386/mysqld /var/run/mysqld/mysqlx.sock
unix 3 [ ] STREAM CONNECTED 970535 44951/chrome --type
unix 3 [ ] STREAM CONNECTED 21922 531/systemd-udevd
unix 3 [ ] STREAM CONNECTED 805753 2900/pulseaudio /run/user/1000/pulse/native
unix 3 [ ] STREAM CONNECTED 164653 7749/gdm-session-wo
unix 3 [ ] STREAM CONNECTED 970534 4759/chrome
unix 3 [ ] STREAM CONNECTED 84953 3037/Xorg @/tmp/.X11-unix/X0
unix 3 [ ] STREAM CONNECTED 129536 4952/chrome --type=
unix 3 [ ] STREAM CONNECTED 129538 4759/chrome
unix 3 [ ] STREAM CONNECTED 129535 4759/chrome
unix 3 [ ] STREAM CONNECTED 81853 3294/ibus-daemon
unix 3 [ ] STREAM CONNECTED 109534 4073/gnome-terminal
unix 2 [ ] DGRAM 21931 531/systemd-udevd
unix 3 [ ] STREAM CONNECTED 88353 3434/dconf-service
unix 3 [ ] STREAM CONNECTED 129539 4957/chrome --type=
unix 3 [ ] STREAM CONNECTED 129153 1/init /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 83553 3393/ibus-engine-si
unix 3 [ ] DGRAM 21933 531/systemd-udevd
unix 3 [ ] STREAM CONNECTED 97533 3622/evolution-sour
unix 3 [ ] STREAM CONNECTED 89353 3600/gnome-shell-ca
unix 3 [ ] DGRAM 21934 531/systemd-udevd
unix 3 [ ] SEQPACKET CONNECTED 130853 4759/chrome
unix 3 [ ] STREAM CONNECTED 83353 1/init /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 132553 4611/update-notifie
unix 3 [ ] STREAM CONNECTED 39532 1903/rtkit-daemon
unix 3 [ ] STREAM CONNECTED 100532 2906/dbus-daemon /run/user/1000/bus
unix 3 [ ] STREAM CONNECTED 868534 2900/pulseaudio /run/user/1000/pulse/native
unix 3 [ ] STREAM CONNECTED 35395 1456/kerneloops
unix 3 [ ] STREAM CONNECTED 28453 1114/dbus-daemon /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 100653 3660/gsd-media-keys
unix 3 [ ] STREAM CONNECTED 35396 1458/kerneloops
unix 3 [ ] STREAM CONNECTED 93535 3622/evolution-sour
unix 3 [ ] STREAM CONNECTED 708953 4759/chrome
unix 3 [ ] STREAM CONNECTED 100530 2906/dbus-daemon /run/user/1000/bus
unix 3 [ ] STREAM CONNECTED 35394 1421/whoopsie
unix 3 [ ] STREAM CONNECTED 968853 1989/master
根据 Brian Turek 我运行 dnsmasq,然后重新加载 NetoworkManager.service 然后运行ps aux | grep dnsmasq
,这是输出:
nobody 103697 0.0 0.0 14776 4264 ? S 06:12 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/run/NetworkManager/dnsmasq.pid --listen-address=127.0.1.1 --cache-size=0 --clear-on-reload --conf-file=/dev/null --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d
paul 103707 0.0 0.0 9028 676 pts/0 S+ 06:12 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox dnsmasq
我认为 NetworkManager 的行为符合预期。NetworkManager 可能正在启动一个 DNSmasq 实例并将您的机器设置为使用它来解析 DNS 地址(从而更改 /etc/resolv.conf)。
我想你想添加
server=8.8.8.8
到你/etc/NetworkManager/dnsmasq.d/local.conf
的以及no-resolv
. 这应该会导致 DNSmasq 使用 Google 作为您的上游 DNS,并让您的机器使用 DNSmasq 作为本地解析器。要回答这个问题,归功于 Brian Turek。结果我不得不禁用 dnsmasq
sudo systemctl stop dnsmaq.service
然后重新启动 systemd 解析,因为 NetworkManager 正在运行它自己的 dnsmasq 实例。然后要在我的文件夹中获取我的所有本地项目,我/home/projects/www/
必须禁用sites-enabled
在/etc/apache2/sites-enabled
.000.default.conf
正在阻止任何其他网站正确加载。