如何在 Ubuntu 14.04 中将 *.localhost 重定向到 127.0.0.1?

Ale*_*rie 7 configuration dns dnsmasq

我曾经是能够做出foo.localhostbar.localhost等等决心127.0.0.1加入

address=/localhost/127.0.0.1
Run Code Online (Sandbox Code Playgroud)

/etc/dnsmasq.conf

dnsmasq.conf在 Ubuntu 14.04 中不存在,仅创建它并添加该行是行不通的。/etc/dnsmasq.d/star-dot-localhost使用该行创建也不起作用。那么如何在 Ubuntu 14.04 中进行通配符 DNS 重定向?

jkt*_*123 6

正如@Danatela 提到的,您需要dnsmasq安装才能使该方法起作用。您可以使用以下apt-cache policy命令检查它是否已安装:

$ apt-cache policy dnsmasq
dnsmasq:
  Installed: (none)
  Candidate: 2.68-1
  Version table:
     2.68-1 0
        500 http://ru.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
Run Code Online (Sandbox Code Playgroud)

使用这些命令来安装它:

sudo apt-get update
sudo apt-get install dnsmasq
Run Code Online (Sandbox Code Playgroud)

或者,您可以编辑/etc/hosts文件并添加以下条目:

127.0.0.1    foo.localhost
127.0.0.1    bar.localhost
Run Code Online (Sandbox Code Playgroud)