  We construct a gauge $B-L$ model with $D_4\times Z_4\times Z_2$ symmetry that
can explain the quark and lepton mass hierarchies and their mixings with the
realistic CP phases via the type-I seesaw mechanism. Six quark mases, three
quark mixing angles and CP phase in the quark sector can get the central values
and Yukawa couplings in the quark sector are diluted a range of three orders of
magnitude difference by the perturbation theory at the first order. For
neutrino sector, the smallness of neutrino mass is achieved by the Type-I
seesaw mechanism. Both inverted and normal neutrino mass hierarchies are in
consistent with the experimental data. The prediction for the sum of neutrino
masses for normal and inverted hierarchies, the effective neutrino masses and
the Dirac CP phase are well consistent with all the recent limits.
