Idiopathic pulmonary fibrosis (IPF) is a chronic progressive interstitial lung disease of unknown etiology, characterized by diffuse alveolitis and alveolar structural damage. Due to the short median survival time and poor prognosis of IPF, it is particularly urgent to find new IPF biomarkers. Previous studies have shown that basement membranes (BMs) are associated with the development of IPF and tumor metastasis. However, there is still a lack of research on BMs-related genes in IPF. Therefore, we investigated the expression level of BMs genes in IPF and control groups, and explored their potential as biomarkers for IPF diagnosis. In this study, the GSE32537 and GSE53845 datasets were used as training sets, while the GSE24206, GSE10667 and GSE101286 datasets were used as validation sets. In the training set, seven immune biomarkers related to BMs were selected by differential expression analysis, machine learning algorithm (LASSO, SVM-RFE, Randomforest) and ssGSEA analysis. Further ROC analysis confirmed that seven BMs-related genes played an important role in IPF. Finally, four immune-related Hub genes ( COL14A1, COL17A1, ITGA10, MMP7) were screened out. Then we created a logistic regression model of immune-related hub genes (IHGs) and used a nomogram to predict IPF risk. The nomogram model was evaluated to have good reliability and validity, and ROC analysis showed that the AUC value of IHGs was 0.941 in the training set and 0.917 in the validation set. Pan-cancer analysis showed that IHGs were associated with prognosis, immune cell infiltration, TME, and drug sensitivity in 33 cancers, suggesting that IHGs may be potential targets for intervention in human diseases including IPF and cancer.