We theoretically study the Ruderman-Kittel-Kasuya-Yosida (RKKY) interaction between magnetic impurities in both Dirac and Weyl semimetals (SMs). We find that the internode process, as well as the unique three-dimensional spin-momentum locking, has significant influences on the RKKY interaction, resulting in both a Heisenberg and an Ising term, and an additional Dzyaloshinsky-Moriya term if the inversion symmetry is absent. These interactions can lead to rich spin textures and possible ferromagnetism in Dirac and time-reversal symmetry-invariant Weyl SMs. The effect of anisotropic Dirac and Weyl nodes on the RKKY interaction is also discussed. Our results provide an alternative scheme to engineer topological SMs and shed new light on the application of Dirac and Weyl SMs in spintronics.