To connect two nodes, you can use the bootnode feature. Once you have made the nodes ready, you have to start a bootstrap node. The bootstrap node is used so that other nodes in the network can find your node. To create the bootnode, run the following command:
bootnode --genkey=boot.key
bootnode --nodekey=boot.key
After this, an enode URL will be displayed on the screen. This URL is used by other nodes to connect to this node.
To connect to this node, run the following command with the right values of your network:
geth --datadir path/to/custom/data/folder --networkid <network id> --bootnodes <bootnode-enode-url-from-above>