TITLE: Can ring homomorphisms be characterized as ring maps such that preimage of any ideal is an ideal?
QUESTION [11 upvotes]: It's a well know fact that preimage of ideals by ring homomorphism are also ideals.
Is the reciprocal true? I.e., let $f:R\to S$ be a map between the rings $R$ and $S$ s.t. $f^{-1}(I)\vartriangleleft R$ if $I\vartriangleleft S$. Then is $f$ a ring homomorphism?

REPLY [17 votes]: No. For instance, the function from any ring to itself which reverses the sign of each element (i.e. $f(x) = -x$) will conserve ideals, but it usually won't be a homomorphism.

REPLY [12 votes]: You can make this fail, for almost any nonzero $R$ and almost any nonzero $S$, by taking $$f(x)=\begin{cases} 0,&\ x=0\\ \ \\ s_0,&\ x\ne0\end{cases}$$ where $s_0$ is a nonzero fixed element of $S$, 
Then for any ideal the pre-image will be $\{0\}$ or $R$, depending on whether the ideal contains $s_0$ or not. 
In some corner cases $f$ may result in an isomorphism, as Eric mentions below.

REPLY [3 votes]: Consider any bijection of $\mathbb R\to\mathbb R$ which isn't additive, but maps $0$ to $0$. You could, for example, take $x\neq 1$ and interchange $x$ and $1$ and map everything else to itself.
It clearly satisfies the property, since $f^{-1}(\{0\})=\{0\}$ and $f^{-1}(\mathbb R)=\mathbb R$, and those are all the ideals that there are.
This map is not a ring homomorphism though, since it does not preserve the multiplicative identity.
This trick works pretty much for any map between rings, except for some edge combinations using $\{0\}$ and $F_2$.