Infection-induced aversion against enteropathogens is a conserved sickness behaviour that can promote host survival1,2. The aetiology of this behaviour remains poorly understood, but studies in Drosophila have linked olfactory and gustatory perception to avoidance behaviours against toxic microorganisms3,4,5. Whether and how enteric infections directly influence sensory perception to induce or modulate such behaviours remains unknown. Here we show that enteropathogen infection in Drosophila can modulate olfaction through metabolic reprogramming of ensheathing glia of the antennal lobe. Infection-induced unpaired cytokine expression in the intestine activates JAK–STAT signalling in ensheathing glia, inducing the expression of glial monocarboxylate transporters and the apolipoprotein glial lazarillo (GLaz), and affecting metabolic coupling of glia and neurons at the antennal lobe. This modulates olfactory discrimination, promotes the avoidance of bacteria-laced food and increases fly survival. Although transient in young flies, gut-induced metabolic reprogramming of ensheathing glia becomes constitutive in old flies owing to age-related intestinal inflammation, which contributes to an age-related decline in olfactory discrimination. Our findings identify adaptive glial metabolic reprogramming by gut-derived cytokines as a mechanism that causes lasting changes in a sensory system in ageing flies.