LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 02-16-2017, 10:08 PM   #1
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Rep: Reputation: 73
edit hosts


I need to edit /etc/hosts on this machine.

I do this on Ubuntu by

sudo gedit

then open /etc/hosts

On this computer with Fedora,

Quote:
[root@localhost pedro]# uname -a
Linux localhost.localdomain 4.8.15-300.fc25.x86_64 #1 SMP Thu Dec 15 23:10:23 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost pedro]#

that does not work. I have an editor called Pluma. When I try to call it, I get:

Quote:
[root@localhost pedro]# pluma
No protocol specified
Unable to init server: Could not connect: Connection refused

(pluma:2217): Gtk-WARNING **: cannot open display: :0
[root@localhost pedro]#
How can I open hosts to edit in this Fedora 25? I don't know how to use vi. It is too cryptic for me.
 
Old 02-16-2017, 10:35 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
If you have sudo, you should never launch a graphical program with it directly. Among other things, there can be left over files, including the editor's own local configurations, that end up being owned by root. Instead, the best, and safest, way is to use sudoedit. For example:

Code:
sudoedit /etc/hosts
That will launch the editor of your choice, be it graphical or normal, and edit a copy of the file as an unprivileged user. When you quit+save, it will then replace the original file with the edited copy. Less can go wrong that way.

About editors that are easier than vi, does Fedora have nano available?

In the long run, it will pay to learn at least a little about vi, because vi is required on all systems and thus ubiquitous. Though its commands are terse, it is very powerful and works very, very well with configuration files. I prefer other editors for other tasks but for shell scripts and configuration files, I find I've become a big vi fan because it lets me do the most with the least work for both types. My favorite, 'cw', allows me to replace a whole word at once.
 
Old 02-16-2017, 11:01 PM   #3
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
Thanks, that's something new I've learnt!

The Fedora machine is at work. Here I have Ubuntu. When I entered the command:

sudoedit /etc/hosts

it came up with nano. When I get back to the office I'll try it there, see what Fedora does. Thanks a lot and thanks for the link to vi tutorials, I will try to get the hang of it!
 
Old 02-17-2017, 01:07 PM   #4
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
You might have leafpad or mousepad installed in F25, either of which can edit your hosts file easily. Or use the command line editors like vi, vim, nano, etc.
 
Old 02-17-2017, 09:16 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
I don't believe Fedora configures sudo out of the box. The sudo fetish is a *buntu thing. Non-*buntu distros do not share it.

Try su - to become root (you will need root's password to do this), then use nano or vim to edit /etc/hosts. If you want to use nano, you may find that you need to install it.

Last edited by frankbell; 02-17-2017 at 09:17 PM.
 
Old 02-18-2017, 11:16 PM   #6
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
I haven't had time to learn vi yet. I installed nano. Please tell me Mr Bell, as it was you that gave me the tip to block sites via hosts, how to call it with sudoedit! Thanks, and sorry I am so useless at computer things!
 
Old 02-19-2017, 01:20 AM   #7
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Hi! #1, make a 'backup' copy of hosts FIRST!
(there's a HIGH chance of 'breaking' this *critical* system file, using a NEW-to-you editor!)
This has to be done as root/su/sudo/UID=0/superuser/whateverYOUcallIT!
I'd recommend first (so you don't have to keep typing /etc/...): cd /etc
cp -p hosts hosts.prior

BUT... I'd suggest a test/'dry'/trial-run, *as you* (not root/su...), in your home directory:
pwd;id #(just to see where&who 'you are')
cp /etc/hosts mytry
edit mytry
...experiment with nano: make the change(s) you want (this won't affect /etc/hosts!)
cat mytry
...did it work ok? IF not, just start over: rm mytry

I'm not sure how to run nano on Fedora: maybe nano (instead of edit)
There are commands like: apropos/man -k/whatis edit (or nano)
There also may be an 'env' variable: echo $EDITOR
http://www.tecmint.com/linux-command-line-editors
(you mightprobably even need to -install- nano! sudo yum install nano
or maybe use an editor listed here, even GUI!)

Best wishes! (take it slow&careful!) p.s hope you enjoy learning: I do!

Last edited by Jjanel; 02-19-2017 at 02:05 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to edit the HOSTS file? dmu Linux - Networking 3 01-29-2006 09:51 AM
edit /etc/hosts ninapratt Linux - Newbie 15 09-19-2005 01:49 PM
Is there an easier way to edit /etc/hosts? n3rds3x Linux - General 4 05-05-2005 05:42 AM
Cannot edit hosts file k3nn0n Fedora 3 05-26-2004 11:00 AM
error on start up---edit /etc/hosts emacin777 Linux - Networking 1 09-03-2003 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 10:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration