Designing a simple challenge-response symmetric mutual authentication protocol
You probably want to use HMAC instead of any hash function.
I will use the notation $H(K, x)$ to denote a keyed MAC.
Your simple protocol version seems to allow a reflection attack.
First the adversary $A$ initiates a session with $B$:
$A \to B$: $\mathrm{id}_A$, $n_A$
$B \to A$: $\mathrm{id}_B$, $n_B$, $H(K, n_A)$
Then $A$ initiates a second session with the nonce $n_B$:
$A \to B$: $\mathrm{id}_A$, $n_B$
$B \to A$: $\mathrm{id}_B$, $n_B'$, $H(K, n_B)$
Now $A$ sends $H(K, n_B)$ to Bob in the first session:
$A \to B$: $H(K, n_B)$
You always want to include the message number, and additionally, who is sending the message and who is receiving the message. You also want to authenticate every piece of that information.