Introduction: Idiopathic pulmonary fibrosis is a chronic interstitial lung disease characterized by excessive deposition of extracellular matrix. Cannabidiol, a natural component extracted from plant cannabis, has been shown to have therapeutic effects on lung diseases, but its exact mechanism of action is unknown, hindering its therapeutic effectiveness.Methods: To establish a pulmonary fibrosis model, combined with UPLC-Q-TOF/MS metabolomics and 16S rDNA sequencing, to explore cannabidiol’s mechanism in treating pulmonary fibrosis. The rats were randomly divided into the control group, pulmonary fibrosis model group, prednisone treatment group, and cannabidiol low, medium, and high dose groups. The expression levels of HYP, SOD, and MDA in lung tissue and the expression levels of TNF-α, IL-1β, and IL-6 in serum were detected. Intestinal microbiota was detected using UPLC-QTOF/MS analysis of metabolomic properties and 16S rDNA sequencing.Results: Pathological studies and biochemical indexes showed that cannabidiol treatment could significantly alleviate IPF symptoms, significantly reduce the levels of TNF-α, IL-1β, IL-6, MDA, and HYP, and increase the expression level of SOD (p < 0.05). CBD-H can regulate Lachnospiraceae_NK4A136_group, Pseudomonas, Clostridia_UCG-014, Collinsella, Prevotella, [Eubacterium]_coprostanoligenes_group, Fusobacterium, Ruminococcus, and Streptococcus, it can restore intestinal microbiota function and reverse fecal metabolism trend. It also plays the role of fibrosis through the metabolism of linoleic acid, glycerol, linolenic acid, and sphingolipid.Discussion: Cannabidiol reverses intestinal microbiota imbalance and attenuates pulmonary fibrosis in rats through anti-inflammatory, antioxidant, and anti-fibrotic effects. This study lays the foundation for future research on the pathological mechanisms of IPF and the development of new drug candidates.