`sudo visudo /etc/hosts` gives syntax errors
Really dumb question, Ubuntu 20, and I have apache2 installed, not much else.
I go sudo visudo /etc/hosts and want to add an alias "dummy.com" domain alias as a hack to point to the server for local only testing a learning site and I get this unusual
>> /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? QI removed the 127.0.0.1 localhost notmydomain.com line , so this is my file now, why does it have such syntax errors as above whenever I edit it?
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-allroutersConfused because the browser does work when I visit fakedomain.com (curiously the alias still carries on working in browser even after I removed the fakedomain.com alias and ran sudo service network-manager restart.) I've wasted so much time on this I'm going to re-install, but would love to know where I might have gone wrong.
1 Answer
visudo is a command designed to edit the /etc/sudoers file (and only that file), and perform an integrity check that ensures the file is valid.
If you give it a file as an argument, it will look for another sudoers file, and check that syntax. Since /etc/hosts is a different file with another syntax, this gives errors.
Just edit /etc/hosts with your favorite editor, like this:
sudo vim /etc/hostsOr you can use the sudoedit (or sudo -e) command, which works the same way as running crontab -e (where you edit a temporary file that are copied to the destination when you're done):
sudoedit /etc/hosts 7