samples/net/dhcpv4_client/README.html · samples/net/dhcpv4_client/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · Networking · DHCP

DHCPv4 Client

QEMU tap0, FRDM-K64F eth1, Arm FVP 환경에서 Kea와 address를 협상합니다.

Official pathsamples/net/dhcpv4_client/README.html
Source filesamples/net/dhcpv4_client/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Kea JSON 설정 두 벌, host route와 세 client 실행·출력·ping 절차를 14개 원문 block 그대로 보존합니다.

Server

Kea DHCPv4

Targets

QEMU · FRDM · FVP

Lease

7,200 · 86,400 s

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 AB20F6789C98A6AA310E8D3E1CF2CBD05138C5C21CD83F75F80958E74643F680
.. zephyr:code-sample:: dhcpv4-client
   :name: DHCPv4 client
   :relevant-api: dhcpv4 net_mgmt

   Start a DHCPv4 client to obtain an IPv4 address from a DHCPv4 server.

Overview
********

This application starts a DHCPv4 client, gets an IPv4 address from the
DHCPv4 server, and prints address, lease time, netmask and router
information to a serial console.

Requirements
************

- :ref:`networking_with_host`

Building and Running
********************

Running DHCPv4 client in Linux Host
===================================

These are instructions for how to use this sample application using
QEMU on a Linux host to negotiate IP address from DHCPv4 server (kea) running
on Linux host.

To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.

Here's a sample server configuration file '/etc/kea/kea-dhcp4.conf'
used to configure the DHCPv4 server:

.. code-block:: console

    {
        "Dhcp4": {
            "interfaces-config": {
                "interfaces": [ "tap0" ],
                "dhcp-socket-type": "raw"
            },

            "valid-lifetime": 7200,

            "subnet4": [
                {
                    "id": 1,
                    "subnet": "192.0.2.0/24",
                    "pools": [ { "pool": "192.0.2.10 - 192.0.2.100" } ],
                    "option-data": [
                        {
                            "name": "routers",
                            "data": "192.0.2.2"
                        },
                        {
                            "name": "domain-name-servers",
                            "data": "8.8.8.8"
                        }
                    ]
                }
            ]
        }
    }

Use another terminal window to start up a DHCPv4 server on the Linux host,
using this conf file:

.. code-block:: console

    $ sudo kea-dhcp4 -c /etc/kea/kea-dhcp4.conf

Run Zephyr samples/net/dhcpv4_client application in QEMU:

.. zephyr-app-commands::
   :zephyr-app: samples/net/dhcpv4_client
   :host-os: unix
   :board: qemu_x86
   :goals: run
   :compact:

Once DHCPv4 client address negotiation completed with server, details
are shown like this:

