Con*_*d B 2 sudo hosts localhost visudo
真是愚蠢的问题,Ubuntu 20,我安装了 apache2,没有太多其他的。我想要sudo visudo /etc/hosts
添加一个别名“dummy.com”域别名作为指向服务器的黑客,仅用于本地测试学习网站,我得到了这个不寻常的结果
>> /etc/hosts: syntax error near line 1 <<<
>>> /etc/hosts: syntax error near line 2 <<<
>>> /etc/hosts: syntax error near line 5 <<<
>>> /etc/hosts: syntax error near line 6 <<<
>>> /etc/hosts: syntax error near line 7 <<<
>>> /etc/hosts: syntax error near line 8 <<<
>>> /etc/hosts: syntax error near line 9 <<<
What now? Q
Run Code Online (Sandbox Code Playgroud)
我删除了该127.0.0.1 localhost notmydomain.com
行,所以现在这是我的文件,为什么每当我编辑它时它都会出现如上所述的语法错误?
conrad@conrad-VirtualBox:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 conrad-VirtualBox
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Run Code Online (Sandbox Code Playgroud)
很困惑,因为当我访问 fakedomain.com 时,浏览器确实可以工作(奇怪的是,即使在我删除了 fakedomain.com 别名并运行后,别名仍然可以在浏览器中工作sudo service network-manager restart
。)我在这上面浪费了很多时间,我要重新-安装,但很想知道我可能哪里出了问题。
Art*_*ild 26
visudo
是一个命令,旨在编辑/etc/sudoers
文件(并且仅编辑该文件),并执行完整性检查以确保文件有效。
如果你给它一个文件作为参数,它会查找另一个sudoers
文件,并检查该语法。由于/etc/hosts
是具有另一种语法的不同文件,因此这会产生错误。
只需/etc/hosts
使用您最喜欢的编辑器进行编辑,如下所示:
sudo vim /etc/hosts
Run Code Online (Sandbox Code Playgroud)
或者您可以使用sudoedit
(或sudo -e
) 命令,其工作方式与运行相同crontab -e
(编辑临时文件,完成后复制到目标):
sudoedit /etc/hosts
Run Code Online (Sandbox Code Playgroud)