9. $f(n)$ is a function defined on the set of natural numbers, when $p$ is a prime number, $f(p)=1$, and for any natural numbers $r$, $s$, we have
$$
f(r s)=r f(s)+s f(r) .
$$

Then, the sum of all $n$ that satisfy the condition
$$
f(n)=n, 1 \leqslant n \leqslant 10^{4}
$$

is.
Given the problem, for any natural numbers $r, s$, we have
$$
\frac{f(r s)}{r s}=\frac{f(r)}{r}+\frac{f(s)}{s} \text {. }
$$

Thus,
$$
\begin{array}{l}
\frac{f\left(p^{m}\right)}{p^{m}}=\frac{f(p)}{p}+\frac{f(p)}{p}+\cdots+\frac{f(p)}{p} \\
\quad=m \cdot \frac{f(p)}{p} .
\end{array}
$$

When $p$ is a prime number, we get
$$
f\left(p^{m}\right)=m p^{m-1},
$$

Suppose the prime factorization of $n$ is $n=p_{1}^{m} p_{2}^{n} \cdots p_{k}^{m_{k}}$. Then,
$$
\begin{array}{l}
\frac{f(u)}{n}=\frac{f\left(p_{1}^{m_{1}^{1}} p_{2}^{\mathrm{m}}{ }_{2}^{2} \cdots p_{k}^{m}\right.}{p_{1}^{m_{1}} p_{2}^{\mathrm{m}_{2}}{ }_{2}^{2} \cdots p_{k}^{\mathrm{m}_{\mathrm{k}}}} \\
=\frac{f\left(p_{1}^{m}{ }^{1}\right)}{p_{1}^{m}{ }_{1}^{2}}+\frac{f\left(p_{2}^{m}{ }_{2}^{m}\right)}{p_{2}^{m}}+\cdots+\frac{f\left(p_{k}^{m_{k}}\right.}{p_{k}^{m}} \\
=\frac{m_{1}}{p_{1}}+\frac{m_{2}}{p_{2}}+\cdots+\frac{m_{\mathrm{k}}}{p_{\mathrm{k}}} \text {. } \\
\end{array}
$$

Therefore, $f(n)=n$ is equivalent to
$$
\frac{m_{1}}{p_{1}}+\frac{m_{2}}{p_{2}}+\cdots+\frac{m_{\mathrm{k}}}{p_{\mathrm{k}}}=1 \text {. }
$$

By finding a common denominator, we get
$$
\begin{array}{r}
m_{1} p_{2} \cdots p_{k}+m_{2} p_{1} p_{3} \cdots p_{k}+\cdots+m_{k} p_{1} p_{2} \\
\cdots p_{k-1}=p_{1} p_{2} \cdots p_{k}
\end{array}
$$

Since any two of $p_{i}, p_{1}, \cdots, p_{k}$ are coprime, $p_{1}$ must be a factor of $m_{1} p_{2} \cdots p_{k}$, thus $p_{1} \mid m_{1}$. Similarly, for $1 \leqslant i \leqslant k$, we have $p_{i} \mid m_{i}$. Therefore, $\frac{m_{i}}{p_{i}} \geqslant 1$.

Thus, (5) holds only if $k=1$. If $f(n)=n$ holds, the prime factorization of $n$ can only be of the form $n=p^{\mathrm{p}}$.
Since $1 \leqslant n \leqslant 10^{4}$, $n$ can take the values $2^{2}, 3^{3}, 5^{5}$. Therefore, $2^{2}+3^{3}+5^{5}=3156$.