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/hosts
Or 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