A friend of mine introduced me to the following question: Does there exist a smooth function $f: \mathbb{R} \to \mathbb{R}$, ($f \in C^\infty$), such that $f$ maps rationals to rationals and irrationals to irrationals and is nonlinear?
I posed this question earlier in math.stackexchange.com (link to the question) where it received considerable interest. There hasn't been an answer so far, but one commenter suggested to bring it here.
Related results
The friend who told me the problem has been able to prove that no polynomial satisfies the required conditions.
If we required just that $f \in C^1$, then we can cut and paste the function $x \mapsto \frac{1}{x}$ to provide a nonlinear example: $$f(x) = \begin{cases}\frac{1}{x-1} + 1, & x \le 0 \\\\ \frac{1}{x+1} - 1, & x \ge 0\end{cases}$$