# The DMZ server

A DMZ server is a CrushMFT that stands in the outer network, where the internet reaches it, and has nothing worth stealing: no users, no files, no settings of its own. Everything it is asked, it passes to a server in the inner network, over a link that the **inner** server opened.

So the firewall between the two networks needs no opening from outside to inside at all. That is the whole point.

```
 internet          outer network (DMZ)         inner network

  users  ------->  +-------------+   <-------  +----------+
  SFTP, HTTPS,     |  DMZ server |    the link |  Server  | --- files, users
  FTPS ...         +-------------+             +----------+
                                      opened from inside
```

A DMZ needs an Enterprise licence. The licence is the inner server's; the DMZ gets it over the link.

## What is where

| | On the DMZ | On the server |
|---|---|---|
| the ports users connect to | yes | its own, for the inner network |
| the protocols: SFTP, FTPS, HTTPS, WebDAV | spoken here | |
| users and passwords | none: every login is passed inward and checked there | all |
| files | none: transfers stream through | all |
| the DMZ's settings | held in memory only | kept as a file, and sent to the DMZ when the link comes up |
| the TLS certificate and SSH host keys users see | held in memory, sent by the server | kept |
| a key of its own | yes: its [node identity](Cluster-Trust.md), which it never gives away | |

A DMZ that is taken apart yields its own key and what was in its memory: no user list, no files.

## How a request travels

A user connects to the DMZ by SFTP and asks for a folder. The DMZ speaks SFTP with the user, and asks the server for the listing over the link. The server answers; the DMZ hands the listing to the user as SFTP. Whatever protocol the user speaks, the DMZ and the server speak one form between them.

The login is the same: the DMZ passes the name and password inward, and the server says yes or no. Bans, two-factor codes, the user's folders and rights are all the server's.

## Starting a DMZ

On the machine in the outer network, install CrushMFT 27 and start it as a DMZ, naming the port it waits on for its server:

```
java -jar CrushMFT.jar -dmz 9000
```

A list of addresses behind the port limits who may connect to it as its server: `-dmz 9000 10.0.1.20`.

To run it as a service: `java -jar CrushMFT.jar -dmzi 9000` on Windows and macOS. On Linux, the start script has a line for the DMZ to use in place of the line for the server.

A DMZ that has no server yet does nothing for users. It waits, and prints a one-time code for pairing:

```
This DMZ is not paired. …
To pair it, open the admin page of your CrushMFT server: Cluster, Pair a DMZ, and enter
    Code:         CFE1-7K2M9Q-RT41XB-…
    Fingerprint:  3F9A-01C2-77B0-E4D5
The code works once and until 14:32. It is also in cluster/pairing_code.txt.
```

## Setting it up on the server

### 1. The DMZ's settings

A DMZ has settings of its own: its ports, its banner, its limits. They are kept on the **server**, in a file beside the server's own settings, named after the DMZ: `prefs_dmz1.XML` for a DMZ called `dmz1`.

The easiest start is a copy of a fresh server's settings file under that name. Afterwards the DMZ's settings are edited in the admin pages like the server's own: see step 4.

### 2. The DMZ port

In [Preferences, IP / Servers](Ports.md), add an item of the type **DMZ (DMZ://)**:

| Field | Is |
|---|---|
| **IP** | "The IP is the address of the DMZ server." |
| **Port** | "The port is the one you used when you started the DMZ server." |
| **Name** | "The name is required and must match the name in your DMZ preferences file: for prefs_dmztest.XML the name is dmztest." |
| the protocol version | **v6 Protocol**. The older ones are there for old installations: "Use only if it was recommended by CrushMFT Support." |
| **Pair in Server Admin** | leads to the pairing |

The page has a **DMZ tour** that walks through these fields.

### 3. Pairing

A DMZ and its server must know each other's keys before anything flows: [Pairing a DMZ](DMZ-Pairing.md). In CrushMFT 27 there is no unpaired way.

### 4. Looking after it

When the link is up, the server sends the DMZ its settings, the licence, the certificates and the host keys, and the DMZ opens its ports.

In Server Admin, the selector at the top right, which reads **Main**, now also offers the DMZ. Choosing it shows the DMZ's own dashboard and lets you edit the DMZ's ports and settings: you are working on the DMZ, through the server. The DMZ also has a tile on the [Cluster](Cluster.md) page, with **Open DMZ Dashboard**.

Users do not have to be made on the DMZ. The account that passes logins inward is made by itself.

## When the server is away

| Server setting | Does | Unless you change it |
|---|---|---|
| `stop_dmz_ports_internal_down` | on a DMZ: while the server that controls it does not answer, the DMZ closes its ports. A load balancer in front sees that and sends users elsewhere. Off: the ports stay open and every login fails. | true |
| `dmz_log_in_internal_server` | the DMZ's log lines are also passed to the server, so that both logs are in one place | false |

Also in [Preferences, Replication](Prefs-Replication.md#dmz) and [Preferences, Logging](Prefs-Logging.md#logging).

## More than one

- **Two DMZs, one server**: two DMZ ports on the server, each with its own name and settings file. A load balancer or DNS spreads users over the DMZs.
- **One DMZ, two servers**: both servers have a port for it. The DMZ is linked to one server at a time; the other stands by and takes it over when the first fails. With [ServerBeat](ServerBeat.md) and `serverbeat_dmz_master`, the holder of the shared address is the one that feeds the DMZs.
- **Two of each** is the usual shape of a highly available installation: see [High availability overview](High-Availability.md).

## What a DMZ may ask of its server

The DMZ is the machine most likely to be attacked, so the server answers it narrowly:

- for a login by SSH key it gets the keys to compare with, not the account with its password;
- it cannot get a login token for an account with admin rights;
- mail it relays through the server is limited: 300 in ten minutes per DMZ unless you set `dmz_relay_email_max_10min`.

And the DMZ runs nothing for anybody but a server whose key it holds.

## Things to know

- **The firewall** between the networks needs one rule: from the server to the DMZ's port. Nothing from the DMZ inward.
- **The link is encrypted**, and both ends are proven by their keys.
- **The server needs an HTTP port** in the inner network: the DMZ's requests arrive there.
- **Jobs on a DMZ.** A job's task can be made to connect from the DMZ, for partners who only accept connections from your public address: **Route connection through DMZ when possible** on the task. See [Conditions on a task](Jobs-Conditions.md#a-form-that-changes-with-the-address).
- **Alerts** raised on a DMZ are passed to the server, which sends the mail.
- **Updates.** Update the DMZ with its server. A DMZ on an older version than its server is shown as such on the Cluster page.
- **Version 5 links** of earlier versions cannot be paired, and a port set to version 5 links nothing: change it to version 6.
- **What was tried**, when the cluster was built, on test servers on one machine: a DMZ printed its code, was paired, refused strangers, and came back after restarts of either side without a new code. Nothing was run again for this page.
