In C. elegans, removal of the germline triggers molecular events in the neighboring intestine, which sends an anti-aging signal to the rest of the animal. In this study, we identified an innate immunity related gene, named irg-7, as a novel mediator of longevity in germlineless animals. We consider irg-7 to be an integral downstream component of the germline longevity pathway because its expression increases upon germ cell removal and its depletion interferes with the activation of the longevity-promoting transcription factors DAF-16 and DAF-12 in germlineless animals. Furthermore, irg-7 activation by itself sensitizes the animals' innate immune response and extends the lifespan of animals exposed to live bacteria. This lifespan-extending pathogen resistance relies on the somatic gonad as well as on many genes previously associated with the reproductive longevity pathway. This suggests that these genes are also relevant in animals with an intact gonad, and can affect their resistance to pathogens. Altogether, this study demonstrates the tight association between germline homeostasis and the immune response of animals, and raises the possibility that the reproductive system can act as a signaling center to divert resources towards defending against putative pathogen attacks.