  We find the distribution function f(E) for dark matter (DM) halos in galaxies
and the corresponding equation of state from the (empirical) DM density
profiles derived from observations. We solve for DM in galaxies the analogous
of the Eddington equation originally used for the gas of stars in globular
clusters. The observed density profiles are a good realistic starting point and
the distribution functions derived from them are realistic. We do not make any
assumption about the DM nature, the methods developed here apply to any DM
kind, though all results are consistent with Warm DM. With these methods we
find: (i) Cored density profiles behaving quadratically for small distances
rho(r) r -> 0 = rho(0) - K r^2 produce distribution functions which are finite
and positive at the halo center while cusped density profiles always produce
divergent distribution functions at the center. (ii) Cored density profiles
produce approximate thermal Boltzmann distribution functions for r < 3 r_h
where r_h is the halo radius. (iii) Analytic expressions for the dispersion
velocity and the pressure are derived yielding an ideal DM gas equation of
state with local temperature T(r) = m v^2(r)/3. T(r) turns to be constant in
the same region where the distribution function is thermal and exhibits the
same temperature within the percent. The self-gravitating DM gas can thermalize
despite being collisionless because it is an ergodic system. (iv) The DM halo
can be consistently considered at local thermal equilibrium with: (a) a
constant temperature T(r) = T_0 for r < 3 \; r_h, (b) a space dependent
temperature T(r) for 3 r_h < r < R_{virial}, which slowly decreases with r.
That is, the DM halo is realistically a collisionless self-gravitating thermal
gas for r < R_{virial}. (v) T(r) outside the halo radius nicely follows the
decrease of the circular velocity squared.
