今回はCiscoルータでDHCPサーバを構築したいと思います。
検証環境

検証環境はPC1台、Ciscoルータ1台ととてもシンプルな構成です。
CiscoルータのFE0/0には172.31.0.1/16を設定し、そのインタフェースにPCを接続します。
クライアントに配布するIPアドレスの範囲は「172.31.0.11〜172.31.255.254」とし、「172.31.0.1〜172.31.0.10」はネットワーク監視者が使用するアドレスとしたいので、配布するアドレスからは除外します。
Ciscoルータの初期コンフィグ
Router#show running-confi
Building configuration...
Current configuration : 553 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
no ip address
duplex auto
speed auto
shutdown
!
interface FastEthernet0/1
no ip address
duplex auto
speed auto
shutdown
!
interface Vlan1
no ip address
shutdown
!
ip classless
!
ip flow-export version 9
!
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end
Ciscoルータの設定
PCを接続するインタフェースにIPアドレス「172.31.0.1/16」を設定します。
また、デフォルトで「shutdown」が設定されていたので、「no shutdown」を投入してインタフェースを解放しておきます。
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(if-config)#ip address 172.31.0.1 255.255.0.0
Router(if-config)#no shutdown
DHCPサービスを有効化します。
Router(config)#
Router(config)#service dhcp
Router(config)#
ネットワーク管理者が使用する「172.31.0.1〜172.31.0.10」の範囲のIPアドレスを配布リストから除外したいと思います。
Router(config)#
Router(config)#ip dhcp excluded-address 172.31.0.1 172.31.0.10
Router(config)#
DHCPのプール名を設定します。
この設定はどのような場所もしくは用途でDHCPサーバを使うかをわかりやすくするための設定です。仮で営業部門のDHCPプールを作成してみます。
Router(config)#ip dhcp pool eigyo
Router(dhcp-config)#
DHCPを設定するモードに移行します。
このモードでは下記のようなコマンドが候補として現れます。
Router(dhcp-config)#?
default-router Default routers
dns-server Set name server
domain-name Domain name
exit Exit from DHCP pool configuration mode
network Network number and mask
no Negate a command or set its defaults
option Raw DHCP options
Router(dhcp-config)#
DHCPクライアントに割り当てるネットワークアドレスを設定するため、先程の候補の中の「network」を使用します。ネットワークアドレスとして「172.31.0.0」を、サブネットマスクとして「255.255.0.0」を設定してみます。
Router(dhcp-config)#network 172.31.0.0 255.255.0.0
Router(dhcp-config)#
続いて、IPアドレスに加えデフォルトルートも一緒に配布したいため、候補の中の「default-router」を設定していきます。Ciscoルータのインタフェースに設定予定の「172.31.0.1」を設定してみます。
Router(dhcp-config)#default-router 172.31.0.1
Router(dhcp-config)#
以上で最低限の設定は完了です。
Ciscoルータのステータス確認
最低限の設定が完了したので、設定したDHCP関連のコマンドがちゃんとCiscoルータに反映されているかを確認してみます。
コマンドは「show ip dhcp pool」を使います。
Router#show ip dhcp pool
Pool eigyo :
Utilization mark (high/low) : 100 / 0
Subnet size (first/next) : 0 / 0
Total addresses : 65534
Leased addresses : 0
Excluded addresses : 1
Pending event : none
1 subnet is currently in the pool
Current index IP address range Leased/Excluded/Total
172.31.0.1 172.31.0.1 - 172.31.255.254 0 / 1 / 65534
Router#
また、「show ip dhcp binding」で既に割り当てられてIPアドレスを表示することができます。出力結果より、PCに「172.31.0.11」が割り当てられていることが分かります。
Router#show ip dhcp binding
IP address Client-ID/ Lease expiration Type
Hardware address
172.31.0.11 0030.A3CA.BC3A -- Automatic
動作確認
CiscoルータのFE0/0にPCをクロスケーブルで接続します。
その後、コマンドプロンプトで「ipconfig」と入力すると、IPアドレスが配布されていることを確認することができます。
C:\>ipconfig
FastEthernet0 Connection:(default port)
Connection-specific DNS Suffix..:
Link-local IPv6 Address.........: FE80::230:A3FF:FECA:BC3A
IPv6 Address....................: ::
IPv4 Address....................: 172.31.0.11
Subnet Mask.....................: 255.255.0.0
Default Gateway.................: ::
172.31.0.1
せっかくなのでCiscoルータのFE0/0にPingを飛ばしてみます。
C:\>
C:\>ping 172.31.0.1
Pinging 172.31.0.1 with 32 bytes of data:
Reply from 172.31.0.1: bytes=32 time=27ms TTL=255
Reply from 172.31.0.1: bytes=32 time<1ms TTL=255
Reply from 172.31.0.1: bytes=32 time<1ms TTL=255
Reply from 172.31.0.1: bytes=32 time<1ms TTL=255
Ping statistics for 172.31.0.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 27ms, Average = 6ms
C:\>
Ciscoルータの設定済みコンフィグ
Router#show running-config
Building configuration...
Current configuration : 689 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
ip dhcp excluded-address 172.31.0.1 172.31.0.10
!
ip dhcp pool eigyo
network 172.31.0.0 255.255.0.0
default-router 172.31.0.1
!
!
!
ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
ip address 172.31.0.1 255.255.0.0
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
duplex auto
speed auto
shutdown
!
interface Vlan1
no ip address
shutdown
!
ip classless
!
ip flow-export version 9
!
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end
最後に
CiscoルータのDHCPサーバの設定をしてみました。
ただし、このままでは使い勝手が良くなかったり、セキュリティ的にも問題があるのでもう少し設定を追加していきたいと思います。
勉強教材
コメント