Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-27-2008, 02:48 AM   #1
LQ Newbie
Registered: Nov 2008
Posts: 5

Rep: Reputation: 0
How to edit host file in Linux

Hi All,

Iam bala and im interested in linux OS. can some one please help me how to edit the host file in linux.

Thanks in advance,
Old 11-27-2008, 03:00 AM   #2
Registered: Aug 2006
Location: Vancouver, BC, Canada
Distribution: Slackware, Bodhi, Mepis, AntiX, Mint
Posts: 172

Rep: Reputation: 21
Are you talking about the /etc/hosts file?
If so, then you will need to log in as root (or the equivalent) in order to edit it.
Do ls -l /etc/hosts to see who can write to the file (usually root only)!
Old 11-27-2008, 03:02 AM   #3
Registered: Nov 2008
Posts: 180

Rep: Reputation: 36
Are you asking how to edit a text file in Linux? Have you booted up and logged in already? If so, then you can use any text editor to edit the file and save it. You can usually find the text editors from the menu options or you can enter in a shell command to start an editor from a terminal window such as "vi", "emacs", "pico", "nano", "kate", "gedit", etc. Many of these have documentation on the internet, and some have man pages as well. From a command line in the shell, type "man vi" to read about that editor, or "man nano" to read about that, etc. For opening the file to edit it: "nano <filename>".
Old 11-27-2008, 03:06 AM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.7, Centos 5.10
Posts: 16,916

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
... and take a copy first in case you make a mistake in the editor.
Old 11-27-2008, 09:24 AM   #5
LQ Newbie
Registered: Nov 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thank You all... Yes iam talking about /etc/host file only..

Thank You
Old 11-27-2008, 11:36 AM   #6
Senior Member
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,096

Rep: Reputation: 102Reputation: 102
depends on what you want to use. But as root you can use pico, emacs or vim. I am a vim fan so you just type
vim /etc/hosts
Just choose you editor of choice and open the file as root.
Old 11-27-2008, 11:41 AM   #7
Registered: Nov 2008
Location: وادی ھنزہ
Distribution: Solaris 5.10, Debian Server 5.2, CentOS 5.6
Posts: 226
Blog Entries: 3

Rep: Reputation: 38
vim /etc/hosts

and then when you are done with editing ...

hit escape button for two times

and the type


to save and exit!!



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 a HTML file in linux shaiful Linux - Newbie 11 11-24-2008 01:36 PM
how to edit remote file on linux ? kapilbajpai88 Linux - Newbie 5 09-05-2008 10:54 AM
help to edit Edit my bootloader's config file from kernel prompt jagdishpandey Linux - Kernel 5 07-03-2007 07:59 AM
How to edit /boot/grub/menu.lst of the host satimis Linux From Scratch 1 09-25-2005 08:21 AM
Startup file on debian linux x86_64, looking to edit Wolvenmoon Linux - Software 1 08-19-2005 10:29 AM

All times are GMT -5. The time now is 06:56 PM.

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