1.. _networking_with_native_sim:
2
3Networking with native_sim board
4################################
5
6.. contents::
7    :local:
8    :depth: 2
9
10This page describes how to set up a virtual network between a (Linux) host
11and a Zephyr application running in a :ref:`native_sim <native_sim>` board.
12
13In this example, the :zephyr:code-sample:`sockets-echo-server` sample application from
14the Zephyr source distribution is run in native_sim board. The Zephyr
15native_sim board instance is connected to a Linux host using a tuntap device
16which is modeled in Linux as an Ethernet network interface.
17
18Prerequisites
19*************
20
21On the Linux Host, fetch the Zephyr ``net-tools`` project, which is located
22in a separate Git repository:
23
24.. code-block:: console
25
26   git clone https://github.com/zephyrproject-rtos/net-tools
27
28
29Basic Setup
30***********
31
32For the steps below, you will need three terminal windows:
33
34* Terminal #1 is terminal window with net-tools being the current
35  directory (``cd net-tools``)
36* Terminal #2 is your usual Zephyr development terminal,
37  with the Zephyr environment initialized.
38* Terminal #3 is the console to the running Zephyr native_sim
39  instance (optional).
40
41Step 1 - Create Ethernet interface
42==================================
43
44Before starting native_sim with network emulation, a network interface
45should be created.
46
47In terminal #1, type:
48
49.. code-block:: console
50
51   ./net-setup.sh
52
53You can tweak the behavior of the net-setup.sh script. See various options
54by running ``net-setup.sh`` like this:
55
56.. code-block:: console
57
58   ./net-setup.sh --help
59
60
61Step 2 - Start app in native_sim board
62======================================
63
64Build and start the ``echo_server`` sample application.
65
66In terminal #2, type:
67
68.. zephyr-app-commands::
69   :zephyr-app: samples/net/sockets/echo_server
70   :host-os: unix
71   :board: native_sim
72   :goals: run
73   :compact:
74
75
76Step 3 - Connect to console (optional)
77======================================
78
79The console window should be launched automatically when the Zephyr instance is
80started but if it does not show up, you can manually connect to the console.
81The native_sim board will print a string like this when it starts:
82
83.. code-block:: console
84
85   UART connected to pseudotty: /dev/pts/5
86
87You can manually connect to it like this:
88
89.. code-block:: console
90
91   screen /dev/pts/5
92