Monday, April 30, 2012

FreeBSD DHCP Set Hostname ( Empty Hostname After Reboot )

I’m using FreeBSD 7.2 on HP laptop and getting IP info via WI-FI router. I’ve setup hostname in /etc/rc.conf buy after the boot process, I check host name with "hostname" command, but get empty line. Setting hostname with "hostname" works well, but after reboot host name is still empty. I suspect it has something to do with DHCP settings. How do I set hostname-using DHCP?

Dynamic Host Configuration Protocol (DHCP) is a network application protocol used by devices (DHCP clients) to obtain configuration information for operation in an Internet Protocol network. The dhclient utility provides a means for configuring network interfaces using DHCP, BOOTP, or if these protocols fail, by statically assigning an address.
This problem indicate that your DHCP server isn't sending the hostname back at all. To solve this problem configure your dhcp server to send back hostname or configure dhcp client to set hostname on your laptop itself.

Say Hello To dhclient-script

From the man page:
The DHCP client network configuration script is invoked from time to timeby dhclient. This script is used by the DHCP client to set each interface's initial configuration prior to requesting an address, to test the address once it has been offered, and to set the interface's final configuration once a lease has been acquired. If no lease is acquired, the script is used to test predefined leases, if any, and also called once if no valid lease can be identified.
Update your /etc/rc.conf as follows:
hostname=""
Create a file called /etc/dhclient-enter-hooks using a text editor:
# vi /etc/dhclient-enter-hooks
Append the following code:
#!/bin/sh
check_hostname(){
hostname laptop.nixcraft.in
}
Save and close the file. Set permission:
# chmod +x /etc/dhclient-enter-hooks
You can now reboot the laptop or just request dhcp lease:
# dhclient iface

Sample dhclient.conf

Here is sample /etc/dhclient.conf file for dhcp client:
timeout 60;
retry 60;
reboot 10;
select-timeout 5;
initial-interval 2;
interface "ep0" {
send host-name "laptop.nixcraft.in";
send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
send dhcp-lease-time 3600;
supersede domain-name "nixcraft.net.in r.nixcraft.com r.vsnl.nixcraft.net.in";
prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, host-name;
require subnet-mask, domain-name-servers;
script "/etc/dhclient-script";
media "media 10baseT/UTP", "media 10base2/BNC";
}
alias {
interface "ep0";
fixed-address 192.5.5.213;
option subnet-mask 255.255.255.255;
}
See dhclient, dhclient.conf and dhclient-script man page for more information.

No comments:

Post a Comment