The DNA-binding protein H-NS is a pleiotropic gene regulator in gram-negative bacteria. Through its capacity to sense temperature and other environmental factors, H-NS allows pathogens like Salmonella to adapt their gene expression to their presence inside or outside warm-blooded hosts. To investigate how this sensing mechanism may have evolved to fit different bacterial lifestyles, we compared H-NS orthologs from bacteria that infect humans, plants, and insects, and from bacteria that live on a deep-sea hypothermal vent. The combination of biophysical characterization, high-resolution proton-less nuclear magnetic resonance spectroscopy, and molecular simulations revealed, at an atomistic level, how the same general mechanism was adapted to specific habitats and lifestyles. In particular, we demonstrate how environment-sensing characteristics arise from specifically positioned intra- or intermolecular electrostatic interactions. Our integrative approach clarified the exact modus operandi for H-NS-mediated environmental sensing and suggested that this sensing mechanism resulted from the exaptation of an ancestral protein feature.