<p>Yes, you would need two separate <code>cardano-node</code> processes, each with their own configuration and their own disk storage directory.</p>
<p>When using <code>cardano-cli</code>  you will need to connect to the correct local domain socket for the network you want to connect to.</p>
<p>Eg for mainnet:</p>
<pre><code>export CARDANO_NODE_SOCKET_PATH=/path/to/mainnet/db/node.socket
cardano-cli ....
</code></pre>
<p>or for testnet:</p>
<pre><code>export CARDANO_NODE_SOCKET_PATH=/path/to/testnet/db/node.socket
cardano-cli ....
</code></pre>

CC BY-SA 4.0
2022-04-22T13:48:54.063Z
Thanks for your answer! 
If I do that, every time I switch between `testnet` and `mainnet`, I need to update this socket variable `CARDANO_NODE_SOCKET_PATH`, it there a way that it can be done automatically?
I see some others suggest use two different linux accounts, it's essentially the same as changing this socket environment variable to me.
Cyrus
CC BY-SA 4.0
2022-04-23T04:03:21.713Z
You can write two trivial bash scripts, with `-mainnet` and `-testnet` in the names and setting the `CARDANO_NODE_SOCKET_PATH`.
Erik de Castro Lopo
CC BY-SA 4.0
2022-04-22T00:20:42.750Z
2022-04-22T00:20:42.750Z
Erik de Castro Lopo
<p>After searching for a while, didn’t find any post regarding this.</p>
<p>I know running node for <code>testnet</code> and <code>mainnet</code> use different configuring files, and on the cardano developer portal, they are showing the same port. But can I run both <code>testnet</code> and mainnet relay node on background (I assume I’d need to change the port number)?
Do I need to make two different cardano-run process?</p>
<p>In that case, it is ok when I run cardano-cli commands just change different network, like <code>testnet-magic ***</code>/<code>–mainnet</code>? Is the rest command the same?
I currently run the testnet as a systemd service, I can definitely just go ahead and run a <code>mainnet</code> node as another service on the background, but I want to ask before head, in case I would messed up the configurations on my server.</p>

<cardano-node>
How to run testnet node and mainnet node on background at the same time?
# How to run testnet node and mainnet node on background at the same time?

(Asked by: username_0 on 2022-04-21)

After searching for a while, didn’t find any post regarding this.

I know running node for `testnet` and `mainnet` use different configuring files, and on the cardano developer portal, they are showing the same port. But can I run both `testnet` and mainnet relay node on background (I assume I’d need to change the port number)?
Do I need to make two different cardano-run process?

In that case, it is ok when I run cardano-cli commands just change different network, like `testnet-magic ***`/`–mainnet`? Is the rest command the same?
I currently run the testnet as a systemd service, I can definitely just go ahead and run a `mainnet` node as another service on the background, but I want to ask before head, in case I would messed up the configurations on my server.

**Tags:** cardano-node

---

## 1 answers

### Answer by username_1 on 2022-04-22. Score: 3

Yes, you would need two separate cardano-node processes, each with their own configuration and their own disk storage directory.
When using cardano-cli  you will need to connect to the correct local domain socket for the network you want to connect to.
Eg for mainnet:
export CARDANO_NODE_SOCKET_PATH=/path/to/mainnet/db/node.socket
cardano-cli ....

or for testnet:
export CARDANO_NODE_SOCKET_PATH=/path/to/testnet/db/node.socket
cardano-cli ....

> **Comments:**
> **username_0**: Thanks for your answer!  If I do that, every time I switch between `testnet` and `mainnet`, I need to update this socket variable `CARDANO_NODE_SOCKET_PATH`, it there a way that it can be done automatically? I see some others suggest use two different linux accounts, it's essentially the same as changing this socket environment variable to me.  
> **username_1**: You can write two trivial bash scripts, with `-mainnet` and `-testnet` in the names and setting the `CARDANO_NODE_SOCKET_PATH`.  

---

