user18345: I am having trouble using regtest mode on Linux.  Using pre-compiled version 0.9.2.1 for linux and starting regtest mode as instructed on bitcoin.org:
<bitcoin-ver>-linux/bin/64>> ./bitcoind -regtest -daemon

The server starts but doing a getinfo returns 'connections' : 0.  Tried experimenting with various rpc* settings in the .conf file.  What exactly do I need to set in order to use regtest mode?  Do I need to add real nodes via addnode for regtest?  It doesn't seem like I should need to.  I was able to get a few connections by adding several real nodes one time but after a few minutes 'connections' dropped back to 0.  Let me know if any additional info would help.

user29691: I would like to make an addition to above answers.
Instead of -connect=ip the correct option to use is -addnode=ip. -connect lets a node connect only to one node and whereas '-addnode' attempts at connecting to the specified list of nodes(ip) among other nodes.

user53: You need to run more than one node on your machine (you can do that if you give each node a different -port and -rpcport). And you need to tell them how to find each other (using -connect=127.0.0.1:portnumber).
There are examples written in bash and python in the Bitcoin Core source tree:
  https://github.com/bitcoin/bitcoin/tree/master/test/functional

user19410: In order to run multiple nodes in regtest mode on a single machine you will need to sandbox each node.
In this example I have three nodes, they are named Alice, Bob and Cory. Since Bitcoin is a Peer/Mesh network, my goal is to connect each nodes so that changes made to Cory are ultimately visible to Bob (without necessarily requiring a direct connection between the two.)
Step 1: Create folders for each node.
These folders will contain our data and configs for each node. The names are not important, they can be renamed later, so you can name them "Alice", "Bob" and "Cory" for now. Remember where you create them, you will need their paths for Step 3 below.
Step 2: In each folder, create a bitcoin.conf file
In the config files Alice will be configured to connect to Cory, and Bob will be configured to connect to Alice. In addition to configuring outbound connections, this is also where we specify regtest=1 and server=1 settings.
bitcoin.conf for Alice
regtest=1
server=1
 # Alice connects to Cory
connect=localhost:18333

bitcoin.conf for Bob
regtest=1
server=1
 # Bob connects to Alice
connect=localhost:18444

bitcoin.conf for Cory
regtest=1
server=1
 # Cory connects to nobody

Step 3: Start each node.
Note each node must have a different port number since only one node can bind to a port number at any time.

Alice on port 18444
Bob on port 18555
Cory on port 18333

You can choose your own port numbers of course, just be careful not to use a port number that is already in use by something else.
The command-line options will tell bitcoin what port number to use, where to store data, and where to find its config file:
Alice:
 "C:\Program Files\Bitcoin\bitcoin-qt.exe" -conf="C:\Alice\bitcoin.conf" -datadir="C:\Alice" -rpcport=18444
Bob:
"C:\Program Files\Bitcoin\bitcoin-qt.exe" -conf="C:\Bob\bitcoin.conf" -datadir="C:\Bob" -rpcport=18555
Cory:
"C:\Program Files\Bitcoin\bitcoin-qt.exe" -conf="C:\Cory\bitcoin.conf" -datadir="C:\Cory" -rpcport=18333
This will launch three instances of the Bitcoin Client, and the folders for each node will begin to initialize with regtest data.
Step 4: Testing
You can use the Help->Debug Window->Console option to interactively execute commands on any of the nodes. For example, you can mine 101 blocks with the following bitcoin console command:
setgenerate true 101
You should (after a few seconds) then have been awarded coins.
These mining activities result in coinbase transactions - and only the last one of 50 BTC is available to spend. Now you can send some BTC to one of the other nodes.  After a bit more mining such a transaction will be confirmed.
You can also use the console commands getpeerinfo and getinfo to check the network is set up correctly.  One of them (Cory with port=18333) should have 'sync=true' in its peerinfo output, and all nodes should have the same "block height" regardless of which node is used for mining.

user4993: Although I believe Fred Tingey's answer is complete, it has the following attributes:

it depends on a config file.
it provides examples for bitcoin-qt on the windows platform, and the OP was asking about bitcoind on the linux platform.

Thus, I wanted to share the following concise bash script which does what the OP wants. As others have partially noted the key to getting this to work is:

specify a unique port (if listening) and rpcport (if using rpc) for each node
specify a unique data directory for each node
if using -connect to restrict to own nodes, remember to use -listen to accept connections from own nodes.

