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

我曾经能够通过添加使foo.localhostbar.localhost等解析为127.0.0.1

 address=/localhost/127.0.0.1 

/etc/dnsmasq.conf

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

正如@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 

使用以下命令安装它:

 sudo apt-get update sudo apt-get install dnsmasq 

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

 127.0.0.1 foo.localhost 127.0.0.1 bar.localhost