The gut microbiota is a complex and diverse community of microorganisms that colonizes the human gastrointestinal tract and influences various aspects of human health. These microbes are closely related to enteric infections. As a foreign entity for the host, commensal microbiota is restricted and regulated by the barrier and immune system in the gut and contributes to gut homeostasis. Commensals also effectively resist the colonization of pathogens and the overgrowth of indigenous pathobionts by utilizing a variety of mechanisms, while pathogens have developed strategies to subvert colonization resistance. Dysbiosis of the microbial community can lead to enteric infections. The microbiota acts as a pivotal mediator in establishing a harmonious mutualistic symbiosis with the host and shielding the host against pathogens. This review aims to provide a comprehensive overview of the mechanisms underlying host-microbiome and microbiome-pathogen interactions, highlighting the multi-faceted roles of the gut microbiota in preventing enteric infections. We also discuss the applications of manipulating the microbiota to treat infectious diseases in the gut.