DHCP smart relayはセカンダリーアドレスを使ったDHCP relay agentです。通常設定ではプライマリアドレスを使いますが、構成上セカンダリーアドレスを使わざるを得ない場合は、この機能を使います。
DHCP relay
設定方法
DHCP smart relayを有効にするには以下のコマンドを入力します。
通常は、DHCP discovryなどのbroadcastを転送を行った転送元アドレスを表すgiaddrフィールドにprimary addressが記入されます。しかし、DHCP smart relayを有効にすると以下のような挙動に変わります。
- giaddrフィールドにprimary addressを設定してDHCP discoverを転送します
- 上記の転送に対してDHCP serverが応答を返さない場合は、giaddrフィールドにsecondary addressを設定してDHCP discoverを転送します
Router(config-if)# ip dhcp smart-relay
構成概要
R2 e0/0のprimary addressとして192.168.12.2/24をsecondary addressとして192.168.21.2を割り当てます。R2はDHCP relay agentとして設定し、R3はDHCP serverとして設定します。R3に設定されたDHCP poolはsecondary addressが割り当てられた192.168.21.0/24です。
       e0/0          e0/0    e0/1          e0/0
 +------+dhcp        .2+------+.2          .3+------+
 |  R1  +--------------+  R2  +--------------+  R3  |
 +------+              +------+              +------+
        192.168.12.0/24        192.168.23.0/24
        192.168.21.0/24
[R1] interface Ethernet0/0 ip address dhcp ! [R2] ip dhcp smart-relay ! interface Ethernet0/0 ip address 192.168.21.2 255.255.255.0 secondary ip address 192.168.12.2 255.255.255.0 ip helper-address 192.168.23.3 ! interface Ethernet0/1 ip address 192.168.23.2 255.255.255.0 [R3] ip dhcp pool VLAN21 network 192.168.21.0 255.255.255.0 ! interface Ethernet0/0 ip address 192.168.23.3 255.255.255.0 ! ip route 0.0.0.0 0.0.0.0 192.168.23.2
なお、設定全文は下記ファイルです。
パケットの観察
DHCPによるアドレス取得の過程で、R2 e0/1を流れたパケットは以下の通りです。DHCP Discoverが3回送信されている事が分かります。
No.     Time        Source                Destination           Protocol Info
      6 12.779000   cc:02:00:d4:00:00     cc:02:00:d4:00:00     LOOP     Reply
      7 12.920000   cc:02:00:d4:00:00     CDP/VTP/DTP/PAgP/UDLD CDP      Device ID: R3  Port ID: Ethernet0/0  
      8 16.248000   192.168.12.2          192.168.23.3          DHCP     DHCP Discover - Transaction ID 0x21f4
      9 20.014000   cc:01:00:d4:00:01     cc:01:00:d4:00:01     LOOP     Reply
     10 20.248000   192.168.12.2          192.168.23.3          DHCP     DHCP Discover - Transaction ID 0x21f4
     11 22.795000   cc:02:00:d4:00:00     cc:02:00:d4:00:00     LOOP     Reply
     12 30.014000   cc:01:00:d4:00:01     cc:01:00:d4:00:01     LOOP     Reply
     13 32.779000   cc:02:00:d4:00:00     cc:02:00:d4:00:00     LOOP     Reply
     14 37.982000   192.168.12.2          192.168.23.3          DHCP     DHCP Discover - Transaction ID 0x21f5
     15 38.060000   192.168.23.3          192.168.21.1          ICMP     Echo (ping) request
     16 39.545000   192.168.23.3          192.168.21.1          ICMP     Echo (ping) request
     17 39.998000   cc:01:00:d4:00:01     cc:01:00:d4:00:01     LOOP     Reply
     18 40.045000   192.168.23.3          192.168.21.2          DHCP     DHCP Offer    - Transaction ID 0x21f5
     19 40.170000   192.168.12.2          192.168.23.3          DHCP     DHCP Request  - Transaction ID 0x21f5
     20 40.264000   192.168.23.3          192.168.21.2          DHCP     DHCP ACK      - Transaction ID 0x21f5
1回目、2回目のDHCP Discoverはprimary addressである192.168.12.2がgiaddrフィールドに設定されたメッセージです。それに対し、3回目のDHCP Discoverはsecondary addressである192.168.21.2がgiaddrフィールドに設定されています。3回目のDHCP Discoverを詳細に表示すると以下の通りです。
Ethernet II, Src: cc:01:00:d4:00:01 (cc:01:00:d4:00:01), Dst: cc:02:00:d4:00:00 (cc:02:00:d4:00:00)
Internet Protocol, Src: 192.168.12.2 (192.168.12.2), Dst: 192.168.23.3 (192.168.23.3)
User Datagram Protocol, Src Port: bootps (67), Dst Port: bootps (67)
Bootstrap Protocol
    Message type: Boot Request (1)
    Hardware type: Ethernet
    Hardware address length: 6
    Hops: 1
    Transaction ID: 0x000021f5
    Seconds elapsed: 0
    Bootp flags: 0x8000 (Broadcast)
    Client IP address: 0.0.0.0 (0.0.0.0)
    Your (client) IP address: 0.0.0.0 (0.0.0.0)
    Next server IP address: 0.0.0.0 (0.0.0.0)
    Relay agent IP address: 192.168.21.2 (192.168.21.2)
    Client MAC address: cc:00:00:d4:00:00 (cc:00:00:d4:00:00)
    Client hardware address padding: 00000000000000000000
    Server host name not given
    Boot file name not given
    Magic cookie: (OK)
    Option: (t=53,l=1) DHCP Message Type = DHCP Discover
    Option: (t=57,l=2) Maximum DHCP Message Size = 1152
    Option: (t=61,l=27) Client identifier
    Option: (t=12,l=2) Host Name = "R1"
    Option: (t=55,l=8) Parameter Request List
    End Option
動作確認
IPアドレスが想定通りに割り当てられている事を確認します。
R1#show ip interface brief Interface IP-Address OK? Method Status Protocol Ethernet0/0 192.168.21.1 YES DHCP up up Ethernet0/1 unassigned YES unset administratively down down Ethernet0/2 unassigned YES unset administratively down down Ethernet0/3 unassigned YES unset administratively down down R1#
 
  
  
  
  