The measurement of the production of prompt D0, D+, D*+, and {mathrm{D}}_{mathrm{S}}^{+} mesons in proton–lead (p–Pb) collisions at the centre-of-mass energy per nucleon pair of sqrt{s_{mathrm{NN}}} = 5.02 TeV, with an integrated luminosity of 292 ± 11 μb−1, are reported. Differential production cross sections are measured at mid-rapidity (−0.96 < ycms< 0.04) as a function of transverse momentum (pT) in the intervals 0 < pT< 36 GeV/c for D0, 1 < pT< 36 GeV/c for D+ and D*+, and 2 < pT< 24 GeV/c for D+ mesons. For each species, the nuclear modification factor RpPb is calculated as a function of pT using a proton-proton (pp) ref- erence measured at the same collision energy. The results are compatible with unity in the whole pT range. The average of the non-strange D mesons RpPb is compared with theoretical model predictions that include initial-state effects and parton transport model predictions. The pT dependence of the D0, D+, and D*+ nuclear modification factors is also reported in the interval 1 < pT< 36 GeV/c as a function of the collision centrality, and the central-to-peripheral ratios are computed from the D-meson yields measured in different centrality classes. The results are further compared with charged-particle measurements and a similar trend is observed in all the centrality classes. The ratios of the pT-differential cross sections of D0, D+, D*+, and {mathrm{D}}_{mathrm{S}}^{+} mesons are also reported. The {mathrm{D}}_{mathrm{S}}^{+} and D+ yields are compared as a function of the charged-particle multiplicity for several pT intervals. No modification in the relative abundances of the four species is observed with respect to pp collisions within the statistical and systematic uncertainties.