That said, here's my start-regtest-network.sh script:
#!/bin/bash
bitcoind -server -listen -port=17591 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16591 -datadir=$HOME/regtest/A/ -connect=localhost:17592 -regtest -pid=$HOME/regtest/A/.pid -daemon -debug
bitcoind -server -listen -port=17592 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16592 -datadir=$HOME/regtest/B/ -connect=localhost:17593 -regtest -pid=$HOME/regtest/B/.pid -daemon -debug
bitcoind -server -listen -port=17593 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16593 -datadir=$HOME/regtest/C/ -connect=localhost:17594 -regtest -pid=$HOME/regtest/C/.pid -daemon -debug
bitcoind -server -listen -port=17594 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16594 -datadir=$HOME/regtest/D/ -connect=localhost:17595 -regtest -pid=$HOME/regtest/D/.pid -daemon -debug
bitcoind -server -listen -port=17595 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16595 -datadir=$HOME/regtest/E/ -connect=localhost:17591 -regtest -pid=$HOME/regtest/E/.pid -daemon -debug

Additionally, here's my stop-regtest-network.sh:
#!/bin/bash
sudo killall --regex bitcoin.*

I realize my stop script is sloppy, and will kill all bitcoin processes.. if you're so inclined you could modify this to pull the individual pids out of each data directory.
Lastly, You will probably need to precreate some data directors for bitcoind if you don't edit the script at all.
mkdir $HOME/regtest/A/
mkdir $HOME/regtest/B/
mkdir $HOME/regtest/C/
mkdir $HOME/regtest/D/
mkdir $HOME/regtest/E/

You should have regtest bitcoind nodes connecting round-robin on ports 17591, 17592, 17593, 17594 and 17595. Likewise, you should be able to connect to rpc ports 16591, 16592, 16593, 16594 and 16595. If you need to know the RPC password you can check ps aux, or set an explicit rpcpassword in the script.
HTH

18345: <p>I am having trouble using regtest mode on Linux.  Using pre-compiled version 0.9.2.1 for linux and starting regtest mode as instructed on bitcoin.org:</p>

<pre><code>&lt;bitcoin-ver&gt;-linux/bin/64&gt;&gt; ./bitcoind -regtest -daemon
</code></pre>

<p>The server starts but doing a getinfo returns 'connections' : 0.  Tried experimenting with various rpc* settings in the .conf file.  What exactly do I need to set in order to use regtest mode?  Do I need to add real nodes via addnode for regtest?  It doesn't seem like I should need to.  I was able to get a few connections by adding several real nodes one time but after a few minutes 'connections' dropped back to 0.  Let me know if any additional info would help.</p>
 29691: <p>I would like to make an addition to above answers.</p>

<p>Instead of <code>-connect=ip</code> the correct option to use is <code>-addnode=ip</code>. <code>-connect</code> lets a node connect only to one node and whereas '-addnode' attempts at connecting to the specified list of nodes(ip) among other nodes.</p>
 53: <p>You need to run more than one node on your machine (you can do that if you give each node a different -port and -rpcport). And you need to tell them how to find each other (using -connect=127.0.0.1:portnumber).</p>

<p>There are examples written in bash and python in the Bitcoin Core source tree:
  <a href="https://github.com/bitcoin/bitcoin/tree/master/test/functional" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/tree/master/test/functional</a></p>
 19410: <p>In order to run multiple nodes in <a href="https://bitcoin.org/en/developer-examples#regtest-mode" rel="nofollow noreferrer">regtest mode</a> on a single machine you will need to sandbox each node.</p>
<p>In this example I have three nodes, they are named Alice, Bob and Cory. Since Bitcoin is a Peer/Mesh network, my goal is to connect each nodes so that changes made to Cory are ultimately visible to Bob (without necessarily requiring a direct connection between the two.)</p>
<h2>Step 1: Create folders for each node.</h2>
<p>These folders will contain our data and configs for each node. The names are not important, they can be renamed later, so you can name them &quot;Alice&quot;, &quot;Bob&quot; and &quot;Cory&quot; for now. Remember where you create them, you will need their paths for Step 3 below.</p>
<h2>Step 2: In each folder, create a <a href="https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File" rel="nofollow noreferrer">bitcoin.conf</a> file</h2>
<p>In the config files Alice will be configured to connect to Cory, and Bob will be configured to connect to Alice. In addition to configuring outbound connections, this is also where we specify <code>regtest=1</code> and <code>server=1</code> settings.</p>
<h3>bitcoin.conf for Alice</h3>
<pre><code>regtest=1
server=1
 # Alice connects to Cory
connect=localhost:18333
</code></pre>
<h3>bitcoin.conf for Bob</h3>
<pre><code>regtest=1
server=1
 # Bob connects to Alice
connect=localhost:18444
</code></pre>
<h3>bitcoin.conf for Cory</h3>
<pre><code>regtest=1
server=1
 # Cory connects to nobody
