Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: /etc/hosts
PostPosted: Fri Mar 13, 2009 11:58 am 
Offline
Junior Member

Joined: Wed Feb 18, 2009 4:50 pm
Posts: 47
Hi, I want to modify my host so that when I'm sitting at the console it is does not look like:

nsajeff@li61-78:/etc$
I want this instead:
$user@ottawahosts.com

This is my /etc/hosts file


127.0.0.1 localhost
97.107.131.78 ottawahosts.com


Thanks for your help.


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 12:08 pm 
Offline
Junior Member

Joined: Tue Feb 19, 2008 7:08 am
Posts: 23
Location: USA
edit /etc/hostname


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 12:12 pm 
Offline
Junior Member

Joined: Wed Feb 18, 2009 4:50 pm
Posts: 47
Ummm...ya, I posted that. I'm just not sure WHAT to edit.


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 12:32 pm 
Offline
Senior Member
User avatar

Joined: Sat Oct 16, 2004 11:13 am
Posts: 176
Code:
echo "ottawahosts.com" > /etc/hostname
hostname -F /etc/hostname


Then logout and login again.

EDIT: changed cat to echo, obviously ...


Last edited by saman007uk on Fri Mar 13, 2009 6:07 pm, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 12:39 pm 
Offline
Junior Member

Joined: Wed Feb 18, 2009 4:50 pm
Posts: 47
saman007uk wrote:
Code:
cat "ottawahosts.com" > /etc/hostname
hostname -F /etc/hostname


Then logout and login again.


Thanks saman007uk. I'll try that.


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 12:40 pm 
Offline
Junior Member

Joined: Wed Feb 18, 2009 4:50 pm
Posts: 47
nsajeff@li61-78:/etc$ sudo cat "ottawahosts.com" > /etc/hostname
-bash: /etc/hostname: Permission denied
nsajeff@li61-78:/etc$ sudo cat "ottawahosts.com" > /etc/hosts
-bash: /etc/hosts: Permission denied
nsajeff@li61-78:/etc$ hostname -F /etc/hosts
hostname: the specified hostname is invalid
hostname: you must be root to change the host name
nsajeff@li61-78:/etc$ sudo hostname -F /etc/hosts
[sudo] password for nsajeff:
hostname: the specified hostname is invalid
nsajeff@li61-78:/etc$


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 12:53 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Kind of obvious, but you don't seem to have enough permissions! Try
Code:
sudo su -

to become root, and then try again.

Besides, you're doing it wrong. It's /etc/hostname, not /etc/hosts. They're two different files, and the latter has nothing to do with the procedure you're supposed to be following.

On a different note, I don't think it's a good idea to use your main domain as your hostname. It sometimes causes weird issues with Apache which can be hard to troubleshoot. Make up a subdomain or something. (The console will usually only display the first part of it, though. Otherwise your command prompt becomes too long!)


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 1:06 pm 
Offline
Junior Member

Joined: Wed Feb 18, 2009 4:50 pm
Posts: 47
hybinet wrote:
Kind of obvious, but you don't seem to have enough permissions! Try
Code:
sudo su -

to become root, and then try again.

Besides, you're doing it wrong. It's /etc/hostname, not /etc/hosts. They're two different files, and the latter has nothing to do with the procedure you're supposed to be following.

On a different note, I don't think it's a good idea to use your main domain as your hostname. It sometimes causes weird issues with Apache which can be hard to troubleshoot. Make up a subdomain or something. (The console will usually only display the first part of it, though. Otherwise your command prompt becomes too long!)


Clearly it isn't that obvious, I have full root privileges through sudo. I ran those commands as root also and had the same problem. /etc/hostname does not exist on my system.


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 1:17 pm 
Offline
Junior Member

Joined: Wed Feb 18, 2009 4:50 pm
Posts: 47
Thanks for clarifying that its a bad idea though. I'll stick with the linode hostname for now.


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 1:22 pm 
Offline

Joined: Fri Mar 13, 2009 1:19 pm
Posts: 1
nsajeff wrote:
hybinet wrote:
Kind of obvious, but you don't seem to have enough permissions! Try
Code:
sudo su -

