DHCP host-name issue

Asked by Bogdan Butnaru

Hi! I have a DHCP problem on my school network, and I'm not sure if the network's misconfigured or if there's something wrong with my DHCP client.

This is on up-to-date Ubuntu Feisty, dhcp3-client's version is 3.0.4-12ubuntu2

I have a network at school (Ethernet) which I connect to using DHCP. I can connect to the network, I receive an IP address, and the network seems to work. However, I can't configure the host-name correctly.

I have the host name set statically in /etc/hostname to "bogdanb-d620", which is my name and my computer. I have tried setting /etc/dhcp3/dhclient.conf to either "send host-name "bogdanb-d620" or "send host-name "<hostname>" or not to send a host name at all. I have also set it (actually, it's set that way by default) to "request host-name" (among other things). I have also tried to "supersede host-name "bogdanb-d620".

Whenever the "supersede" or "request host-name" options is mentioned in the dhclient.conf file, the server (apparently) answers with my ip address. If none of the options supersede or request mentions host-name, the server doesn't send any host-name back.

The problem is that dhclient complains about the ip address given. As far as I can tell, it expects a string instead of an ip. I don't know if that's a bug in the school's server or in my client.

The secondary problem -- which is what irks me -- is that in this situation I get all sorts of weird problems with some apps. In particular, I'm trying to write some network-using application in Java, and I get stupid errors like "InetAddress.getLocalHost()" throwing "UnknownHostException: bogdanb-d620". (I think that's a Java library bug; the method claims to throw UHE only if it can't find an IP address for the host; the host _has_ an IP address, it's just that the _host-name_ doesn't have one.)

So the question is: what can I do about the host-name? Is the server sending me garbage or is my dhclient broken? Can I convince the resolver to return my IP address for my host-name without using the DNS. (I know I can do this with /etc/hosts but I want it to work with the dynamic addresses I get through DHCP.)

And (2), can I get Java to stop being silly without solving (1)?

****************
bogdanb-d620$ sudo dhclient -d
There is already a pid file /var/run/dhclient.pid with pid 12343
removed stale PID file
Internet Systems Consortium DHCP Client V3.0.4
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

Listening on LPF/eth0/00:18:8b:a6:e4:d8
Sending on LPF/eth0/00:18:8b:a6:e4:d8
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
DHCPOFFER from 193.51.25.1
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 193.51.25.1
host-name: garbage in format string: h
host-name: 12 extra bytes
Unexpected format code h
host-name: garbage in format string: h
host-name: 12 extra bytes
Unexpected format code h
bound to 193.51.25.234 -- renewal in 834 seconds.
<Ctrl-C>

bogdanb-d620$ cat /var/lib/dhcp3/dhclient.leases
lease {
  interface "eth0";
  fixed-address 193.51.25.234;
  option subnet-mask 255.255.255.0;
  option routers 193.51.25.254;
  option dhcp-lease-time 1800;
  option dhcp-message-type 5;
  option domain-name-servers 193.51.25.1,193.51.24.1;
  option dhcp-server-identifier 193.51.25.1;
  option broadcast-address 193.51.25.255;
  option host-name 193.51.25.255;
  option domain-name "prism.uvsq.fr";
  renew 4 2007/2/8 10:42:45;
  rebind 4 2007/2/8 10:55:06;
  expire 4 2007/2/8 10:58:51;
}

bogdanb-d620$ sudo dhclient -d
There is already a pid file /var/run/dhclient.pid with pid 12369
removed stale PID file
Internet Systems Consortium DHCP Client V3.0.4
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

/var/lib/dhcp3/dhclient.leases line 11: expecting string.
  option host-name 193.
                   ^
[same output as before follows]

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Ralph Janke
Solved:
Last query:
Last reply:
Revision history for this message
Ralph Janke (txwikinger) said :
#1

The configuration file nsswitch.conf gives you the order in which the ip address is looked up. What is that configuration for host in that file ?

i.e. hosts: files dns

means it will look first in you resolv.conf file, than use dns.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#2

bogdanb@bogdanb-d620:~$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd: compat
group: compat
shadow: compat

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
networks: files

protocols: db files
services: db files
ethers: db files
rpc: db files

netgroup: nis

bogdanb@bogdanb-d620:~$ cat /etc/resolv.conf
search prism.uvsq.fr
nameserver 193.51.25.1
nameserver 193.51.24.1

bogdanb@bogdanb-d620:~$ cat /etc/hosts
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

*****************
I temporarily solved the second problem (confused programs) by adding "193.51.25.234 bogdanb-d620 bogdanb-d620.lan bogdanb-d620.local bogdanb-d620.prism.uvsq.fr" to my etc/hosts file, but I'm not satisfied with that because it won't change automatically when I change the IP address. And I still think I'll have issues when I'll run the program through the network.

Revision history for this message
Ralph Janke (txwikinger) said :
#3

Do you need the ip for your host being an external address? Or can you use 127.0.0.1 instead for your hostname in resolv.conf?

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#4

First, I need that my host name ("bogdanb-d620") be resolved by all programs on my machine to my DHCP-given IP address.

Second, I want to know if the DHCP server is correct in returning me my IP address _as_my_hostname_.

Depending on the second answer, I'm curious if it is possible either (1) to have no host-name, or (2) to have an IP as the host-name, or (3) to dynamically change the host-name to what the DHCP server assigns me.

I'm not bothered that much by dhclient complaining. The main problem is that lots of Java methods (like "getLocalHost" or "Socket.getLocalAddress") tend to fail miserably when the host-name is linked by the network's DNS with the IP. As far as I can tell, they try to get the local host name and then resolve it.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#5

I was a bit unclear there. I meant the network's DNS server does _not_ associate my host name with the IP I get from DHCP. And this means that applications that try to resolve my host-name ("bogdanb-d620") fail with an error.

Revision history for this message
Ralph Janke (txwikinger) said :
#6

Are those applications running on the same host, or on other hosts?

In the second case, you need to have a dynamic upgrade of your dns server.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#7

The applications that I'm concerned about are running on the same machine. To those on other hosts I send IP addresses only, and as far as I can tell it works correctly.

Revision history for this message
Ralph Janke (txwikinger) said :
#8

The applications on your host should be happy with the 127.0.0.1 address. Otherwise maybe the package dhcp-dns can help you with the dynamic entries into your dns server. However, this only works if your dns server allows such upgrade-records and is configured to accept them from your dhcp server.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#9

Thing is, the local application needs to send the machine's IP to another app on another host. So it tries to do "getLocalHost" or "getLocalAddress" to find out the local machine's IP; it receives an InetAddress, and it sends the IP it extracts from that address to the remote application.

None of the two apps _need_ to resolve the host-name. They're both very happy to deal with the IP. However, for some weird reason, Java's standard library (and, perhaps, others) try to find out the local machine's IP by _resolving its host-name_. (And they fail.) I don't know if that's normal or not, but that's what they do, and I need a way of making that resolve operation work.

I can't change the app to try to find out the local machine's external IP by some other means, either.

Revision history for this message
Ralph Janke (txwikinger) said :
#10

Can you send dynamic updates to the dns server and achive the name-resolution that way ?

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#11

I don't know how to do that. I'm wary of annoying the network manager, but I can try if there's a standard method to do that. I looked around a bit and I can't find any docs on that subject except for Windows. Can you point me to something?

Revision history for this message
Ralph Janke (txwikinger) said :
#12

dhcp3 has an option to send requests to the dns server... otherwise there is an application called dhcp-dns.

However, the DNS server must accept those request. Is it running on Windows or Linux ?

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#13

I _think_ it's running some kind of Unix, probably Linux. It doesn't accept my requests -- presumably it wants (as it's normal) authentication. I sent a mail to the admin, perhaps he'll help me.

But I'm still curious: is there no quick way of convincing the system to always resolve the currently-set host-name to one of the existing addresses, without using DNS, and without me hacking the DHCP scripts to rebuild the /etc/hosts files every time my IP changes?

Revision history for this message
Best Ralph Janke (txwikinger) said :
#14

I think you have a couple of different ways, it might work. Don't know how clean or messy you will find them.

1) you could write a script that replaces that ip address in the resolv.conf file. It probably should be called by /etc/networking/if-up. It needs to run after dhclient has received the ip address. You can retrieve it by using either ifconfig or ip. However, as I understand your descriptions above, that might not work with every function that looks for the ip-addresse, since not all use nsswitch.conf, I remember there are differences.

2) You could run a dns server of this host, and run it in it own domain. Certainly you need to configure it that it forwards request outside this domain to the usual dns server. It also assumes you do not do any dns-lookups about this host from other machines, which I think do not happen from the discussion above. This would then allow correct lookups for the function if it uses dns as default.

I think both solutions are a little messy, but in your situation and used in a limited way, it might work.

I hope you are lucky with one of them. I am not sure I have any other idea for your particular situation, but maybe I don't understand all the details yet.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#15

User confirmed that the request is solved.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#16

Yes, I think that's about it. Thanks for all the info!