Solved

How do I edit the Hosts file on Ubuntu 10.10?

Posted on 2011-02-15
8
1,342 Views
Last Modified: 2012-06-27
I cannot edit the Hosts file on my Ubuntu 10.10 install. I have tried using the following commands:

sudo gedit \etc\hosts
sudo nano \etc\hosts
sudo vi \etc\hosts

None have worked. Althought the Vi editor MAY work, I am having difficulty doing so. What would I need to do to get Gedit to work on the Hosts file?
0
Comment
Question by:CCB-Tech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Assisted Solution

by:abbright
abbright earned 50 total points
ID: 34897873
Pathnames in Linux are written using "/" not "\", so try using
sudo gedit /etc/hosts
sudo nano /etc/hosts
sudo vi /etc/hosts
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 50 total points
ID: 34897903
Hi,

first of all, don't use backslashes ( \ )! Use the normal slashes ( / ) as directory separators.

gedit is the default editor in Ubuntu.
Should it be missing nevertheless install it with:

apt-get gedit

Here is a vi tutorial:
http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html
http://www.unix-manuals.com/tutorials/vi/vi-in-10-2.html

wmp
0
 
LVL 35

Expert Comment

by:torimar
ID: 34898327
>> "What would I need to do to get Gedit to work on the Hosts file?"

Apart from the slashes which you put wrongly and which have already been addressed, if you really want to use Gedit, which is a graphical Gnome application, you should launch it via the graphical sudo command 'gksudo', i.e.:

# gksudo gedit /etc/hosts

See this as reference: https://help.ubuntu.com/community/RootSudo#Graphical sudo

'nano' doesn't require any additional thought, and also is much simpler to use than vi, so I'd always recommend to use 'nano'.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 35

Expert Comment

by:torimar
ID: 34898341
0
 

Author Comment

by:CCB-Tech
ID: 34899091
LOL, yikes I knew I would get the slashes wrong. I posted this question in a hurry before a meeting. I had been running the commands with the correct slashes. And gedit is installed and running fine. The problem I had was that no matter what I've tried I am not able to save my changes. I just tried using gksudo and sudo and neither worked. It prompts for the root password and then runs fine. When I bring up gedit the save options are all greyed out. Leading me to think something is amiss with the permissions. Although I just tried Nano again and it seems to be working. Any idea WTF might have caused this to prevent gedit from working? Nano is fine but gedit is simpler.

Thanks for all the quick responses!
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34899250
Maybe you forgot sudo sometimes?

And sudo does not prompt for root's password, it prompts for your (the user's) password!

wmp
0
 
LVL 35

Accepted Solution

by:
torimar earned 150 total points
ID: 34899397
There are several reports about Gedit sometimes behaving strangely when saving, whereas other editors, graphical ones included, are fine.

Most of the time this has turned out to have to do with the fact that Gedit creates a temporary copy of the edited file which is later saved to disk as a backup.
Try this:
In Gedit, go Edit > Preferences > Editor, and look for "Create a backup copy of files before saving".
If it is checked, uncheck; if it is unchecked, check.
Then try editing and saving again.
0
 

Author Closing Comment

by:CCB-Tech
ID: 34900692
I did try what you mentioned about the backup file. It was unchecked. I checked it, closed gedit, and re-opened it to verify that it stuck. Then I ran the gksudo command to edit the file. No joy :(. Oh well. I tried nedit as an alternative since you mentioned that gedit sometimes has issues. Worked a treat! Thanks for everyones help!
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question