此Linux基础知识包括dhcp的一般应用,分配固定ip,中继代理
1.实验环境搭建
CentOS5.4虚拟机4台,分别为S(dhcpserver),A(dhcp-client),R(route),B(中继代理)
网卡配置如下:/etc/sysconfig/network-scripts/ifcfg-eth0 或 eth1
S:DEVICE=eth0
BOOTPRTO=static
HWADDR=XX:XX:XX:XX:XX:XX
ONBOOT=yes
IPADDR=192.168.8.2
NETMASK=255.255.255.0
GATEWAY=192.168.8.1 (中继代理需要)
A:DEVICE=eth0
BOOTPRTO=dhcp
ONBOOT=yes
HWADDR:00:0C:29:0A:4B:EE (固定分配IP需要)
R:DEVICE=eth0
BOOTPRTO=static
HWADDR=XX:XX:XX:XX:XX:XX
IPADDR=192.168.8.1
NETMASK=255.255.255.0
DEVICE=eth1
BOOTPRTO=static
HWADDR=XX:XX:XX:XX:XX:XX
IPADDR=192.168.38.1
NETMASK=255.255.255.0
B:DEVICE=eth0
BOOTPRTO=static
HWADDR=XX:XX:XX:xX:XX:xX
IPADDR=192.168.38.2
NETMASK=255.255.255.0
GATEWAY=192.168.38.1
2.拓扑结构说明:
虚拟机S位于192.168.8.x网段上,网关为虚拟机R eth0的IP
虚拟机B位于192.168.38.x网段上,网关为虚拟机R eth1的IP
虚拟机R作用为路由器,故设置转发:
查看是否是网卡是否能转发数据
cat /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_forward
设置成功后试用虚拟机B ping dhcp服务器S
虚拟机A先与S处于同一网段(VMnet2)
2.安装dhcp包
由于dhcp包包含了dhcp服务于中继服务,所以虚拟机S 虚拟机B都需要安装
rpm -ivh dhcp-xxxx.rpm
拷贝配置文件 dhcp
cp /usr/share/doc/dhcp-3.0xx/dhcpd.conf.sample /etc/dhcpd.conf
中继服务dhcrelay不需要拷贝配置文件
3.虚拟机S的dhcpd.conf设置
vi /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 192.168.8.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.8.1;
option subnet-mask 255.255.255.0;
# option nis-domain "domain.org";
# option domain-name "domain.org";
# option domain-name-servers 192.168.13.220;
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;
range dynamic-bootp 192.168.8.120 192.168.13.167; (这里设置地址池)
range dynamic-bootp 192.168.8.169 192.168.13.254; (预留168给特定mac)
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.RedHat.com;
hardware ethernet 00:0C:29:0A:4B:EE; (为特定mac预留IP 这里为虚拟机A预留)
fixed-address 192.168.8.168;
}
}