to become root, and then try again.

Besides, you're doing it wrong. It's /etc/hostname, not /etc/hosts. They're two different files, and the latter has nothing to do with the procedure you're supposed to be following.

On a different note, I don't think it's a good idea to use your main domain as your hostname. It sometimes causes weird issues with Apache which can be hard to troubleshoot. Make up a subdomain or something. (The console will usually only display the first part of it, though. Otherwise your command prompt becomes too long!)


Clearly it isn't that obvious, I have full root privileges through sudo. I ran those commands as root also and had the same problem. /etc/hostname does not exist on my system.


No, sudo doesn't always work exactly the same as actually being the root user, this is one of those cases. Do a
Code:
sudo su -

and run the command again

edit: Sudo is only sudo-ing the echo command, not the > command.


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 1:54 pm 
Offline
Senior Member

Joined: Fri Dec 07, 2007 1:37 am
Posts: 385
Location: NC, USA
nsajeff wrote:
nsajeff@li61-78:/etc$ sudo cat "ottawahosts.com" > /etc/hostname
-bash: /etc/hostname: Permission denied
nsajeff@li61-78:/etc$ sudo cat "ottawahosts.com" > /etc/hosts
-bash: /etc/hosts: Permission denied
nsajeff@li61-78:/etc$ hostname -F /etc/hosts
hostname: the specified hostname is invalid
hostname: you must be root to change the host name
nsajeff@li61-78:/etc$ sudo hostname -F /etc/hosts
[sudo] password for nsajeff:
hostname: the specified hostname is invalid
nsajeff@li61-78:/etc$

First, the original advice was in error - you wanted to use echo, not cat:
Code:
echo "domain.com" >/etc/hostname


Second, as mentioned already, the sudo command you used didn't affect the redirection so you were trying to write the file as your regular user.

Third, apparently the hostname file lives somewhere else for your system. On gentoo it is /etc/conf.d/hostname - maybe you need to look around to find it on yours.

And lastly, changing config files by blindly overwriting an existing file is a recipie for disaster. IMHO you should fire up a text editor of your choice to make these kinds of changes. As a good example, the gentoo /etc/conf.d/hostname file I mentioned would be quite broken if you replaced it as you were trying to do.[/code]


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 3:49 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
On Debian/Ubuntu, here's how to do it.

Assuming that you want sub.domain.com:

Code:
sudo vi /etc/hosts

Or if you prefer, you can use other editors such as nano.

Put the following line somewhere in the file:
Code:
your.ip.address sub.domain.com sub

Note that there are three entries and two spaces. It is important that the fullly qualified domain name comes first, then just the subdomain part of it. (I said above that /etc/hosts has little to do with what you're trying to do, but if you use a subdomain it's useful to take this step.)

Code:
sudo vi /etc/hostname

Again, replace with your favorite editor.

Replace the entire contents of the file (if any) with:
Code:
sub

That is, just the subdomain part of your hostname. Some tutorials tell you to put the entire domain name there, but in my opinion that's wrong. Others may disagree, though.

Finally, run the following command:
Code:
sudo /etc/init.d/hostname.sh start


Now log out and log back in. You should see the new hostname.


Top
   
 Post subject:
PostPosted: Fri Mar 13, 2009 5:03 pm 
Offline
Junior Member

Joined: Wed Feb 18, 2009 4:50 pm
Posts: 47
Thank you hybinet. That is exactly what I was looking for. It also fixed the pesky problem of telling me it couldn't resolve my host when using sudo.


Top
   
PostPosted: Sun Mar 15, 2009 2:48 pm 
Offline
Newbie

Joined: Sun Mar 15, 2009 7:26 am
Posts: 4
I followed all of the instructions (didn't do that before, if you saw my earlier post), and was able to resolve the problem.

I was even able to get it to work by just specifying the machine name in the "localhost" portion of my /etc/hosts. First line is loopback, second line is external IP.

127.0.0.1 localhost customized_name
44.33.22.11 external.domain.name

doing that, plus putting customized_name in /etc/hostname worked.

Result: command prompt = username@customized_name >


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group