> For the complete documentation index, see [llms.txt](https://docs.enginsight.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enginsight.com/docs/knowledge-base/english/database/what-changes-do-i-need-to-make-if-the-ip-address-of-my-enginsight-database-changes.md).

# What changes do I need to make if the IP address of my Enginsight database changes?

If the IP address of your Enginsight database changes, you need to make several changes to your database configuration. The following steps show you what these changes are and what else you need to adjust.

{% stepper %}
{% step %}

### Stop the Enginsight Application Server

{% hint style="danger" %}
**Please note**: This step is *mandatory* before making any changes to the database.
{% endhint %}

1. Log in to the Enginsight Application Server and navigate to the Enginsight installation directory using the following command:

```
cd /opt/enginsight/enterprise
```

2. Now stop the Application Server using the following command:

```
sudo docker-compose down
```

{% endstep %}

{% step %}

### Create a database backup

Log in to the Enginsight Database Server and perform a MongoDB dump.

{% hint style="warning" %}
**Please note**: The commands required for a MongoDB dump may vary, for example if your database is secured via SSL/TLS.
{% endhint %}

{% hint style="success" icon="lightbulb-exclamation" %}
For more information about available MongoDB dump options, see the Knowledge Base: [How do I create a backup of my Enginsight instance?](/docs/knowledge-base/english/database/how-do-i-create-a-backup-of-my-enginsight-instance.md)
{% endhint %}
{% endstep %}

{% step %}

### Comment out the replica set configuration

In Enginsight, the replica set configuration is based on IP addresses. Since the IP address of the database will change, the replica set must be reinitialized after the IP address has been changed.

Reinitialization requires that the replica set is disabled first. This is best done at the beginning so that you can avoid inconsistencies caused by faulty replication in the following steps.

1. Open the MongoDB configuration file `mongod.conf` using the following command:

```
sudo nano /etc/mongod.conf
```

2. Navigate to the `replication` section:

```
replication:
  replSetName: "rs0"
```

3. Add a hash character **#** in front of the relevant lines to comment them out:

```
# replication:
#   replSetName: "rs0"
```

4. Save the changes to the configuration file (**Ctrl** + **o**) and confirm the save process. Close the file (**Ctrl** + **x**).
   {% endstep %}

{% step %}

### Delete the replica set in the local database

Because the replica set configuration exists both in `/etc/mongod.conf` and internally in the `local` database, the existing internal database configuration of the replica set must now also be reset after it has been disabled in the MongoDB configuration file `mongod.conf`.

1. Use the following commands to navigate to the MongoDB shell `mongosh` and from there to the local database `local`:

```
sudo mongosh
use local
```

2. Now reset the local database using the following command (this does **not** delete the Enginsight database!):

```
db.dropDatabase()
```

{% endstep %}

{% step %}

### Restart MongoDB

Restart MongoDB using the following command to apply the changes:

```
sudo systemctl restart mongodb
```

{% endstep %}

{% step %}

### Assign the new IP address

1. Open the network configuration file using the following command:

```
sudo nano /etc/network/interfaces
```

2. Enter the new IP address of the database.

<pre><code>iface ens19 inet static
<strong>    address &#x3C;IPAddress>
</strong><strong>    netmask &#x3C;Netmask>
</strong></code></pre>

{% hint style="info" %}
**Please note**: The interface name shown here (`ens19`) is only an example and may be different in your environment. In addition to the `address` and `netmask` parameters, other parameters may also need to be set, for example `gateway`. You can find the complete documentation in the [Debian Wiki](https://wiki.debian.org/NetworkConfiguration) and on the [`man` page](https://manpages.debian.org/trixie/ifupdown/interfaces.5.en.html).
{% endhint %}

3. Save the changes to the configuration file (**Ctrl** + **o**) and confirm the save process. Close the file (**Ctrl** + **x**).
   {% endstep %}

{% step %}

### Restart the Database Server

Restart the Database Server using the following command to activate the new network configuration:

```
sudo reboot
```

{% endstep %}

{% step %}

### Revert the commented-out replica set

You now need to revert the replica set that was commented out in step 3.

1. Open the MongoDB configuration file `mongod.conf` using the following command:

```
sudo nano /etc/mongod.conf
```

2. Navigate to the `# replication` section and remove both **#** characters:

```
replication:
  replSetName: "rs0"
```

3. Save the changes to the configuration file (**Ctrl** + **o**) and confirm the save process. Close the file (**Ctrl** + **x**).
   {% endstep %}

{% step %}

### Restart MongoDB

Restart MongoDB using the following command to apply the changes:

```
sudo systemctl restart mongodb
```

{% endstep %}

{% step %}

### Reinitialize the replica set

1. Navigate to the MongoDB shell using the following command:

```
sudo mongosh
```

2. Reinitialize the replica set using the following command:

```
rs.initiate( {
   _id : "rs0",
   members: [
      { _id: 0, host: "<DatabaseServerIPAddress>:27017" }
   ]
})
```

{% hint style="info" %}
Remember to replace `<DatabaseServerIPAddress>` with the IP address of the Database Server that is reachable from the Application Server.
{% endhint %}

3. Now check whether the replica set is active using the following command:

```
rs.status()
```

If the configuration is correct, the following prompt is displayed after running the command:

```
rs0:PRIMARY>
```

{% endstep %}

{% step %}

### Adjust the iptables file

1. Open the iptables file using the following command:

```
sudo nano /etc/iptables/rules.v4
```

2. Change the IP addresses according to the new network requirements, for example:

```
-A INPUT -s <NewDatabaseServerIPAddress>/32 -p tcp -m tcp --dport 27017 -j ACCEPT
```

3. Save the changes to the configuration file (**Ctrl** + **o**) and confirm the save process. Close the file (**Ctrl** + **x**).
   {% endstep %}

{% step %}

### Apply the changes on the application server

1. Go back to the Application Server and navigate to the Enginsight installation directory using the following command:

```
cd /opt/enginsight/enterprise
```

2. Run the setup script for the application server anew using the following command:

```
sudo ./setup.sh
```

3. When prompted for the URIs and URLs, enter the **MongoDB URI** as follows:\
   `mongodb://mongoDefaultUser:<MongoDBPassword>@<NewDatabaseServerIPAddress>:27017/enginsight?authSource=enginsight&replicaSet=rs0`

{% hint style="info" %}
Remember to replace `<MongoDBPassword>` and `<NewDatabaseServerIPAddress>` accordingly.\
You can also find the MongoDB password in the `/home/ngsapp/mongoDefaultUserPassword` directory.
{% endhint %}
{% endstep %}
{% endstepper %}

***
