今回はCiscoルータでDHCPリレーエージェントを設定したいと思います。
検証環境

検証環境としてPC1台とCiscoルータを2台用意しました。
CiscoルータはDHCPサーバ用に1台、DHCPリレーエージェント用に1台用意しています。
DHCPリレーエージェントが必要な理由は?
DHCPサーバとDHCPクライアント間の通信はブロードキャストで行われるため、両者とも同じセグメントに属している必要があります。
しかし、一般的なネットワーク構成として、複数のセグメントを介して通信が行われることが多いことから、同じセグメント上にDHCPサーバを置けない場合は使えないことになります。
そこで役に立つのが、DHCPリレーエージェント機能です。
DHCPリレーエージェント機能により、DHCPサーバとDHCPクライアントが同じサブネットに属していない場合でも両者の通信を仲介してくれるため、複数セグメントを介してDHCPを使いたい場合に有効と言えます。
Ciscoルータの初期設定
Router#show running-config
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ルータ(DHCPサーバ)の設定
使用用途が分かるように最初にホスト名を「DHCPSV」にしたいと思います。
Router#
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#
Router(config)#hostname DHCPSV
DHCPSV(config)#
基本的な設定内容は前回と同様です。

DHCPリレーエージェント用のCiscoルータと接続するインタフェースの設定を行います。FE0/0にIPアドレス「172.31.1.1/24」を設定します。
DHCPSV(config)#
DHCPSV(config)#interface fastEthernet 0/0
DHCPSV(config-if)#
DHCPSV(config-if)#ip address 172.31.1.1 255.255.255.0
DHCPSV(config-if)#no shutdown
DHCPSV(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
DHCPSV(config-if)#
DHCPSV(config-if)#exit
DHCPSV(config)#
ネットワーク管理者が使用する「172.31.0.1〜172.31.0.4」の範囲のIPアドレスを配布リストから除外したいと思います。
DHCPSV(config)#
DHCPSV(config)#ip dhcp excluded-address 172.31.0.1 172.31.0.4
DHCPSV(config)#
続いて、DHCPの設定を追加していきます。
今回はDHCPのプール名を「guest」、DHCPで配布するIPアドレスのネットワークアドレス「172.31.0.0」、サブネットマスクとして「255.255.255.0」を設定します。デフォルトゲートウェイとして「172.31.0.1」を設定します。
HCPSV(config)#
DHCPSV(config)#ip dhcp pool guest
DHCPSV(dhcp-config)#network 172.31.0.0 255.255.255.0
DHCPSV(dhcp-config)#default-router 172.31.0.1
DHCPSV(dhcp-config)#exit
DHCPSV(config)#
Ciscoルータ(DHCPサーバ)から見て、「172.31.0.0/24」のセグメントがどこにいるか分からないため、スタティックルートを設定します。ネクストホップのアドレスはCiscoルータ(DHCPリレーエージェント)の「172.31.1.2」にします。
DHCPSV(config)#
DHCPSV(config)#ip route 172.31.0.0 255.255.255.0 172.31.1.2
DHCPSV(config)#
以上で、Ciscoルータ(DHCPサーバ)の設定は完了です。
Ciscoルータ(DHCPリレーエージェント)の設定
使用用途が分かるようにホスト名を設定を「DHCPRL」にしておきます。
Router#
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#
Router(config)#hostname DHCPRL
DHCPRL(config)#
続いて、インタフェースの設定をしていきます。
最初に、Ciscoルータ(DHCPサーバ)側の設定をしていきます。FE0/1にIPアドレス「172.31.1.2/24」を設定します。
DHCPRL(config)#
DHCPRL(config)#interface fastEthernet 0/1
DHCPRL(config-if)#ip address 172.31.1.2 255.255.255.0
DHCPRL(config-if)#no shutdown
DHCPRL(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
DHCPRL(config-if)#
DHCPRL(config-if)#exit
DHCPRL(config)#
続いて、PC側を設定していきます。FE0/0にIPアドレス「172.31.0.1/24」を設定します。FE0/0に設定するIPアドレスは、DHCPでデフォルトゲートウェイとして配布するアドレスと同じものになります。
DHCPRL(config)#
DHCPRL(config)#interface fastEthernet 0/0
DHCPRL(config-if)#ip address 172.31.0.1 255.255.255.0
DHCPRL(config-if)#no shutdown
DHCPRL(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
DHCPRL(config-if)#
最後に、FE0/0のインタフェースにDHCPリレーエージェントの設定を追加します。設定しているIPアドレスは、Ciscoルータ(DHCPサーバ)のIPアドレスです。
DHCPRL(config-if)#
DHCPRL(config-if)#ip helper-address 172.31.1.1
DHCPRL(config-if)#
以上で、Ciscoルータ(DHCPリレーエージェント)の設定は完了です。
動作確認
では、動作確認をしていきます。それぞれの機器をケーブルで接続し、検証環境の図の構成を作ります。
その後、PCのコマンドプロンプトで「ipconfig /renew」と入力して、DHCPのアドレスが配布されることを確認します。すると、「172.31.0.19/24」が配布され、ゲートウェイとして「172.31.0.1」が配布されていることが分かります。
C:\>
C:\>ipconfig /renew
IP Address......................: 172.31.0.19
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 172.31.0.1
DNS Server......................: 0.0.0.0
C:\>
せっかくなのでCiscoルータ(DHCPサーバ)のFE0/0にPingを飛ばしてみます。
C:\>
C:\>ping 172.31.1.1
Pinging 172.31.1.1 with 32 bytes of data:
Reply from 172.31.1.1: bytes=32 time<1ms TTL=254
Reply from 172.31.1.1: bytes=32 time<1ms TTL=254
Reply from 172.31.1.1: bytes=32 time=1ms TTL=254
Reply from 172.31.1.1: bytes=32 time<1ms TTL=254
Ping statistics for 172.31.1.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
C:\>
無事に到達性を確認することができました。
設定後のコンフィグ
設定を行ったCiscoルータのコンフィグは下記の通りです。
Ciscoルータ(DHCPサーバ)の設定済みコンフィグ
DHCPSV#show running-config
Building configuration...
Current configuration : 738 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname DHCPSV
!
!
!
!
ip dhcp excluded-address 172.31.0.1 172.31.0.4
!
ip dhcp pool guest
network 172.31.0.0 255.255.255.0
default-router 172.31.0.1
!
!
!
ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
ip address 172.31.1.1 255.255.255.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 route 172.31.0.0 255.255.255.0 172.31.1.2
!
ip flow-export version 9
!
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end
Ciscoルータ(DHCPリレーエージェント)の設定済みコンフィグ
DHCPRL#
DHCPRL#show ru
DHCPRL#show running-config
Building configuration...
Current configuration : 607 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname DHCPRL
!
!
!
!
!
!
!
!
ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
ip address 172.31.0.1 255.255.255.0
ip helper-address 172.31.1.1
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 172.31.1.2 255.255.255.0
duplex auto
speed auto
!
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
最後に
DHCPリレーエージェントの設定を追加するインタフェースさえ間違わなければ、すんなり成功すると思います。
ぜひ試してみてください。
学習教材
コメント