2. Given the function
$$
f(x)=x^{3}+(a+1) x^{2}+(a+1) x+a
$$

has both a maximum and a minimum value in its domain. Then the range of the real number $a$ is ( ).
(A) $a<-12$
(C) $a>2$ or $a<-1$
2. D.

Let $f(x)=x^{3}+(a+1) x^{2}+(a+1) x+a$, then $f^{\prime}(x)=3 x^{2}+2(a+1) x+(a+1)$.
From the given condition, we know that $f^{\prime}(x)=0$ must have two distinct real roots.
Therefore, $\Delta=4(a+1)^{2}-12(a+1)>0$.
Solving this, we get $a>2$ or $a<-1$.