Based on symmetry analysis and lattice model calculations, we demonstrate that Dirac nodal line (DNL) can stably exist in two-dimensional (2D) nonmagnetic as well as antiferromagnetic systems. We focus on the situations where the DNLs are enforced by certain symmetries and the degeneracies on the DNLs are inevitable even if spin–orbit coupling is strong. After thorough analysis, we find that five space groups, namely 51, 54, 55, 57 and 127, can enforce the DNLs in 2D nonmagnetic semimetals, and four type-III magnetic space groups (51.293, 54.341, 55.355, 57.380) plus eight type-IV magnetic space groups (51.299, 51.300, 51.302, 54.348, 55.360, 55.361, 57.387 and 127.396) can enforce the DNLs in 2D antiferromagnetic semimetals. By breaking these symmetries, the different 2D topological phases can be obtained. Furthermore, by the first-principles electronic structure calculations, we predict that monolayer YB4C4 is a good material platform for studying the exotic properties of 2D symmetry-enforced Dirac node-line semimetals.