LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-01-2006, 09:33 PM   #1
hutyerah
Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 41

Rep: Reputation: 20
Hosts file entry with DHCP


I've got my pc set up for DHCP from my cable router. For some reason though, the slackware net scripts assign the loopback IP to my hostname in /etc/hosts, despite the hosts file actually saying that it causes problems. Lo and behold, it causes me problems, with a certain Java API call to get the local IP that always returns the local LAN address on any other OS.

The IP that I normally get from the router is 192.168.0.33, and that's what should be assigned to my hostname in /etc/hosts. I could set up a script to edit it every time I get an IP, but that really shouldn't be necessary. Solution anyone?

/etc/hosts (snipped a bit)
Code:
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1               localhost
127.0.0.1               mulbox.bigpond.net.au mulbox
/etc/rc.d/rc.inet1 (relevant part)
Code:
# Config information for eth0:
IPADDR[0]=""
NETMASK[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME[0]="mulbox"
 
Old 02-02-2006, 01:22 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
I'd suggest to leave out the "127.0.0.1 mulbox.bigpond.net.au mulbox" from /etc/hosts, for the reasons stated in the remarks at the top of that file.
 
Old 02-02-2006, 06:59 AM   #3
hutyerah
Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 41

Original Poster
Rep: Reputation: 20
If I remove the line, it causes more problems than it solves, because then programs can't lookup my hostname in the hosts file. If I change the address to the address I normally get from DHCP, everything works fine, but that's obviously not a solution because DHCP is supposed to be dynamic, changeable, yada yada. What I think should really happen is I add some lines to rc.inet1 that place the correct entry in the hosts file. But shouldn't that be a part of the slackware distro to begin with, and I need to file some kind of bug report? Or is there some plain solution that I'm too n00b to see?
 
Old 02-02-2006, 09:13 AM   #4
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
I am convinced that you should leave out this line to start with. It is an improper solution and you need to solve the problem correctly. I have never added this type of line in my hosts file and I have always managed to get an IP from the dhcpd.

Which program do you use which looks up the hostname this way?
 
Old 02-02-2006, 11:18 PM   #5
hutyerah
Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 41

Original Poster
Rep: Reputation: 20
I didn't add the line, it was present after I installed slackware. I know that programs should use a better technique to find out the local IP. The program that I'm using is Mercury, a Java-based MSN messenger client; and in fact it uses a simple Java API call to get the local IP, so it's many Java-based programs that may have this problem. There are other ways to do so within Java, and I'm trying to get the author to use one of these methods to solve the problem. However, the fact that it was wrong to begin with without my intervention is something that needs to be fixed, no?
 
Old 02-03-2006, 05:30 PM   #6
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
This is how my /etc/hosts looks on a fresh 10.2 install with static IP:
Code:
#
# hosts		This file describes a number of hostname-to-address
#		mappings for the TCP/IP subsystem.  It is mostly
#		used at boot time, when no name servers are running.
#		On small systems, this file can be used instead of a
#		"named" name server.  Just add the names, addresses
#		and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1		localhost
192.168.1.13		slackb102.internal.pu slackb102

# End of hosts.
This makes me believe that during installation you actually entered 127.0.0.1 as your static IP address. Is that possible?
 
Old 02-04-2006, 12:47 AM   #7
hutyerah
Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 41

Original Poster
Rep: Reputation: 20
Nope, definitely not possible. I had the line removed from /etc/hosts as you suggested and I just tried the netconfig script again. Lo and behold, the line reappeared.
Line 158 (part of write_config_files) puts the line in there, correct in your case but not in mine:
Code:
$IPADDR         $HOSTNM.$DOMAIN $HOSTNM
In the case of DHCP though, IPADDR stays as the default of 127.0.0.1 from line 263 (the main code section):
Code:
IPADDR=127.0.0.1
I'm not a script fiend so I don't really know how to fix it, or even what to do to fix it :P
 
Old 02-04-2006, 04:13 AM   #8
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
You're right. I reconfigured my machine with DHCP and got the same line in my /etc/hosts. I commented it out again, and `hostname` is still giving the correct hostname despite the line now missing from /etc/hosts, even after a reboot.
So it appears that the line does no harm, and that it's "just" an application problem you are experiencing. The solution being that the application gets the hostname from the `hostname` command or the correspondant API and _not_ from the /etc/hosts file.
 
  


Reply


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
Help me: slowly booting when adding an entry in /etc/hosts jindo Linux - Networking 6 09-29-2005 10:45 AM
/etc/hosts entry? batard Linux - Newbie 5 03-25-2005 01:22 PM
hosts MX entry twistedpair Linux - Networking 1 01-10-2004 03:01 AM
127.0.0.1 Entry in Zone file and /etc/hosts, will this cause probs? mikeyt_333 Linux - Networking 7 12-02-2003 02:51 PM
hosts entry for a lan unit with no dns entry linxtc Linux - Networking 1 10-03-2003 08:05 AM

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

All times are GMT -5. The time now is 03:54 PM.

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