Gut bacteria influence brain functions and metabolism. We investigated whether this influence can be mediated by direct sensing of bacterial cell wall components by brain neurons. In mice, we found that bacterial peptidoglycan plays a major role in mediating gut-brain communication via the Nod2 receptor. Peptidoglycan-derived muropeptides reach the brain and alter the activity of a subset of brain neurons that express Nod2. Activation of Nod2 in hypothalamic inhibitory neurons is essential for proper appetite and body temperature control, primarily in females. This study identifies a microbe-sensing mechanism that regulates feeding behavior and host metabolism.