Environmental factors, such as microbiota, are likely to play an important role in the development of inflammatory bowel disease, including Crohn’s disease and ulcerative colitis. The microbiota regulates intestinal physiology by modifying host gene expression along the length of the intestine, but the underlying mechanisms have remained unresolved. We show that exposure to microbiota under physiological conditions is associated with extensive alterations in DNA methylation at regulatory elements, which is TET2/3 dependent. This causes transcriptional activation of a set of “early sentinel” response genes that are linked to normal intestinal homeostasis and prime cells for future inflammatory processes. We further show that exposure to microbiota in acute inflammation results in profound changes in DNA methylation and chromatin accessibility at regulatory elements, which culminate in alterations in expression of genes enriched in colitis and cancer.