The innate immune system provides hosts with a crucial first line of defense against pathogens. While immune genes are often among the fastest evolving genes in the genome, in Drosophila , antimicrobial peptides (AMPs) are notable exceptions. Instead, AMPs may be under balancing selection, such that over evolutionary timescales multiple alleles are maintained in populations. In this study, we focus on the Drosophila antimicrobial peptide Diptericin A, which has a segregating amino acid polymorphism associated with differential survival after infection with the Gram-negative bacteria Providencia rettgeri . Diptericin A also helps control opportunistic gut infections by common Drosophila gut microbes, especially those of Lactobacillus plantarum . In addition to genotypic effects on gut immunity, we also see strong sex-specific effects that are most prominent in flies without functional diptericin A . To further characterize differences in microbiomes between different diptericin genotypes, we used 16S metagenomics to look at the microbiome composition. We used both lab reared and wild caught flies for our sequencing and looked at overall composition as well as the differential abundance of individual bacterial families. Overall, we find flies that are homozygous for one allele of diptericin A are better equipped to survive a systemic infection from P. rettgeri , but in general have a shorter lifespans after being fed common gut commensals. Our results suggest a possible mechanism for the maintenance of genetic variation of diptericin A through the complex interactions of sex, systemic immunity, and the maintenance of the gut microbiome.