一,为dhcp服务器设置ip:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0c:29:12:45:0c
ONBOOT=yes
DHCP_HOSTNAME=localhost.localdomain
IPADDR=172.17.17.2
NETMASK=255.255.255.0
TYPE=Ethernet
GATEWAY=172.17.17.1
~
[root@localhost ~]# service network restart
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:12:45:0C
inet addr:172.17.17.2 Bcast:172.17.17.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe12:450c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:547 errors:0 dropped:0 overruns:0 frame:0
TX packets:123 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:45460 (44.3 KiB) TX bytes:19384 (18.9 KiB)
Interrupt:67 Base address:0x2024
[root@localhost ~]#
安装DHCP:
[root@localhost ~]# mount /dev/cdrom /mnt
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# yum install dhcp*
设置主配置文件:
[root@localhost ~]# vim /etc/dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhc
dhclient-eth0.conf dhcp6s.conf
dhcp6c.conf dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp:是否覆盖“/etc/dhcpd.conf”? y
[root@localhost ~]# vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 172.17.17.0 netmask 255.255.255.0 {
# --- default gateway
option routers 172.17.17.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.1;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 172.17.17.1 172.17.17.100;
default-lease-time 21600;
max-lease-time 43200;
启动dhcp:[root@localhost ~]# service dhcpd start
启动 dhcpd: [确定]
[root@localhost ~]#
二,中继代理
设置ip:
eth0: 172.17.17.17.1 255.255.255.0
eth1: 192.168.1.1 255.255.255.0
eth2: 192.168.2.1 255.255.255.0
service network restart
安装dhcp:[root@localhost ~]# mount /dev/cdrom /mnt
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# yum install dhcp*
修改配置文件:
[root@localhost ~]#vim /etc/sysconfig/dhcrelay
#Command line options here
INTERFACES="eth0 eth1 eth2"
DHCPSERVERS="172.17.17.2"
启动dhcrelay:
[root@localhost ~]#service dhcrelay start
启动 dhcrelay [确定]
设置ip转发:
[root@localhost ~]# vim /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p
客户端测试:
[root@localhost ~]# dhclient eth0
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/00:0c:29:0a:35:35
Sending on LPF/eth0/00:0c:29:0a:35:35
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
DHCPOFFER from 172.17.17.2
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 172.17.17.2
bound to 172.17.17.98 -- renewal in 10526 seconds.
[root@localhost ~]#
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:0A:35:35
inet addr:172.17.17.98 Bcast:172.17.17.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0a:3535/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2301 errors:0 dropped:0 overruns:0 frame:0
TX packets:369 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:227283 (221.9 KiB) TX bytes:47738 (46.6 KiB)
Interrupt:67 Base address:0x2024
[root@localhost ~]#