<blockquote>
  <p>I want to disconnect <em>both</em> nodes from each other.</p>
  
  <p>From Alice's Console, I use:</p>

<pre><code>addnode 127.0.0.1:18445 remove
</code></pre>
</blockquote>

<p>This is incorrect. This command will only remove Bob's node from the list of addnode'd peers. The correct command to actually disconnect Bob's node is</p>

<pre><code>disconnectnode "127.0.0.1:18445"
</code></pre>

<blockquote>
  <p>On Alice's node, the peer is:</p>
  
  <p><code>127.0.0.1:18445</code></p>
  
  <p>However, on Bob's node, the peer is</p>
  
  <p><code>127.0.0.1:57594</code></p>
  
  <p>but I expect it to be:</p>
  
  <p><code>127.0.0.1:18444</code></p>
</blockquote>

<p>Outbound connections are not made from the P2P port. Rather a random high numbered port is chosen to bind to and the outbound connection is made from there. IIRC this is done by the kernel and not the software itself. This behavior is standard for most software that make outbound connections.</p>

<blockquote>
  <p>I then try to disconnect Bob's node from Alice's node using the the Peers tab. Right click on peer (Bob) and choose disconnect.</p>
  
  <p>The node is disconnected for about 45 seconds, then reconnects.</p>
</blockquote>

<p>A connection is still being made because you did not remove the other node from both nodes (i.e. one node still has the other one in its peers database).</p>

<p>The proper way to do this would be to use the <code>onetry</code> option as that means that the node is not actually added to the peers database but rather tried once. To disconnect, you should be using the <code>disconnectnode</code> command.</p>

CC BY-SA 3.0
2017-12-26T00:00:49.173Z
0.15.1 has no `disconnectpeer` command. It does have a `disconnectnode` command. Using it, together with the `onetry` option for connecting did the trick.
Rich Apodaca
CC BY-SA 3.0
2017-12-26T02:36:48.827Z
Oh that's a mistake, I meant to write `disconnectnode`.
Ava Chow
CC BY-SA 3.0
2017-12-23T07:16:06.290Z
2017-12-26T02:36:57.893Z
2017-12-26T02:36:57.893Z
Ava Chow
<p><a href="https://github.com/bitcoin/bitcoin/issues/6901" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/issues/6901</a></p>

<p>I found this issue, could be helpful
if you are not being able to remove address what about "setban {bob's ip} add {bantime}"</p>

CC BY-SA 3.0
2017-12-19T19:49:38.653Z
I also found that issue. It was helpful in that it shows how to disconnect/ban through the GUI. However, the peer always reconnects when I do so.
Rich Apodaca
CC BY-SA 3.0
2017-12-20T04:49:46.447Z
since thats a regtest, you can delete the alice and bob node and recreate again
Niroj Shr
CC BY-SA 3.0
2017-12-19T05:09:13.343Z
2017-12-19T05:09:13.343Z
Niroj Shr
<p>Well I think a big problem might be in the lack of detail:</p>

<pre><code>addnode 127.0.0;1:18445 add
</code></pre>

<p>Try 127.0.0.1:18445 instead you have a semicolon before the last 1.</p>

<p>Also have you tried editing this in bitcoin.conf? Try adding the nodes in conf.</p>

CC BY-SA 3.0
2017-12-18T02:06:19.220Z
Also added nodes in bitcoin.conf using both addnode and connect. No difference in behavior.
Rich Apodaca
CC BY-SA 3.0
2017-12-14T15:48:09.510Z
Edited typo in post. No I have not tried adding nodes in bitcoin.conf. Why would doing so change the outcome?
Rich Apodaca
CC BY-SA 3.0
2017-12-14T08:38:56.747Z
2017-12-14T08:38:56.747Z
Ethan
<p>I'm trying to set up a private Bitcoin network using Bitcoin Core in regtest mode. However, there are two problems:</p>

<ol>
<li>the port reported by the Bitcoin Core GUI doesn't match the one the node is running at; and</li>
<li>when a peer is disconnected (or even banned) it re-connects automatically.</li>
</ol>

<p>Here's what I did. I create two folders, <code>alice</code> and <code>bob</code>. I then launch the GUI from the OSX Terminal:</p>

<pre><code># start Alice node
$ open -n /Applications/Bitcoin-Qt.app --args -regtest -datadir=/Users/{username}/Desktop/alice/ -port=18444

# start Bob node
$ open -n /Applications/Bitcoin-Qt.app --args -regtest -datadir=/Users/{username}/Desktop/bob/ -port=18445
</code></pre>

<p>From Alice's Console, I do:</p>

<pre><code>addnode 127.0.0.1:18445 add
</code></pre>

<p>This creates a connection to both nodes.</p>

<p>I want to disconnect <em>both</em> nodes from each other.</p>

<p>From Alice's Console, I use:</p>

<pre><code>addnode 127.0.0.1:18445 remove
</code></pre>

<p>On Alice's node, the peer is:</p>

<p><code>127.0.0.1:18445</code></p>

<p>However, on Bob's node, the peer is</p>

<p><code>127.0.0.1:57594</code></p>

<p>but I expect it to be:</p>

<p><code>127.0.0.1:18444</code></p>

<p>I try to remove Bob's node from Alice with:</p>

<p><code>addnode 127.0.0.1:18445 remove</code></p>

<p>Console returns <code>null</code> but doesn't remove the node.</p>

