# Create a Managed Private Network

You can create a managed Private Network through the Portal, the 
[CLI]({{< ref "/tools/command-line-interface/" >}}), or using tools like Terraform. 

In this example, we will use the CLI:

```bash
exo compute private-network create managed-network \
    --zone ch-gva-2      \
    --start-ip 10.0.0.20 \
    --end-ip 10.0.0.200  \
    --netmask 255.255.255.0
```

Output:

```bash
 ✔ Creating Private Network "managed-network"... 3s
┼─────────────────┼──────────────────────────────────────┼
│ PRIVATE NETWORK │                                      │
┼─────────────────┼──────────────────────────────────────┼
│ ID              │ 0f621ed0-a161-4c9a-a533-51c8e3504a13 │
│ Name            │ managed-network                      │
│ Description     │                                      │
│ Zone            │ ch-gva-2                             │
│ Type            │ managed                              │
│ Start IP        │ 10.0.0.20                            │
│ End IP          │ 10.0.0.200                           │
│ Netmask         │ 255.255.255.0                        │
│ Leases          │ -                                    │
┼─────────────────┼──────────────────────────────────────┼
```

The `--start-ip`, `--end-ip` and `--netmask` flags allow you to define the IP range of your Private Network:

Some values are forbidden:

- the IP address for `--start-ip` must be lower than the `--end-ip`, and cannot be the network address.
- the IP address for `--end-ip` cannot be the network broadcast address or the last IP of the network, because this IP will be the IP address of the DHCP server.
- you cannot shrink the network range, you can only increase it. For example, `exo compute private-network update <NETWORK> --end-ip 10.0.0.230` will increase the network range.

In this example, the DHCP server will assign IP addresses between `10.0.0.20` and `10.0.0.200` to the network interfaces. This means that you can only have at most 180 machines in this network.


### Static IP addresses
You can assign static IP addresses to private interfaces. The IP address must be in the network range, but not necessarily in the network IP range.

For example, you will be able to assign static IP addresses between `10.0.0.1` and `10.0.0.253` for the network defined above. The IP address must not be already used by a network interface.

Using the `exo` CLI, you have two ways to configure a static IP address on your Private Network interface:

* Specify the static IP address with the `--ip` flag when attaching your instance to a managed Private Network by running the `exo compute instance private-network attach` command.
* Run the `exo compute instance private-network update-ip` command.


### Interfaces configuration
On Debian and Ubuntu, you will need to configure the corresponding network
interface(s) - e.g. `eth1` - for DHCP.


#### Ubuntu >= 18.04 (Bionic) [netplan]
In `/etc/netplan/eth1.yaml`:

```yaml
network:
  version: 2
  ethernets:
    eth1:
      dhcp4: true
```

Followed by `sudo netplan apply` to bring the interface up.


#### Debian and Ubuntu < 18.04 [ifconfig]
In `/etc/network/interfaces.d/eth1.conf`:

```bash
allow-hotplug eth1
iface eth1 inet dhcp
```

Followed by `ifup eth1` to bring the interface up.


#### Using Cloud-Init (for Debian or Ubuntu)
To automate your Private Network setup, you may include the ad-hoc configuration
in your Compute instance's [user-data]({{< ref "/product/compute/instances/how-to/cloud-init-user-data/" >}}), e.g. for `netplan` (Ubuntu 18.04):

```yaml
#cloud-config
write_files:
  - path: /etc/netplan/eth1.yaml
    content: |
      network:
        version: 2
        ethernets:
          eth1:
            dhcp4: true

runcmd:
  - [ netplan, apply ]
```

### Granular DHCP Options Support via the CLI
Exoscale's Managed Private Networks support granular DHCP configurations, providing enhanced control over network settings through the exo CLI.

- [DHCP Option 3] Default Gateway (Router): Sets the IP of the default gateway for external traffic.
- [DHCP Option 6] DNS Servers: Specifies DNS server IPs for domain name resolution.
- [DHCP Option 42] NTP Servers: Defines IPs for time synchronization with NTP servers.
- [DHCP Option 119] Domain Search List: Supplies a list of domain suffixes supporting multi-domain environments (limited to 255 octets).