</code></pre>
<h2>Step 3: Start each node.</h2>
<p>Note each node must have a different port number since only one node can bind to a port number at any time.</p>
<ul>
<li>Alice on port 18444</li>
<li>Bob on port 18555</li>
<li>Cory on port 18333</li>
</ul>
<p>You can choose your own port numbers of course, just be careful not to use a port number that is already in use by something else.</p>
<p>The command-line options will tell bitcoin what port number to use, where to store data, and where to find its config file:</p>
<h3>Alice:</h3>
<p><code> &quot;C:\Program Files\Bitcoin\bitcoin-qt.exe&quot; -conf=&quot;C:\Alice\bitcoin.conf&quot; -datadir=&quot;C:\Alice&quot; -rpcport=18444</code></p>
<h3>Bob:</h3>
<p><code>&quot;C:\Program Files\Bitcoin\bitcoin-qt.exe&quot; -conf=&quot;C:\Bob\bitcoin.conf&quot; -datadir=&quot;C:\Bob&quot; -rpcport=18555</code></p>
<h3>Cory:</h3>
<p><code>&quot;C:\Program Files\Bitcoin\bitcoin-qt.exe&quot; -conf=&quot;C:\Cory\bitcoin.conf&quot; -datadir=&quot;C:\Cory&quot; -rpcport=18333</code></p>
<p>This will launch three instances of the Bitcoin Client, and the folders for each node will begin to initialize with regtest data.</p>
<h2>Step 4: Testing</h2>
<p>You can use the <code>Help-&gt;Debug Window-&gt;Console</code> option to interactively execute commands on any of the nodes. For example, you can mine 101 blocks with the following bitcoin console command:</p>
<p><code>setgenerate true 101</code></p>
<p>You should (after a few seconds) then have been awarded coins.</p>
<p>These mining activities result in <a href="https://bitcoin.org/en/developer-guide#transaction-data" rel="nofollow noreferrer">coinbase transactions</a> - and only the last one of 50 BTC is available to spend. Now you can send some BTC to one of the other nodes.  After a bit more mining such a transaction will be <a href="https://en.bitcoin.it/wiki/Confirmation" rel="nofollow noreferrer">confirmed</a>.</p>
<p>You can also use the console commands <code>getpeerinfo</code> and <code>getinfo</code> to check the network is set up correctly.  One of them (Cory with port=18333) should have 'sync=true' in its peerinfo output, and all nodes should have the same &quot;block height&quot; regardless of which node is used for mining.</p>
 4993: <p>Although I believe Fred Tingey's answer is complete, it has the following attributes:</p>

<ul>
<li>it depends on a config file.</li>
<li>it provides examples for bitcoin-qt on the windows platform, and the OP was asking about bitcoind on the linux platform.</li>
</ul>

<p>Thus, I wanted to share the following concise <strong>bash script</strong> which does what the OP wants. As others have partially noted the key to getting this to work is:</p>

<ul>
<li>specify a unique port (if listening) and rpcport (if using rpc) for each node</li>
<li>specify a unique data directory for each node</li>
<li>if using <code>-connect</code> to restrict to own nodes, remember to use <code>-listen</code> to accept connections from own nodes.</li>
</ul>

<p>That said, here's my <code>start-regtest-network.sh</code> script:</p>

<pre><code>#!/bin/bash
bitcoind -server -listen -port=17591 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16591 -datadir=$HOME/regtest/A/ -connect=localhost:17592 -regtest -pid=$HOME/regtest/A/.pid -daemon -debug
bitcoind -server -listen -port=17592 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16592 -datadir=$HOME/regtest/B/ -connect=localhost:17593 -regtest -pid=$HOME/regtest/B/.pid -daemon -debug
bitcoind -server -listen -port=17593 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16593 -datadir=$HOME/regtest/C/ -connect=localhost:17594 -regtest -pid=$HOME/regtest/C/.pid -daemon -debug
bitcoind -server -listen -port=17594 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16594 -datadir=$HOME/regtest/D/ -connect=localhost:17595 -regtest -pid=$HOME/regtest/D/.pid -daemon -debug
bitcoind -server -listen -port=17595 -rpcuser=bitcoinrpc -rpcpassword=P$SECONDS -rpcport=16595 -datadir=$HOME/regtest/E/ -connect=localhost:17591 -regtest -pid=$HOME/regtest/E/.pid -daemon -debug
</code></pre>

<p><strong>Additionally</strong>, here's my <code>stop-regtest-network.sh</code>:</p>

<pre><code>#!/bin/bash
sudo killall --regex bitcoin.*
</code></pre>

<p>I realize my stop script is sloppy, and will kill all bitcoin processes.. if you're so inclined you could modify this to pull the individual pids out of each data directory.</p>

<p><strong>Lastly</strong>, You will probably need to precreate some data directors for bitcoind if you don't edit the script at all.</p>

<pre><code>mkdir $HOME/regtest/A/
mkdir $HOME/regtest/B/
mkdir $HOME/regtest/C/
mkdir $HOME/regtest/D/
mkdir $HOME/regtest/E/
</code></pre>

<p>You should have regtest bitcoind nodes connecting round-robin on ports 17591, 17592, 17593, 17594 and 17595. Likewise, you should be able to connect to rpc ports 16591, 16592, 16593, 16594 and 16595. If you need to know the RPC password you can check <code>ps aux</code>, or set an explicit rpcpassword in the script.</p>

<p>HTH</p>