<p>When I try this from Alice's node:</p>

<p><code>addnode 127.0.0.1:57549 remove</code></p>

<p>I get <code>Error: Node has not been added. (code -24)</code></p>

<p>I then try to disconnect Bob's node from Alice's node using the the Peers tab. Right click on peer (Bob) and choose disconnect.</p>

<p>The node is disconnected for about 45 seconds, then reconnects.</p>

<p>To summarize, I have two questions:</p>

<ol>
<li>Why doesn't the port number on Bob's node match the port number I gave it?</li>
<li>How can I keep regtest nodes permanently disconnected for arbitrary periods of time and then reconnect them?</li>
</ol>

<bitcoin-core><network><regtest>
How are Bitcoin Core GUI nodes properly connected and disconnected in regtest mode?
Rich Apodaca
# How are Bitcoin Core GUI nodes properly connected and disconnected in regtest mode?

(Asked by: username_0 on 2017-12-14)

I'm trying to set up a private Bitcoin network using Bitcoin Core in regtest mode. However, there are two problems:

1. the port reported by the Bitcoin Core GUI doesn't match the one the node is running at; and
2. when a peer is disconnected (or even banned) it re-connects automatically.

Here's what I did. I create two folders, `alice` and `bob`. I then launch the GUI from the OSX Terminal:

```
# start Alice node
$ open -n /Applications/Bitcoin-Qt.app --args -regtest -datadir=/Users/{username}/Desktop/alice/ -port=18444

# start Bob node
$ open -n /Applications/Bitcoin-Qt.app --args -regtest -datadir=/Users/{username}/Desktop/bob/ -port=18445

```

From Alice's Console, I do:

```
addnode 127.0.0.1:18445 add

```

This creates a connection to both nodes.

I want to disconnect *both* nodes from each other.

From Alice's Console, I use:

```
addnode 127.0.0.1:18445 remove

```

On Alice's node, the peer is:

`127.0.0.1:18445`

However, on Bob's node, the peer is

`127.0.0.1:57594`

but I expect it to be:

`127.0.0.1:18444`

I try to remove Bob's node from Alice with:

`addnode 127.0.0.1:18445 remove`

Console returns `null` but doesn't remove the node.

When I try this from Alice's node:

`addnode 127.0.0.1:57549 remove`

I get `Error: Node has not been added. (code -24)`

I then try to disconnect Bob's node from Alice's node using the the Peers tab. Right click on peer (Bob) and choose disconnect.

The node is disconnected for about 45 seconds, then reconnects.

To summarize, I have two questions:

1. Why doesn't the port number on Bob's node match the port number I gave it?
2. How can I keep regtest nodes permanently disconnected for arbitrary periods of time and then reconnect them?

**Tags:** bitcoin-core, network, regtest


---

## 3 answers

### Answer by username_1 on 2017-12-23. Score: 2 | Accepted answer

> I want to disconnect *both* nodes from each other.
>
> From Alice's Console, I use:
>
> ```
> addnode 127.0.0.1:18445 remove
>
> ```

This is incorrect. This command will only remove Bob's node from the list of addnode'd peers. The correct command to actually disconnect Bob's node is

```
disconnectnode "127.0.0.1:18445"

```

> On Alice's node, the peer is:
>
> `127.0.0.1:18445`
>
> However, on Bob's node, the peer is
>
> `127.0.0.1:57594`
>
> but I expect it to be:
>
> `127.0.0.1:18444`

Outbound connections are not made from the P2P port. Rather a random high numbered port is chosen to bind to and the outbound connection is made from there. IIRC this is done by the kernel and not the software itself. This behavior is standard for most software that make outbound connections.

> I then try to disconnect Bob's node from Alice's node using the the Peers tab. Right click on peer (Bob) and choose disconnect.
>
> The node is disconnected for about 45 seconds, then reconnects.

A connection is still being made because you did not remove the other node from both nodes (i.e. one node still has the other one in its peers database).

The proper way to do this would be to use the `onetry` option as that means that the node is not actually added to the peers database but rather tried once. To disconnect, you should be using the `disconnectnode` command.

> **Comments:**
> **username_0**: 0.15.1 has no `disconnectpeer` command. It does have a `disconnectnode` command. Using it, together with the `onetry` option for connecting did the trick.  
> **username_1**: Oh that's a mistake, I meant to write `disconnectnode`.  

---

### Answer by username_2 on 2017-12-19. Score: 0

<https://github.com/bitcoin/bitcoin/issues/6901>

I found this issue, could be helpful
if you are not being able to remove address what about "setban {bob's ip} add {bantime}"

> **Comments:**
> **username_0**: I also found that issue. It was helpful in that it shows how to disconnect/ban through the GUI. However, the peer always reconnects when I do so.  
> **username_2**: since thats a regtest, you can delete the alice and bob node and recreate again  

---

### Answer by username_3 on 2017-12-14. Score: 0

Well I think a big problem might be in the lack of detail:

```
addnode 127.0.0;1:18445 add

```

Try 127.0.0.1:18445 instead you have a semicolon before the last 1.

Also have you tried editing this in bitcoin.conf? Try adding the nodes in conf.

> **Comments:**
> **username_0**: Edited typo in post. No I have not tried adding nodes in bitcoin.conf. Why would doing so change the outcome?  
> **username_0**: Also added nodes in bitcoin.conf using both addnode and connect. No difference in behavior.  

---

