<a id="network-create"></a>

# How to create a network

To create a managed network, use the [`lxc network`](https://canonical.com/lxd/docs/default/reference/manpages/lxc/network/index.html.md#lxc-network-md) command and its subcommands.
Append `--help` to any command to see more information about its usage and available flags.

<a id="network-types"></a>

## Network types

The following network types are available:

| Network type   | Documentation                                                                    | Configuration options                                                                         |
|----------------|----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| `bridge`       | [Bridge network](https://canonical.com/lxd/docs/default/reference/network_bridge/index.html.md#network-bridge)     | [Configuration options](https://canonical.com/lxd/docs/default/reference/network_bridge/index.html.md#network-bridge-options)   |
| `ovn`          | [OVN network](https://canonical.com/lxd/docs/default/reference/network_ovn/index.html.md#network-ovn)           | [Configuration options](https://canonical.com/lxd/docs/default/reference/network_ovn/index.html.md#network-ovn-options)      |
| `macvlan`      | [Macvlan network](https://canonical.com/lxd/docs/default/reference/network_macvlan/index.html.md#network-macvlan)   | [Configuration options](https://canonical.com/lxd/docs/default/reference/network_macvlan/index.html.md#network-macvlan-options)  |
| `sriov`        | [SR-IOV network](https://canonical.com/lxd/docs/default/reference/network_sriov/index.html.md#network-sriov)      | [Configuration options](https://canonical.com/lxd/docs/default/reference/network_sriov/index.html.md#network-sriov-options)    |
| `physical`     | [Physical network](https://canonical.com/lxd/docs/default/reference/network_physical/index.html.md#network-physical) | [Configuration options](https://canonical.com/lxd/docs/default/reference/network_physical/index.html.md#network-physical-options) |

## Create a network

CLI

Use the following command to create a network:

```bash
lxc network create <name> --type=<network_type> [configuration_options...]
```

See [Network types](#network-types) for a list of available network types and links to their configuration options.

If you do not specify a `--type` argument, the default type of `bridge` is used.

<a id="id2"></a>

### Create a network in a cluster

If you are running a LXD cluster and want to create a network, you must create the network for each cluster member separately.
The reason for this is that the network configuration, for example, the name of the parent network interface, might be different between cluster members.

Therefore, you must first create a pending network on each member with the `--target=<cluster_member>` flag and the appropriate configuration for the member.
Make sure to use the same network name for all members.
Then create the network without specifying the `--target` flag to actually set it up.

For example, the following series of commands sets up a physical network with the name `UPLINK` on three cluster members:

`user@host:~$ ``lxc network create UPLINK --type=physical parent=br0 --target=vm01`
```text
Network UPLINK pending on member vm01
```

`user@host:~$ ``lxc network create UPLINK --type=physical parent=br0 --target=vm02`
```text
Network UPLINK pending on member vm02
```

`user@host:~$ ``lxc network create UPLINK --type=physical parent=br0 --target=vm03`
```text
Network UPLINK pending on member vm03
```

`user@host:~$ ``lxc network create UPLINK --type=physical`
```text
Network UPLINK created
```

Also see [How to configure networks for a cluster](https://canonical.com/lxd/docs/default/howto/cluster_config_networks/index.html.md#cluster-config-networks).

UI

From the main navigation, select Networks.

On the resulting page, click Create network in the upper-right corner.

You can then configure the network name and type, as well as other attributes. Optional additional attributes are split into the categories Bridge, IPv4, IPv6 and DNS, which can be seen in the submenu on the right.

Click Create to create the network.

![Create a network in LXD](images/networks/network_create.png)

<a id="network-attach"></a>

## Attach a network to an instance

CLI

After creating a managed network, you can attach it to an instance as a [NIC device](https://canonical.com/lxd/docs/default/reference/devices_nic/index.html.md#devices-nic).

To do so, use the following command:

```none
lxc network attach <network_name> <instance_name> [<device_name>] [<interface_name>]
```

The device name and the interface name are optional, but we recommend specifying at least the device name.
If not specified, LXD uses the network name as the device name, which might be confusing and cause problems.
For example, LXD images perform IP auto-configuration on the `eth0` interface, which does not work if the interface is called differently.

For example, to attach the network `my-network` to the instance `my-instance` as `eth0` device, enter the following command:

```none
lxc network attach my-network my-instance eth0
```

UI

When [creating](https://canonical.com/lxd/docs/default/howto/instances_create/index.html.md#instances-create) or [configuring an instance](https://canonical.com/lxd/docs/default/howto/instances_configure/index.html.md#instances-configure), go to the Devices section in the left-hand submenu, then select Network to view and edit the networks linked to the instance.

![Add a network to an instance in LXD](images/networks/network_add_to_instance.png)

Click the Attach network button to add a new network. From here, you can select an existing network from the Network dropdown and assign it a device name.

![Attach a network to an instance in LXD](images/networks/network_attach_instance.png)

If configuring an instance, select Save changes to save your changes. If creating an instance, select Create to create your instance.

### Attach the network as a device

The [`lxc network attach`](https://canonical.com/lxd/docs/default/reference/manpages/lxc/network/attach/index.html.md#lxc-network-attach-md) command is a shortcut for adding a NIC device to an instance.
Alternatively, you can add a NIC device based on the network configuration in the usual way:

```none
lxc config device add <instance_name> <device_name> nic network=<network_name>
```

When using this way, you can add further configuration to the command to override the default settings for the network if needed.
See [NIC device](https://canonical.com/lxd/docs/default/reference/devices_nic/index.html.md#devices-nic) for all available device options.
