LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-08-2004, 08:42 PM   #1
madangsweh
Member
 
Registered: Jul 2003
Posts: 32

Rep: Reputation: 15
Unhappy Basic question on hostname under DHCP


I always had this question. Is there anybody can answer?
------------------------------------------------------------------------------------------------
Under DHCP, the hostname is set to localhost during Linux installation. This is true for /etc/hosts and /etc/sysconfig/network under Redhat installation. The IP address will set by DHCP server that could be either DHCP server or router. If I would like to set a name for the computer, say "MyCom", then how can I do that? The /etc/hosts file is requires IP address to set but it comes from DHCP server. The network file can be modified to reflect the new hostname for the computer, but it genereate an error during boot process. The error asks to change /etc/hosts to add the name, but the IP address can't be set under DHCP.

Any clue for this??
 
Old 12-08-2004, 09:53 PM   #2
bdogg
Member
 
Registered: Sep 2004
Location: Salt Lake City, UT
Distribution: Debian Sarge
Posts: 93

Rep: Reputation: 15
as root:

# hostname MyComp (or whatever you wanted)

Should do the trick.

Be aware: a FEW (and I do mean very few) dhcp servers only assign addresses to hostnames that it recognizes. If you can't get an ip after you change your hostname, it probably shouldn't be changed. Though, I don't see this happening in your case as you get an ip address with the hostname localhost, which, if I were running a dhcp server that authenticated by hostname, would be one of the first blacklisted.

You also might need to log out and log back in to notice the effect in your bash prompt and such.

Last edited by bdogg; 12-08-2004 at 09:55 PM.
 
Old 12-08-2004, 10:56 PM   #3
madangsweh
Member
 
Registered: Jul 2003
Posts: 32

Original Poster
Rep: Reputation: 15
Hello, bdogg

I did as what you suggested. After the change, however, when I login to the computer, it gets an error!! That is what I described in my previous message.
The error is :
"Could not look up internet address for MYHOSTNAME. This could prevent GNOME from operating correctly. It may be possible to correct the problem by adding MYHOSTNAME to the file /etc/hosts".

Here I have a problem! Because with DHCP I can't assign IP address to the hostname that is required in /etc/hosts.

Any help is appreciated!
 
Old 12-09-2004, 08:47 AM   #4
bdogg
Member
 
Registered: Sep 2004
Location: Salt Lake City, UT
Distribution: Debian Sarge
Posts: 93

Rep: Reputation: 15
I am having a little trouble understanding your situation. It's good to inlude exact error messages, thanks for that.

Quote:
Because with DHCP I can't assign IP address to the hostname that is required in /etc/hosts.
Why can't it? Is it because you have configured your DHCP server (or your ISP has) so that it will block connections from that host?

Why is the hostname you are seeking "required" in /etc/hosts?


Step 1:
Your /etc/hosts file should read like this

127.0.0.1 localhost.localdomain localhost (HOSTNAME U WANT)

And then any other IPv6 or IPv4 hosts you want to note.

Step 2:
Remember the last half of my first post? When a DHCP server tells you that it can't assign an ip to the hostname you have chosen, it's something with the DHCP server that needs fixing.

AS WELL, GNOME looking up your hostname is different from a DHCP server giving you an IP.

Step 3:
You could also check /etc/hostname and put your hostname there.

Then you could go to /etc/hosts and add a line like so

127.0.0.1 (HOSTNAME U WANT)

That would fall right under your first line that reads ... localhost.localdomain ... etc
 
Old 12-09-2004, 11:44 AM   #5
madangsweh
Member
 
Registered: Jul 2003
Posts: 32

Original Poster
Rep: Reputation: 15
Hello, Bdogg

First of all, thank you for your help on this. No matter what I get at the end of this discussion, I am sure I will learn a lot on Linux. Thank you for it.
----------------------------------------------------------------------------------------------------------------------------------------------------------
>>Why can't it? Is it because you have configured your DHCP server (or your ISP has) so that it will block connections from that host?

Ans: The host I am talking about is my machine. I have a home network with DSL and a router. As far as my knowledge goes, the router governs the IP address, so that it is not ncessary to set the IP address in /etc/hosts file. If I set it up, DOES DHCP OVERWRITES IT? I found that this computer always gets 192.168.2.7 ( I have 4 computers on the network ), should I change the /etc/hosts as follows?

127.0.0.1 localhost.localdomain localhost (this is for loopback)
192.168.2.8 MYHOST

or just
127.0.0.1 localhost.localdomain MYHOST

>>Why is the hostname you are seeking "required" in /etc/hosts?

Ans: Because GNOME yells at the login process as I mentioned in the message. If there is no error, then I would just leave this file without any change.
 
Old 12-09-2004, 02:55 PM   #6
bdogg
Member
 
Registered: Sep 2004
Location: Salt Lake City, UT
Distribution: Debian Sarge
Posts: 93

Rep: Reputation: 15
if your computer always gets 192.168.2.7 then do it like this

127.0.0.1 localhost.localdomain localhost MYHOST
192.168.2.7 MYHOST

Try putting those two lines in your /etc/hosts file.
 
Old 12-09-2004, 04:55 PM   #7
madangsweh
Member
 
Registered: Jul 2003
Posts: 32

Original Poster
Rep: Reputation: 15
There are many files regarding hostname setup in Linux.

/etc/hosts
/etc/sysconfig/network
/etc/sysconfig/networking/devices/ifcfg-eth0
/etc/sysconfig/networking/profile/... (4 files are there)
/etc/sysconfig/network-scripts/ifcfg-eth0

Do you know each one and what use for??

I will change hosts file with hard number but that what I was confused with DHCP becuase it supposed to get the IP from the server...

Thanks..
 
  


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
dhcp hostname ahz10 Linux - Networking 1 05-06-2005 03:40 PM
Get hostname from DHCP microft Linux - Networking 2 07-18-2004 03:31 PM
Basic DNS/DHCP question sporkfish Linux - Networking 5 07-14-2004 07:30 PM
dhcp hostname .... phoeniXflame Linux - Networking 6 12-07-2003 11:12 AM
Basic DHCP Question bfloeagle Linux - Networking 3 08-23-2000 07:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:02 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