The classification of curves of genus 2 over an algebraically closed field was studied by Clebsch and Bolza using invariants of binary sextic forms, and completed by Igusa with the computation of the corresponding three-dimensional moduli variety
M
2
\mathcal M_2
. The locus of curves with group of automorphisms isomorphic to one of the dihedral groups
D
8
D_8
or
D
12
D_{12}
is a one-dimensional subvariety. In this paper we classify these curves over an arbitrary perfect field
k
k
of characteristic
char
k
≠
2
\operatorname {char} k\neq 2
in the
D
8
D_8
case and
char
k
≠
2
,
3
\operatorname {char} k\neq 2,3
in the
D
12
D_{12}
case. We first parameterize the
k
¯
\overline k
-isomorphism classes of curves defined over
k
k
by the
k
k
-rational points of a quasi-affine one-dimensional subvariety of
M
2
\mathcal M_2
; then, for every curve
C
/
k
C/k
representing a point in that variety we compute all of its
k
k
-twists, which is equivalent to the computation of the cohomology set
H
1
(
G
k
,
Aut
(
C
)
)
H^1(G_k,\operatorname {Aut}(C))
. The classification is always performed by explicitly describing the objects involved: the curves are given by hyperelliptic models and their groups of automorphisms represented as subgroups of
GL
2
(
k
¯
)
\operatorname {GL}_2(\overline k)
. In particular, we give two generic hyperelliptic equations, depending on several parameters of
k
k
, that by specialization produce all curves in every
k
k
-isomorphism class.