> Source: https://docs.cyberelements.io/bastion/4.7/hr/Usage/Configuration/EdgeGateway/ConnectAnEdgeGatewayWithPairingToken/

# Connecting an Edge Gateway using the pairing mechanism

> **Information**
>
> The pairing connection method works the same way for an Edge Gateway as it does for an HTML5 Gateway.

> **Prerequisites**
>
> SSH or console access with the `root` user to the Edge Gateway is required.
>
> In order for the Edge Gateway pairing to be successful, the `ipdiva-gateway-setup` package must be installed on the machine. All CyberElements Bastion virtual appliances (version 4.6 or later) have the package.
> If the Systancia repository is correctly configured, the following command will check for the presence of the package and attempt to install it if necessary:
>
> ```
> 1
> ```

> **Certificate of the Mediation Controller**
>
> Pairing contacts the Mediation Controller over HTTPS and checks its web certificate. If this certificate is issued by a certification authority that the Edge Gateway server does not recognise, pairing fails: [add this authority to the trusted CAs of the Edge Gateway](https://docs.cyberelements.io/bastion/4.7/hr/Usage/Configuration/EdgeGateway/AddANewTrustedCertificationAuthority/#global-addition-to-debian) before pairing, or use the unsecured mode (`-k`, see below).

Connect to the Edge Gateway server via SSH or console mode with the `root` user and run the pairing command of an Edge Gateway or HTML5 Gateway.

## Build the command

Fill in the values and tick the options you need in the table: the command updates as you type and is copied with the button of the code block. A refused value turns red and is not taken into the command. Each option is detailed after the command.

| Value or activation | Option | Role |
|---|---|---|
|  | `-s` | DNS name or IP address of the Mediation Controller (required). |
|  | `-t` | Pairing token (required). |
|  | `-n` | Suffix of the instance name (optional). |
|  | `-x` | URL of the proxy (optional, see [Proxy](#proxy)). |
|  | `-k` | Unsecured mode: the web certificate of the Mediation Controller is not checked. |
|  | `--no-care` | The recording service certificate is not installed. |
|  | `--noproxy` | No proxy, even if one is set in the environment. |
|  | `--cleanroom-infra` | Edge Gateway of the main database (see [below](#cleanroom-infra)). |
|  | `-v` | Verbose mode. |

```
1
```

Here are the details of the different options:

- `-s`: defines the DNS name of the Mediation Controller; an IP address can be used but will most likely require the use of unsecured mode.
- `-t`: defines the pairing token to be used ([generation of a pairing token](https://docs.cyberelements.io/bastion/4.7/hr/Usage/Configuration/AdminConsole/CreatePairingTokenForEdgeGateway/)).
- `-k`: activation of unsecured mode, in which the validity check of the Mediation Controller's web certificate is disabled. This setting should not be used systematically, only in contexts where it is necessary and where the presence of a MITM attacker has been ruled out (validation of a web certificate to ensure the identity of the server contacted).
- `-n`: definition of the suffix of the Edge Gateway instance name on the machine; if not defined, the main instance name, `gateway` or `html5gateway`, will be used. Only specify a name containing numbers, letters, or the special characters `-` or `_`. For the first connection of an Edge Gateway or HTML5 Gateway to the server, it is recommended not to set the `-n` parameter.
- `--no-care`: the pairing will not attempt to install the recording service certificate.
- `-v`: activation of verbose mode to obtain more information about the pairing process.
- `-x` or `--proxy`: URL of the proxy to use to reach the Mediation Controller (see below).
- `--noproxy`: no proxy is used, even if one is set in the environment.
- `--cleanroom-infra`: pairs an Edge Gateway of the main database, with a token generated on the Mediation Controller (see below).

> **If the pairing fails**
>
> The message `Failed to reach the server` does not give the cause of the failure: run the command again with the `-v` option to display it (for example `CERTIFICATE_VERIFY_FAILED` when the web certificate of the Mediation Controller is not recognised).

Once paired, the Edge Gateway connects to the SSL Router of the Mediation Controller: in the administration console, the status icon in front of its name, in the list of Edge Gateways, shows it connected.

> **Mediation Controller behind NAT**
>
> When the log of the Edge Gateway (`/var/log/IPdivaGateway.log`) shows `the peer certificate is only valid for …`, the address through which it reaches the SSL Router (typically an address translated by NAT) is not a name of the certificate of the Mediation Controller: declare the accepted names in `cert-peernames` ([`<ssl>` section of `gateway.xml`](https://docs.cyberelements.io/bastion/4.7/hr/Usage/Reference/ConfigurationFiles/EdgeGateway/GatewayXml/#ssl)).

> **Examples**
>
> To install the first Edge Gateway instance on a machine, the following command would be sufficient:
>
> ```
> 1
> ```
>
> However, if access to the Mediation Controller server is only possible with an IP address whose web certificate is not suitable, then unsecured mode must be enabled (preferably used when the connection does not pass through the public network):
>
> ```
> 1
> ```
>
> If a first instance of Edge Gateway is already present on the machine, then it would be necessary to create a new instance without modifying the recording service certificate:
>
> ```
> 1
> ```
>
> The previous command, by creating a new instance named `gateway-instance-2` (Edge Gateways automatically take the prefix `gateway-` while HTML5 Gateways take the prefix `html5gateway-`), also creates new directories for:
>
> - Manage instance settings using the `/etc/ipdiva/gateway-instance-2/` directory.
> - Start, stop, or restart the instance using the scripts in the `/usr/local/ipdiva/gateway-instance-2/bin/` directory.

## Proxy

Without any option, pairing uses the proxy set in the environment (`HTTPS_PROXY` variable, or else `HTTP_PROXY`), if there is one; `-x` imposes another one, `--noproxy` uses none. The proxy retained is written into the Edge Gateway configuration, which then uses it for its connections to the Mediation Controller. The accepted schemes are `http`, `https`, `socks4` and `socks5`; a domain login is written with `%5C` instead of the backslash:

```
1
2
```

## Edge Gateway of the main database

An Edge Gateway used to reach the main database of the Mediation Controller belongs to the `cleanroom_infra` virtual organisation and is not paired with a token from the administration console: its token is generated on the Mediation Controller, and the `--cleanroom-infra` option sends it to the pairing address of the infrastructure. The full procedure is described in [Main database through Edge Gateways](https://docs.cyberelements.io/bastion/4.7/hr/Usage/Reference/ConfigurationFiles/MediationController/DatabaseSettings/#main-database-through-edge-gateways).

```
1
```
