I guess DOF means "degrees of freedom".
When saying that the number of DOF of the electromagnetic field is 2, we should remember that we are talking about the gauge field $A_\mu$. This four-vector usually has 4 independent components,
that satisfies $\partial_{\mu}F^{\mu\nu}=0$ in the vacuum. Applying the Lorenz condition, $\partial_{\mu}A^{\mu}=0$, it simplifies to
$$\partial_{\nu}\partial^{\nu}A^{\mu}=0$$
Taking $A^{\mu}=\epsilon^{\mu} e^{i k.x}$, where $k.x=k_{\mu}x^{\mu}=- \omega t + \boldsymbol{k}.\boldsymbol{x}$, and substituting this into the above equation we find
$$k^2=0$$
which is another way of saying that the mass of photon is zero. Since $k^{\mu}$ is a null vector, using the spatial $SO(3)$ symmetry, it can be parametrized as
$$k^{\mu}=|k|(1,0,0,1)$$
where we take $\eta_{\mu\nu}=(-1,1,1,1)$. Now let'e get back to the Lorenz condition. For the above $A^{\mu}$ and $k^{\mu}$, it gives
$$k_{\mu}\epsilon^{\mu}=0$$
The most general four-vector $\epsilon^{\mu}$ satisfying this relation with the above $k^{\mu}$ is parametrized with three parameters $\alpha_{0,1,2}$:
$$\epsilon^{\mu}= \alpha_0 (1,0,0,1)+ \alpha_1 (0,1,0,0)+ \alpha_2 (0,0,1,0) $$
So far we have used "Maxwell equations + Lorenz gauge condition"; the result is that photon seems to have 3 dof: $\alpha_{0,1,2}$.
However, there does exist some residual gauge redundancy which has not fully fixed by the Lorenz condition. It is easy to see that if we make a gauge transformation
$$A_{\mu}\rightarrow A'_{\mu}=A_{\mu}+\partial_{\mu}\Lambda$$
with
$$\partial_{\nu}\partial^{\nu}\Lambda=0\,,$$
the new gauge field $A'_{\mu}$ will satisfy the Lorenz gauge, too.
In other words, all gauge transformation satisfying the above condition are still to be fixed.
To fix this gauge freedom, let's choose $\Lambda = \lambda e^{i k . x}$. Then
$$\epsilon^{\mu}\rightarrow \epsilon'^{\mu}= \big(\alpha_0+i\lambda|k|\big) (1,0,0,1)+ \alpha_1 (0,1,0,0)+ \alpha_2 (0,0,1,0) $$
Choosing $\lambda=- i |k|/\alpha_0$ we arrive at
$$\epsilon'^{\mu}= \alpha_1 (0,1,0,0)+ \alpha_2 (0,0,1,0) $$
This is the final result: a photon with two dof: $\alpha_{1,2}$.
The above choice of $\lambda$ is the famous
$$\text{Coulomb gauge:}\,\,\, \boldsymbol{\epsilon}.\boldsymbol{k}=0$$
In summary, combining "Maxwell equations + Lorenz gauge+ Coulomb gauge", motion of photon along the $z$ direction can be described in terms of only two polarization vectors
$$\epsilon^{\mu}_1=(0,1,0,0)\,,\,\,\,\,\, \epsilon^{\mu}_1= (0,0,1,0)$$
that are both transverse to $\boldsymbol{k}$.
Hope this helps.
See also Counting degrees of freedom of gauge bosons