Is a Lipschitz continuous function with this rationality condition piecewise linear? If $f:[0,1] \to \mathbb R$ is Lipschitz, i.e. $|f(x)-f(y)|<K|x-y|$ for fixed $K$, and for every rational $r$ there exists integers $a$, $b$ such that $f(r)=ar+b$, do there exist finitely many intervals $I_n$ such that $[0,1] =\cup I_n$ and $f$ is linear on $I_n$?

It seems intuitive to me that $f$ is linear on a small enough neighborhood of $x\in[0,1]$. I tried proving that if $r$ and $q$ are rationals in this neighborhood, then the integers mentioned in the hypothesis for both numbers should be equal i.e. if $f(r)=ar+b$ and $f(q)=cq+d$ then $a=c$ and $b=d$. It seems logical that this should follow from Lipschitz continuity, so I tried to show that
$|ar-cq+b-d|<\epsilon $ 
Implies that $|a-c|,|b-d|<\epsilon$ and since they are integers, their differences should be $0$ for $\epsilon <1$.

But so far I have been unsuccessful. It seems to me this would be the last step, since then the compact interval has a finite subcover where $f$ is linear, which yields the result.

Any clues or hints on how to overcome that problem?

Yes, $f$ will be piecewise linear. Specifically, $f$ is contained in the union $U$ of the lines $ax+b$ with $a,b$ integers and $|a|<K.$
The main trick is to notice that the set of slopes between "consecutive" rationals
$$(f(\tfrac{p+1}q)-f(\tfrac p q))q$$
is compact.
Spoiler
Suppose for contradiction that $f$ is not contained in $U.$ Then there's a compact interval where $f$ is completely outside $U$ -
 this is the only bit of analysis needed. There's some subinterval with the maximum possible slope within this interval, which forces $f$ to be linear there, and in fact must be of the form $ax+b,$ a contradiction.
