天天看點

建構DHCP伺服器及配置DHCP中繼的安裝過程

一、搭建環境:

準備三台虛拟機,分别命名為dhcp,dhcprelay(添加三塊網卡),client ,Dhcp 連接配接 vmnet1,

dhcprelay 分别連接配接 vmnet1,vmnet2,vmnet3.

為三台虛拟機配置IP位址

dhcp-eth0:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 

DEVICE=eth0

ONBOOT=yes

IPADDR=50.1.1.1

NETMASK=255.255.255.0

GATEWAY=50.1.1.254

[root@localhost ~]# ifdown eth0 ; ifup eth0

dhcprelay-eth0:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth

ifcfg-eth0      ifcfg-eth0.bak  ifcfg-eth1      ifcfg-eth2

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet

IPADDR=50.1.1.254

dhcprelay-eth1:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth1

BOOTPROTO=static

IPADDR=50.2.2.254

[root@localhost ~]# ifdown eth1 ; ifup eth1

dhcprelay-eth2:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth2

DEVICE=eth2

IPADDR=50.3.3.254

[root@localhost ~]# ifdown eth2 ; ifup eth2

二、在dhcp 和 dhcprelay 上安裝dhcp服務

[root@localhost ~]# mount -o loop /dev/cdrom /media/

[root@localhost ~]# cd /media/Server/

[root@localhost Server]# rpm -ivh dhcp-3.0.5-23.el5.i386.rpm 

error: failed to stat /media/RHEL_5.5 i386 DVD: 沒有那個檔案或目錄

Preparing...                ########################################### [100%]

   1:dhcp                   ########################################### [100%]

三、在dhcp上編輯/etc/dhcpd.conf

[root@localhost Server]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf 

cp:是否覆寫“/etc/dhcpd.conf”? y

[root@localhost Server]# vim /etc/dhcpd.conf 

ddns-update-style none;

default-lease-time 21600;

max-lease-time 43200;

option domain-name-servers 202.106.0.20;

subnet  50.1.1.0  netmask 255.255.255.0 {

        option routers                  50.1.1.254;

        option subnet-mask              255.255.255.0;

        range dynamic-bootp 50.1.1.2 50.1.1.100;

        host srv {

                hardware ethernet 12:34:56:78:AB:CD;

                fixed-address 50.1.1.50;

        }

}

subnet 50.2.2.0 netmask 255.255.255.0{

        range dynamic-bootp 50.2.2.2 50.2.2.100;

        option subnet-mask 255.255.255.0;

        option routers 50.2.2.254;

subnet 50.3.3.0 netmask 255.255.255.0{

        range dynamic-bootp 50.3.3.2 50.3.3.100;

        option routers 50.3.3.254;

四、在dhcp上啟動dhcp 服務

[root@localhost ~]# service dhcpd start

啟動 dhcpd:                                               [确定]

五、在dhcprelay 上開啟路由轉發

[root@localhost Server]# vim /etc/sysctl.conf 

net.ipv4.ip_forward = 1

[root@localhost Server]# sysctl -p

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

net.ipv4.tcp_syncookies = 1

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 4294967295

kernel.shmall = 268435456

六、在dhcprelay 上配置中繼

[root@localhost Server]# vim /etc/sysconfig/dhcrelay 

# Command line options here

INTERFACES="eth0 eth1 eth2"

DHCPSERVERS="50.1.1.1"

七、啟動dhcprelay 中繼服務

[root@localhost Server]# service dhcrelay start

啟動 dhcrelay:                                            [确定]

八、驗證

1、将client 連接配接vmnet1上,并設定dhcp自動擷取

BOOTPROTO=dhcp

2、重新開機網卡後檢視IP

[root@localhost ~]# ifdown eth0

[root@localhost ~]# ifup eth0

正在決定 eth0 的 IP 資訊...完成。

[root@localhost ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:B1:17:07  

          inet addr:50.1.1.100  Bcast:50.1.1.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:feb1:1707/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:221 errors:0 dropped:0 overruns:0 frame:0

          TX packets:659 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:43662 (42.6 KiB)  TX bytes:133870 (130.7 KiB)

          Interrupt:177 Base address:0x2024 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:3162 errors:0 dropped:0 overruns:0 frame:0

          TX packets:3162 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:5332786 (5.0 MiB)  TX bytes:5332786 (5.0 MiB)

3、修改網卡使用的MAC位址為 cc-cc-cc-cc-cc-cc 獲得ip 位址為保留ip 50.1.1.50

[root@localhost ~]# ifconfig eth0 hw ether cc:cc:cc:cc:cc:cc

[root@localhost ~]# ifconfig 

eth0      Link encap:Ethernet  HWaddr CC:CC:CC:CC:CC:CC  

          inet addr:50.1.1.50  Bcast:50.1.1.255  Mask:255.255.255.0

          inet6 addr: fe80::cecc:ccff:fecc:cccc/64 Scope:Link

          RX packets:227 errors:0 dropped:0 overruns:0 frame:0

          TX packets:693 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:45714 (44.6 KiB)  TX bytes:141004 (137.6 KiB)

4、将client 連接配接 vmnet2上,并設定重新開機網卡獲得50.2.2.100

          inet addr:50.2.2.100  Bcast:50.2.2.255  Mask:255.255.255.0

          RX packets:241 errors:0 dropped:0 overruns:0 frame:0

          TX packets:742 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:49190 (48.0 KiB)  TX bytes:150619 (147.0 KiB)

5、将client連接配接vmnet3上,并設定重新開機網卡獲得50.3.3.100

          inet addr:50.3.3.100  Bcast:50.3.3.255  Mask:255.255.255.0

          RX packets:247 errors:0 dropped:0 overruns:0 frame:0

          TX packets:791 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:50116 (48.9 KiB)  TX bytes:161057 (157.2 KiB)

繼續閱讀