Many epidemiological studies have shown that idiopathic pulmonary fibrosis (IPF) is a risk factor for lung cancer (LC), but these studies do not provide direct evidence of a causal association between the two diseases. We investigated the causal association between IPF and different pathological types of LC based on the Mendelian randomization (MR) study. The genome-wide association study (GWAS) data of IPF and LC were obtained from the latest published articles, and instrumental variables (IVs) for analysis were obtained after screening and eliminating the confounders. MR Analysis was carried out with the help of random effects inverse variance weighting (re-IVW), MR-egger, and weighted median method, and a comprehensive sensitivity test was conducted. The results of re-IVW analysis showed that IPF may increase the risk of lung squamous cell carcinoma (LUSC) (OR = 1.045, 95% CI 1.011 to 1.080, P = 0.008). In addition, no causal relationship was found between IPF and overall LC (OR = 0.977, 95% CI 0.933 to 1.023, P = 0.32), lung adenocarcinoma (LUAD) (OR = 0.967, 95% CI 0.903 to 1.036, P = 0.345) and small cell lung carcinoma (SCLC) (OR = 1.081, 95% CI 0.992 to 1.177, P = 0.074). A comprehensive sensitivity analysis ensured the reliability of the study. In conclusion, from the perspective of genetic association, we found that IPF is an independent risk factor for LUSC and may increase the risk of LUSC, but no such causal relationship was found in LUAD and SCLC.