.. code-block:: console

    [00:00:00.000,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
    [00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on slip: index=1
    [00:00:07.080,000] <inf> net_dhcpv4: Received: 192.0.2.10
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample:    Address[1]: 192.0.2.10
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Router[1]: 192.0.2.2
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 7200 seconds

To verify the Zephyr application client is running and has received
an ip address by typing:

.. code-block:: console

    $ ping -I tap0 192.0.2.10


FRDM_K64F
=========

These are instructions for how to use this sample application running on
:ref:`frdm_k64f` board to negotiate IP address from DHCPv4 server (kea) running
on Linux host.

Connect ethernet cable from :ref:`Freedom-K64F board <frdm_k64f>` to Linux host
machine and check for new interfaces:

.. code-block:: console

    $ ifconfig

Add ip address and routing information to interface:

.. code-block:: console

    $ sudo ip addr add 192.0.2.2 dev eth1
    $ sudo ip route add 192.0.2.0/24 dev eth1

Here's a sample server configuration file '/etc/kea/kea-dhcp4.conf'
used to configure the DHCPv4 server:

.. code-block:: console

    {
        "Dhcp4": {
            "interfaces-config": {
                "interfaces": [ "eth1" ],
                "dhcp-socket-type": "raw"
            },

            "valid-lifetime": 7200,

            "subnet4": [
                {
                    "id": 1,
                    "subnet": "192.0.2.0/24",
                    "pools": [ { "pool": "192.0.2.10 - 192.0.2.100" } ],
                    "option-data": [
                        {
                            "name": "routers",
                            "data": "192.0.2.2"
                        },
                        {
                            "name": "domain-name-servers",
                            "data": "8.8.8.8"
                        }
                    ]
                }
            ]
        }
    }

Use another terminal window to start up a DHCPv4 server on the Linux host,
using this conf file:

.. code-block:: console

    $ sudo kea-dhcp4 -c /etc/kea/kea-dhcp4.conf

Build Zephyr samples/net/dhcpv4_client application:

.. zephyr-app-commands::
   :zephyr-app: samples/net/dhcpv4_client
   :host-os: unix
   :board: frdm_k64f
   :goals: build flash
   :compact:

Once DHCPv4 client address negotiation completed with server, details
are shown like this:

.. code-block:: console

    $ sudo screen /dev/ttyACM0 115200
    [00:00:00.000,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
    [00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on ethernet: index=1
    [00:00:07.080,000] <inf> net_dhcpv4: Received: 192.0.2.10
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample:    Address[1]: 192.0.2.10
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Router[1]: 192.0.2.2
    [00:00:07.080,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 7200 seconds

To verify the Zephyr application client is running and has received
an ip address by typing:

.. code-block:: console

    $ ping -I eth1 192.0.2.10


Arm FVP
========

* :ref:`fvp_baser_aemv8r`
* :ref:`fvp_base_revc_2xaemv8a`

This sample application running on Arm FVP board can negotiate IP
address from DHCPv4 server running on Arm FVP, so there is no extra
configuration that needed to do. It can be build and run directly.

Build Zephyr samples/net/dhcpv4_client application:

.. zephyr-app-commands::
   :zephyr-app: samples/net/dhcpv4_client
   :host-os: unix
   :board: fvp_baser_aemv8r
   :goals: build run
   :compact:

Once DHCPv4 client address negotiation completed with server, details
are shown like this:

.. code-block:: console

    uart:~$
    [00:00:00.060,000] <inf> phy_mii: PHY (0) ID 16F840

    [00:00:00.170,000] <inf> phy_mii: PHY (0) Link speed 10 Mb, half duplex

    [00:00:00.170,000] <inf> eth_smsc91x: MAC 00:02:f7:ef:37:16
    *** Booting Zephyr OS build zephyr-v3.2.0-4300-g3e6505dba29e ***
    [00:00:00.170,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
    [00:00:00.180,000] <inf> net_dhcpv4_client_sample: Start on ethernet@9a000000: index=1
    [00:00:07.180,000] <inf> net_dhcpv4: Received: 172.20.51.1
    [00:00:07.180,000] <inf> net_dhcpv4_client_sample:    Address[1]: 172.20.51.1
    [00:00:07.180,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
    [00:00:07.180,000] <inf> net_dhcpv4_client_sample:     Router[1]: 172.20.51.254
    [00:00:07.180,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 86400 seconds

Part 3

한국어 전문 번역

개요

이 application은 DHCPv4 client를 시작하고 DHCPv4 server에서 IPv4 address를 얻은 뒤 address, lease time, netmask, router 정보를 serial console에 출력합니다.

요구 사항

Build와 실행

Linux host에서 DHCPv4 client 실행

다음 절차는 Linux host에서 실행 중인 DHCPv4 server인 Kea와 QEMU의 sample application이 IPv4 address를 협상하도록 구성합니다.

QEMU 시험 환경은 QEMU network 설정을 먼저 구성해야 합니다.

다음은 DHCPv4 server에 사용할 /etc/kea/kea-dhcp4.conf 예제입니다. Raw DHCP socket을 tap0에 연결하고 192.0.2.10~192.0.2.100 pool, 7,200초 lease, router 192.0.2.2, DNS 8.8.8.8을 제공합니다.

{
    "Dhcp4": {
        "interfaces-config": {
            "interfaces": [ "tap0" ],
            "dhcp-socket-type": "raw"
        },

        "valid-lifetime": 7200,

        "subnet4": [
            {
                "id": 1,
                "subnet": "192.0.2.0/24",
                "pools": [ { "pool": "192.0.2.10 - 192.0.2.100" } ],
                "option-data": [
                    {
                        "name": "routers",
                        "data": "192.0.2.2"
                    },
                    {
                        "name": "domain-name-servers",
                        "data": "8.8.8.8"
                    }
                ]
            }
        ]
    }
}

다른 terminal에서 이 configuration file을 사용해 Linux host의 DHCPv4 server를 시작합니다.

$ sudo kea-dhcp4 -c /etc/kea/kea-dhcp4.conf

QEMU에서 Zephyr samples/net/dhcpv4_client application을 실행합니다.

west build -b qemu_x86 samples/net/dhcpv4_client
west build -t run

DHCPv4 client와 server의 address 협상이 끝나면 다음과 같이 SLIP interface에 192.0.2.10 address, /24 netmask, router, lease time이 표시됩니다.

[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on slip: index=1
[00:00:07.080,000] <inf> net_dhcpv4: Received: 192.0.2.10
[00:00:07.080,000] <inf> net_dhcpv4_client_sample:    Address[1]: 192.0.2.10
[00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
[00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Router[1]: 192.0.2.2
[00:00:07.080,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 7200 seconds

Zephyr client가 실행 중이고 IP address를 받았는지 tap0를 통해 ping하여 확인합니다.

$ ping -I tap0 192.0.2.10

FRDM-K64F

다음 절차는 FRDM-K64F board에서 실행하는 sample이 Linux host의 Kea DHCPv4 server와 IPv4 address를 협상하도록 구성합니다.

Freedom-K64F board와 Linux host machine을 Ethernet cable로 연결하고 새 interface를 확인합니다.

$ ifconfig

새 interface가 eth1이라고 가정하고 IP address와 route 정보를 추가합니다.

$ sudo ip addr add 192.0.2.2 dev eth1
$ sudo ip route add 192.0.2.0/24 dev eth1

DHCPv4 server용 /etc/kea/kea-dhcp4.conf는 QEMU 설정과 같은 pool과 option을 사용하되 interface를 eth1로 지정합니다.

{
    "Dhcp4": {
        "interfaces-config": {
            "interfaces": [ "eth1" ],
            "dhcp-socket-type": "raw"
        },

        "valid-lifetime": 7200,

        "subnet4": [
            {
                "id": 1,
                "subnet": "192.0.2.0/24",
                "pools": [ { "pool": "192.0.2.10 - 192.0.2.100" } ],
                "option-data": [
                    {
                        "name": "routers",
                        "data": "192.0.2.2"
                    },
                    {
                        "name": "domain-name-servers",
                        "data": "8.8.8.8"
                    }
                ]
            }
        ]
    }
}

다른 terminal에서 이 configuration file로 Linux host의 DHCPv4 server를 시작합니다.

$ sudo kea-dhcp4 -c /etc/kea/kea-dhcp4.conf

FRDM-K64F용 Zephyr application을 build하고 flash합니다.

west build -b frdm_k64f samples/net/dhcpv4_client
west flash

DHCPv4 client의 address 협상이 끝나면 serial console에서 다음 세부 정보를 확인할 수 있습니다.

$ sudo screen /dev/ttyACM0 115200
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on ethernet: index=1
[00:00:07.080,000] <inf> net_dhcpv4: Received: 192.0.2.10
[00:00:07.080,000] <inf> net_dhcpv4_client_sample:    Address[1]: 192.0.2.10
[00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
[00:00:07.080,000] <inf> net_dhcpv4_client_sample:     Router[1]: 192.0.2.2
[00:00:07.080,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 7200 seconds

Zephyr client가 실행 중이고 IP address를 받았는지 eth1를 통해 ping하여 확인합니다.

$ ping -I eth1 192.0.2.10

Arm FVP

  • fvp_baser_aemv8r
  • fvp_base_revc_2xaemv8a

Arm FVP board에서 실행하는 sample application은 FVP에서 실행 중인 DHCPv4 server와 IP address를 협상할 수 있으므로 추가 configuration이 필요하지 않습니다. Application을 바로 build하고 실행할 수 있습니다.

다음은 fvp_baser_aemv8r용 build와 실행 명령입니다.

west build -b fvp_baser_aemv8r samples/net/dhcpv4_client
west build -t run

협상이 완료되면 PHY와 MAC 초기화 뒤 172.20.51.1 address, /24 netmask, 172.20.51.254 router, 86,400초 lease가 표시됩니다.

uart:~$
[00:00:00.060,000] <inf> phy_mii: PHY (0) ID 16F840

[00:00:00.170,000] <inf> phy_mii: PHY (0) Link speed 10 Mb, half duplex

[00:00:00.170,000] <inf> eth_smsc91x: MAC 00:02:f7:ef:37:16
*** Booting Zephyr OS build zephyr-v3.2.0-4300-g3e6505dba29e ***
[00:00:00.170,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
[00:00:00.180,000] <inf> net_dhcpv4_client_sample: Start on ethernet@9a000000: index=1
[00:00:07.180,000] <inf> net_dhcpv4: Received: 172.20.51.1
[00:00:07.180,000] <inf> net_dhcpv4_client_sample:    Address[1]: 172.20.51.1
[00:00:07.180,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
[00:00:07.180,000] <inf> net_dhcpv4_client_sample:     Router[1]: 172.20.51.254
[00:00:07.180,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 86400 seconds

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.