# Source: host-wireless-network.adoc

*Note: This file could not be automatically converted from AsciiDoc.*

== Host a wireless network from your Raspberry Pi

Your Raspberry Pi can host its own wireless network using a wireless module. If you connect your Raspberry Pi to the internet via the Ethernet port (or a second wireless module), other devices connected to the wireless network can access the internet through your Raspberry Pi.

Consider a wired network that uses the `10.x.x.x` IP block. You can connect your Raspberry Pi to that network and serve wireless clients on a separate network that uses another IP block, such as `192.168.x.x`.

In the diagram below, note that the laptop exists in an IP block separate from the router and wired clients:

image::images/host-a-network.png[]


With this network configuration, wireless clients can all communicate with each other through the Raspberry Pi router. However, clients on the wireless network cannot directly interact with clients on the wired network other than the Raspberry Pi; wireless clients exist in a private network separate from the network that serves wired clients.

NOTE: The Raspberry Pi 5, 4, 3, Zero W, and Zero 2 W can host a wireless network using the built-in wireless module. Raspberry Pi models that lack a built-in module support this functionality using a separate wireless dongle.

=== Enable hotspot

To create a hosted wireless network on the command line, run the following command, replacing the `<example-network-name>` and `<example-password>` placeholders with your own values:

[source,console]
----
$ sudo nmcli device wifi hotspot ssid <example-network-name> password <example-password>
----

Use another wireless client, such as a laptop or smartphone, to connect to the network. Look for a network with a SSID matching `<example-network-name>`. Enter your network password, and you should connect successfully to the network. If your Raspberry Pi has internet access via an Ethernet connection or a second wireless adapter, you should be able to access the internet.

=== Disable hotspot

To disable the hotspot network and resume use of your Pi as a wireless client, run the following command:

[source,console]
----
$ sudo nmcli device disconnect wlan0
----

After disabling the network, run the following command to reconnect to another Wi-Fi network:

[source,console]
----
$ sudo nmcli device up wlan0
----

TIP: For more information about connecting to wireless networks, see xref:configuration.adoc#networking[Configure networking].

=== Use your Raspberry Pi as a network bridge

By default, the wireless network hosted from your Raspberry Pi exists separately from the parent network connected via Ethernet. In this arrangement, devices connected to the parent network cannot directly communicate with devices connected to the wireless network hosted from your Raspberry Pi. If you want connected wireless devices to be able to communicate with devices on the parent network, you can configure your Raspberry Pi as a https://en.wikipedia.org/wiki/Network_bridge[network bridge]. With a network bridge in place, each device connected to the Pi-hosted wireless network is assigned an IP address in the parent network.

In the diagram below, the laptop exists in the same IP block as the router and wired clients:

image::images/bridge-network.png[]

The following steps describe how to set up a network bridge on your Raspberry Pi to enable communication between wireless clients and the parent network.

First, create a network bridge interface:

[source,console]
----
$ sudo nmcli connection add type bridge con-name 'Bridge' ifname bridge0
----

Next, add your device's Ethernet connection to the parent network to the bridge:

[source,console]
----
$ sudo nmcli connection add type ethernet slave-type bridge \
    con-name 'Ethernet' ifname eth0 master bridge0
----

Finally, add your wireless hotspot connection to the bridge. You can either add an existing hotspot interface or create a new one:

* If you have already created a wireless hotspot connection using the instructions above, add the existing interface to the bridge with the following command:
+
[source,console]
----
$ sudo nmcli connection modify 'Hotspot' master bridge0
----

* If you have not yet created a wireless hotspot connection, create a new interface and add it to the bridge with a single command, replacing the `<hotspot-ssid>` and `<hotspot-password>` placeholders with a network name and password of your choice, respectively:
+
[source,console?prompt=$]
----
$ sudo nmcli connection add con-name 'Hotspot' \
    ifname wlan0 type wifi slave-type bridge master bridge0 \
    wifi.mode ap wifi.ssid <hotspot-ssid> wifi-sec.key-mgmt wpa-psk \
    wifi-sec.proto rsn wifi-sec.pairwise ccmp \
    wifi-sec.psk <hotspot-password>
----


Now that you've configured your bridge, it's time to activate it. Run the following command to activate the bridge:

[source,console]
----
$ sudo nmcli connection up Bridge
----

And run the following command to start hosting your wireless network:

[source,console]
----
$ sudo nmcli connection up Hotspot
----

You can use the `nmcli device` command to verify that the bridge, Ethernet interface, and wireless hotspot interface are all active.

TIP: Use a tool such as https://github.com/royhills/arp-scan[arp-scan] to check if devices on the parent network are accessible once connected to the hotspot.