In both cases, you're only talking about a handful of strains. The strains however, are known to be much hardier than the majority of the strains present in the gut and they also have known benefits. Estimates on the numbers of species present in the gut range from 400-500, to 1,000+, to 5,500, to 40,000+ depending on the source. The majority of these will be based on the foods and liquids we consume. Fermented foods and probiotics both have been found to be beneficial.
Bacteria are only one component. Immune function is another, and intestinal epithelial cells are a third. It's an ecosystem that balances itself when properly regulated.