FreeBSD使用DHCP时,如何设置主机名
时间:2019-11-20 08:54:05 来源:igfitidea点击:
FreeBSD在重启后,主机名为空。 如何解决?
如何使用DHCP设置主机名?
dhclient脚本
dhclient会不时调用DHCP客户端网络配置脚本。
DHCP客户端使用此脚本在请求地址之前设置每个接口的初始配置,在提供地址后对其进行测试,并在获取租约后设置接口的最终配置。
修改文件/etc/rc.conf:
hostname=""
创建一个新文件/etc/dhclient-enter-hooks
# vi /etc/dhclient-enter-hooks
内容如下:
#!/bin/sh check_hostname(){ hostname laptop.theitroad.com }
设置权限:
# chmod +x /etc/dhclient-enter-hooks
重启服务器,或者dhcp
# dhclient iface
dhclient.conf文件示例
/etc/dhclient.conf:
timeout 60; retry 60; reboot 10; select-timeout 5; initial-interval 2; interface "ep0" { send host-name "laptop.theitroad.com"; send dhcp-client-identifier 1:0:a0:24:ab:fb:9c; send dhcp-lease-time 3600; supersede domain-name "theitroad.net.in r.theitroad.com r.vsnl.theitroad.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; }