[root@www network-scripts]# cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.0.12
PREFIX=24
GATEWAY=192.168.0.1
DNS1=202.106.0.20
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=eth0
UUID=488f1bb4-2e85-497c-9caf-80827626cad4
ONBOOT=yes
DNS2=8.8.8.8
以上是本机的第一块网卡IP设置,下面是DHCP的配置文件:
[root@www network-scripts]# cat /etc/dhcp/dhcpd.conf
ddns-update-style interim; 设置DNS更新类型
ignore client-updates; 设置禁止客户端更新DNS
subnet 192.168.0.0 netmask 255.255.255.0 { 定义自动分配地址的网段 range dynamic-bootp 192.168.0.130 192.168.0.160; 定义自动分配地址的范围
option routers 192.168.0.1; 定义客户端的网关
option subnet-mask 255.255.255.0; 定义客户端IP地址的子网掩码
option domain-name-servers 202.106.0.20,8.8.8.8; 定义客户获取的DNS
default-lease-time 21600; 定义默认更新IP时间
max-lease-time 43200; 定义最大更新时间
}
host xp { 设置保留IP,针对服务器等需要使用固定IP,host后面的xp是自定义的名字
hardware ethernet 00:0c:29:5e:b0:db; 定义客户端的MAC地址
fixed-address 192.168.0.144; 定义为客户端保留的IP地址
}
设置之后保存退出重启服务,如果启动过程中出错,可以动态查看日志:
[root@www network-scripts]# tail -f /var/log/messages
设置中继代理为其他网段提供IP分配:
[root@www 桌面]# cat /etc/dhcp/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 202.106.0.20,8.8.8.8;
range dynamic-bootp 192.168.0.130 192.168.0.160;
default-lease-time 21600;
max-lease-time 43200;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.1.144 192.168.1.155;
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
}
subnet 192.168.2.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.2.155 192.168.2.166;
option routers 192.168.2.1;
option subnet-mask 255.255.255.0;
}
[root@www 桌面]# cat /etc/sysconfig/dhcrelay
# Command line options here
INTERFACES="eth1 eth2" 定义要转发的网卡
DHCPSERVERS="192.168.0.12" DHCP服务器地址
[root@www 桌面]# dhcrelay -i eth1 -i eth2 192.168.0.12 生成中继代理