Idiopathic pulmonary fibrosis (IPF) is a rare disease of the lung with a largely unknown etiology and a poor prognosis. Intriguingly, forms of familial pulmonary fibrosis (FPF) have long been known and linked to specific genetic mutations. There is little evidence of the possible role of genetics in the etiology of sporadic IPF. We carried out a non-systematic, narrative literature review aimed at describing the main known genetic and epigenetic mechanisms that are involved in the pathogenesis and prognosis of IPF and FPF. In this review, we highlighted the mutations in classical genes associated with FPF, including those encoding for telomerases (TERT, TERC, PARN, RTEL1), which are also found in about 10–20% of cases of sporadic IPF. In addition to the Mendelian forms, mutations in the genes encoding for the surfactant proteins (SFTPC, SFTPA1, SFTPA2, ABCA3) and polymorphisms of genes for the mucin MUC5B and the Toll-interacting protein TOLLIP are other pathways favoring the fibrogenesis that have been thoroughly explored. Moreover, great attention has been paid to the main epigenetic alterations (DNA methylation, histone modification and non-coding RNA gene silencing) that are emerging to play a role in fibrogenesis. Finally, a gaze on the shared mechanisms between cancer and fibrogenesis, and future perspectives on the genetics of pulmonary fibrosis have been analyzed.