We derive a dielectric-dependent hybrid functional which accurately describes the electronic properties of heterogeneous interfaces and surfaces, as well as those of three-and two-dimensional bulk solids. The functional, which does not contain any adjustable parameter, is a generalization of self-consistent hybrid functionals introduced for homogeneous solids, where the screened Coulomb interaction is defined using a spatially varying, local dielectric function. The latter is determined self-consistently using density functional calculations in finite electric fields. We present results for the band gaps and dielectric constants of 3D and 2D bulk materials, and band offsets for interfaces, showing an accuracy comparable to that of GW calculations.