1.. zephyr:code-sample:: telnet-console
2   :name: Telnet console
3   :relevant-api: shell_api net_core net_if net_mgmt
4
5   Access Zephyr shell over telnet.
6
7Overview
8********
9
10This application will setup IPv4/IPv6 addresses on the default
11network interface. The telnet console service is started transparently
12by the kernel, along with the shell and two shell modules: net and kernel.
13Once up and running, you can connect to the target over the network,
14using a telnet client.
15
16Requirements
17************
18
19- :ref:`networking_with_qemu`
20
21
22Building and Running
23********************
24
25QEMU x86
26========
27
28These are instructions for how to use this sample application using
29QEMU on a Linux host connected to a network with DHCP service.
30
31To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.
32
33Run Zephyr samples/net/telnet application in QEMU:
34
35.. zephyr-app-commands::
36   :zephyr-app: samples/net/telnet
37   :host-os: unix
38   :board: qemu_x86
39   :goals: run
40   :compact:
41
42Once started, you should see you IP address details for example:
43
44.. code-block:: console
45
46    [Setup] [INF] main: Starting Telnet sample
47    [Setup] [INF] setup_ipv4: IPv4 address: 192.0.2.1
48    [Setup] [INF] setup_ipv6: IPv6 address: 2001:db8::1
49
50At this point, your QEMU guest is up and running. Connect to the telnet
51console from your linux host this way:
52
53.. code-block:: console
54
55    $ telnet 192.0.2.1
56    Telnet escape character is '^]'.
57    Trying 192.0.2.1...
58    Connected to 192.0.2.1.
59    Escape character is '^]'.
60
61Now type enter, the shell prompt will appear and you can enter commands,
62for example ``help``.
63
64
65Freedom-K64F Board
66===================
67
68These are instructions for how to use this sample application running on a
69Freedom-K64F board. Unlike running it on QEMU, :ref:`Freedom-K64F board
70<frdm_k64f>` network configuration for IPv4 will rely on DHCPv4. You cad modify
71the :file:`prj_frdm_k64f.conf` to set static IPv4 addresses if it is really needed.
72
73For detailed instructions about building, flashing and using the serial console
74logs, follow the  :ref:`Freedom-K64F board <frdm_k64f>` documentation section.
75
76Connect ethernet cable from :ref:`Freedom-K64F <frdm_k64f>` board to a
77local network providing IPv4 address configuration via DHCPv4. Creating your own
78DHCP server on a local network is not in the scope of this README.
79
80Build Zephyr samples/net/telnet application:
81
82.. zephyr-app-commands::
83   :zephyr-app: samples/net/telnet
84   :board: frdm_k64f
85   :goals: build
86   :compact:
87
88Flash the resulting Zephyr binary following the :ref:`Freedom-K64F <frdm_k64f>`
89board documentation noted above.
90
91From your host computer, open a serial console to your board:
92
93.. code-block:: console
94
95    $ sudo screen /dev/ttyACM0 115200
96
97Plug the Ethernet cable to the :ref:`Freedom-K64F <frdm_k64f>` board.
98Reset the board, you should see first on the console:
99
100.. code-block:: console
101
102    [dev/eth_mcux] [INF] eth_0_init: Enabled 100M full-duplex mode.
103    [dev/eth_mcux] [DBG] eth_0_init: MAC 00:04:9f:69:c7:36
104    shell> [Setup] [INF] main: Starting Telnet sample
105    [Setup] [INF] setup_dhcpv4: Running dhcpv4 client...
106    [Setup] [INF] setup_ipv6: IPv6 address: 2001:db8::1
107
108And if the DHCPv4 client succeeds, you will soon see something like:
109
110.. code-block:: console
111
112   [Setup] [INF] ipv4_addr_add_handler: IPv4 address: 192.168.0.21
113   [Setup] [INF] ipv4_addr_add_handler: Lease time: 86400 seconds
114   [Setup] [INF] ipv4_addr_add_handler: Subnet: 255.255.255.0
115   [Setup] [INF] ipv4_addr_add_handler: Router: 192.168.0.1
116
117The above result depends on your local network.
118At this point you should be able to connect via telnet over the network.
119On your linux host:
120
121.. code-block:: console
122
123    $ telnet 192.168.0.21
124    Telnet escape character is '^]'.
125    Trying 192.168.0.21...
126    Connected to 192.168.0.1.
127    Escape character is '^]'.
128
129You are now connected, and as for the UART console, you can type in
130your commands and get the output through your telnet client.
131