Gut epithelial cells contact both commensal and pathogenic bacteria, and proper responses to these bacteria require a balance of positive and negative regulatory signals. In the Drosophila intestine, peptidoglycan-recognition proteins (PGRPs), including PGRP-LE, play central roles in bacterial recognition and activation of immune responses, including induction of the IMD-NF-κB pathway. We show that bacteria recognition is regionalized in the Drosophila gut with various functional regions requiring different PGRPs. Specifically, peptidoglycan recognition by PGRP-LE in the gut induces NF-κB-dependent responses to infectious bacteria but also immune tolerance to microbiota through upregulation of pirk and PGRP-LB, which negatively regulate IMD pathway activation. Loss of PGRP-LE-mediated detection of bacteria in the gut results in systemic immune activation, which can be rescued by overexpressing PGRP-LB in the gut. Together these data indicate that PGRP-LE functions as a master gut bacterial sensor that induces balanced responses to infectious bacteria and tolerance to microbiota.