The temperature profile of hot gas in galaxies and galaxy clusters is largely determined by the depth of the total gravitational potential and thereby by the dark matter (DM) distribution. We use high-resolution hydrodynamical simulations of galaxy formation to derive a surprisingly simple relation between the gas temperature and DM properties. We show that this relation holds not just for galaxy clusters but also for equilibrated and relaxed galaxies at radii beyond the central stellar-dominated region of typically a few kpc. It is then clarified how a measurement of the temperature and density of the hot gas component can lead to an indirect measurement of the DM velocity anisotropy in galaxies. We also study the temperature relation for galaxy clusters in the presence of self-regulated, recurrent active galactic nuclei (AGN), and demonstrate that this temperature relation even holds outside the inner region of ≈ 30 kpc in clusters with an active AGN.Subject headings: