DynagenでCCIEを目指す
DHCP
最終更新:
it_certification
-
view
1. 目的
- ルータでDHCPを設定する方法を確認します。
2. 構成
2.1. 設定概要
- Host OS Loopback, Guest OS eth1はDHCPでIPアドレスを取得するように設定します。
- ルータR2 f0/1にはIPアドレスを設定しません。後述の検証で、DHCPで動的にIPアドレスを割り当てます。
2.2. 構成図

2.3. netファイル
model = 3660 [localhost] [[3660]] image = C:\Program Files\Dynamips\images\c3660-ik9o3s-mz.124-6.T.bin ram = 128 [[ROUTER R1]] f0/0 = NIO_gen_eth:\Device\NPF_{8B89D910-5ED3-4A43-9DE9-6A272A3D7592} f0/1 = R2 f0/1 [[ROUTER R2]] f0/0 = NIO_gen_eth:\Device\NPF_{5933302A-7AAA-475C-A8FE-A6B82B0C0F98}
2.4. 初期設定
- R1
! version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname R1 ! boot-start-marker boot-end-marker ! ! no aaa new-model ! resource policy ! memory-size iomem 5 ! ! ip cef no ip domain lookup ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface FastEthernet0/0 ip address 192.168.200.1 255.255.255.0 duplex auto speed auto ! interface FastEthernet0/1 ip address 192.168.12.1 255.255.255.0 duplex auto speed auto ! ip http server no ip http secure-server ! ! ! no cdp run ! ! ! control-plane ! ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 ! ! end
- R2
! version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname R2 ! boot-start-marker boot-end-marker ! ! no aaa new-model ! resource policy ! memory-size iomem 5 ! ! ip cef no ip domain lookup ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface FastEthernet0/0 ip address 192.168.201.2 255.255.255.0 duplex auto speed auto ! interface FastEthernet0/1 no ip address shutdown duplex auto speed auto ! ip http server no ip http secure-server ! ! ! no cdp run ! ! ! control-plane ! ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 ! ! end
3. [検証] DHCP 基本設定
3.1. DHCP 基本設定
Host OS loopbackに割り当てるIPアドレスを設定します。
R1(config)#ip dhcp excluded-address 192.168.200.1 R1(config)# R1(config)#ip dhcp pool WINDOWS R1(dhcp-config)#network 192.168.200.0 255.255.255.0 R1(dhcp-config)#default-router 192.168.200.1 R1(dhcp-config)#lease 0 1 <- lease期間を0日1時間とします(デフォルトは1日) R1(dhcp-config)#domain-name hogehoge.local R1(dhcp-config)#dns-server 192.168.200.1 R1(dhcp-config)#netbios-name-server 192.168.200.1 R1(dhcp-config)#netbios-node-type b-node
3.2. DHCP 設定確認
Host OS(Windows)でコマンドプロンプトを立ち上げ、「ipconfig」を入力します。(IPアドレスが取得できない場合は、/renewオプションを付ける事で再取得できます。なおオプションの指定方法はWindowsのバージョンによって異なります。)
C:\>ipconfig /renew *Loopback* Windows IP Configuration - 中略 - Ethernet adapter Loopback: Connection-specific DNS Suffix . : hogehoge.local IP Address. . . . . . . . . . . . : 192.168.200.2 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.200.1 C:\>
「ipconfig /all」と入力し、より詳細な情報を確認します。
C:\>ipconfig /all - 中略 - Ethernet adapter Loopback: Connection-specific DNS Suffix . : hogehoge.local Description . . . . . . . . . . . : Microsoft Loopback Adapter Physical Address. . . . . . . . . : 02-00-4C-4F-4F-50 Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.200.2 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.200.1 DHCP Server . . . . . . . . . . . : 192.168.200.1 DNS Servers . . . . . . . . . . . : 192.168.200.1 Primary WINS Server . . . . . . . : 192.168.200.1 Lease Obtained. . . . . . . . . . : 2010年9月7日 22:19:30 Lease Expires . . . . . . . . . . : 2010年9月7日 23:19:30 C:\>
ルータR1で「show ip dhcp binding」と入力し、割り当てたIPアドレスを確認します。
R1#show ip dhcp binding Bindings from all pools not associated with VRF: IP address Client-ID/ Lease expiration Type Hardware address/ User name 192.168.200.2 0102.004c.4f4f.50 Mar 01 2002 01:05 AM Automatic R1#
4. [検証] Cisco機をDHCP clientとする
4.1. DHCP サーバの設定
R1をDHCPサーバとして設定します。
R1(config)#ip dhcp excluded-address 192.168.12.1 R1(config)#ip dhcp pool LAN R1(dhcp-config)#network 192.168.12.0 255.255.255.0
4.2. DHCP クライアントの設定
R2 f0/1に対してIPアドレスをDHCPで割り当てます。
R2(config)#interface FastEthernet 0/1 R2(config-if)#no shutdown R2(config-if)# *Mar 1 00:00:56.523: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up *Mar 1 00:00:57.523: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up R2(config-if)#ip address dhcp R2(config-if)# *Mar 1 00:03:43.495: %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/1 assigned DHCP address 192.168.12.2, mask 255.255.255.0, hostname R2 R2(config-if)#
4.3. 設定確認
R2 f0/1に割り当てられたIPアドレスを確認します。
R2#show ip interface brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 192.168.201.2 YES NVRAM up up FastEthernet0/1 192.168.12.2 YES DHCP up up R2#
R1がR2に割り当てたIPアドレスを確認します。
R1#show ip dhcp binding Bindings from all pools not associated with VRF: IP address Client-ID/ Lease expiration Type Hardware address/ User name 192.168.12.2 0063.6973.636f.2d63. Mar 02 2002 12:17 AM Automatic 6330.312e.3039.3438. 2e30.3030.312d.4661. 302f.31 R1#
5. [検証] マニュアルバインディング
5.1. マニュアルバインディング
DHCPで割り当てるIPアドレスを静的に定義する事もできます。以下の要領で、DHCPの設定を行って下さい。
R2(config)#ip dhcp excluded-address 192.168.201.200 R2(config)# R2(config)#ip dhcp pool LINUX_STATIC R2(dhcp-config)#host 192.168.201.200 255.255.255.0 R2(dhcp-config)#hardware-address 00:FF:B1:A9:9E:00 <- ifconfigなどで予めGuest OSのMACアドレスを確認しておきます。
5.2. IPアドレスの確認
Guest OS eth1に割り当てられたIPアドレスを確認します。
[root@localhost ~]# /etc/init.d/network restart Shutting down interface eth0: [ OK ] Shutting down interface eth1: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining IP information for eth0... done. [ OK ] Bringing up interface eth1: Determining IP information for eth1... done. [ OK ] [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# /sbin/ifconfig eth0 Link encap:Ethernet HWaddr 00:FF:B2:EC:F0:00 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:947 errors:0 dropped:0 overruns:0 frame:0 TX packets:787 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:76197 (74.4 KiB) TX bytes:145802 (142.3 KiB) Interrupt:10 eth1 Link encap:Ethernet HWaddr 00:FF:B1:A9:9E:00 inet addr:192.168.201.200 Bcast:192.168.201.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:293 errors:0 dropped:0 overruns:0 frame:0 TX packets:41 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:33232 (32.4 KiB) TX bytes:11950 (11.6 KiB) Interrupt:10 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:464 errors:0 dropped:0 overruns:0 frame:0 TX packets:464 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:23488 (22.9 KiB) TX bytes:23488 (22.9 KiB) [root@localhost ~]#
6. [補足] チューニング
6.1. 重複チェックのチューニング
DHCPサーバは、IPアドレスを割り当てる前に割り当てようとしているIPアドレスが重複していないか調べます。Ciscoルータの場合、割り当てる予定のIPアドレスに対してpingを2回送信(timeoutは500msec)して、重複チェックを行います。
この重複チェックについては、以下の要領でチューニングする事ができます。
この重複チェックについては、以下の要領でチューニングする事ができます。
R1(config)#ip dhcp ping packets 3 R1(config)#ip dhcp ping timeout 600
7. [補足] 出来そうで出来ない設定
7.1. network, hostの併用
特定のホストのみ静的にIPアドレスを割り当て、その他のホストには動的にIPアドレスを割り当てたいとします。しかし、hostコマンドを入力すると、networkコマンドと併用できないと怒られてしまいます。
R2(config)#ip dhcp excluded-address 192.168.201.2 R2(config)#ip dhcp excluded-address 192.168.201.200 R2(config)#ip dhcp pool LINUX R2(dhcp-config)#network 192.168.201.0 255.255.255.0 R2(dhcp-config)#host 192.168.201.200 255.255.255.0 % This command may not be used with network, origin, vrf, or relay pools. R2(dhcp-config)#
7.2. dynamic pool, static poolの併用
特定のホストのみ静的にIPアドレスを割り当て、その他のホストには動的にIPアドレスを割り当てたいとします。静的なプールと動的なプールを2つ用意しましたが、ホストに割り当てられたのは動的なIPアドレスでした。静的なプールと動的なプールを2つ用意した場合は、動的なプールが優先されてしまうようです。
R2(config)#ip dhcp excluded-address 192.168.201.2 R2(config)#ip dhcp excluded-address 192.168.201.200 R2(config)# R2(config)# R2(config)#ip dhcp pool LINUX R2(dhcp-config)#network 192.168.201.0 255.255.255.0 R2(dhcp-config)#exit R2(config)# R2(config)# R2(config)#ip dhcp pool LINUX_STATIC R2(dhcp-config)#host 192.168.201.200 255.255.255.0 R2(dhcp-config)#hardware-address 00:FF:B1:A9:9E:00
添付ファイル