Accurate and efficient source analysis in electro- and magnetoencephalography using sophisticated realistic head geometries requires advanced numerical approaches. This paper presents DUNEuro, a free and open source C++ software toolbox for forward modeling in bioelectromagnetism. Building upon the DUNE framework, it provides implementations of modern fitted and unfitted finite element methods to efficiently solve the forward problems in electro- and magnetoencephalography. The user can choose between a variety of different source models that are implemented. The softwares aim is to provide interfaces that are extendible and easy-to-use. In order to enable a closer integration into existing analysis pipelines, interfaces to Python and Matlab are provided. The practical use is demonstrated by a source analysis example of somatosensory evoked potentials using a realistic six compartment head model.