The internet offers a long list of fungus gnat remedies, and it is worth separating those with a plausible mechanism from those without.
Hydrogen peroxide
Widely recommended as a compost drench, usually one part three per cent solution to three or four parts water. It does kill larvae on contact by oxidation, and it fizzes satisfyingly.
The caution is that it is not selective – it damages fine root hairs and kills beneficial soil organisms alongside the larvae. Repeated applications set a plant back noticeably.
It also breaks down within minutes into water and oxygen, so it has no residual effect and does nothing about eggs deeper in the pot or adults flying about.
Usable once as a knockdown, not as a programme.
Soil drenches with insecticide
Products containing systemic insecticides will control larvae. Whether to use them indoors is a separate question – the plants are in living space, and the same result is available from nematodes and Bti without the exposure.
For most domestic situations the biological options are equally effective and preferable.
Sprays for adults
Aerosols and pyrethrin sprays kill adults on contact and do nothing about the larvae, so the population regenerates within days. They are a way of clearing a room temporarily rather than a control.
The home remedies that do little
Cinnamon, sometimes credited with fungicidal properties, has minimal effect on gnat larvae. Chamomile tea drenches, similar. Neither has been shown to control an infestation.
Apple cider vinegar traps catch fruit flies far better than fungus gnats, which are not attracted to fermentation in the same way. If a vinegar trap is catching a great deal, the insects are probably fruit flies rather than gnats.
Garlic, essential oils and washing-up liquid drenches all have advocates and little evidence, and some risk damaging roots.
Neem and soap
Neem drenches have a modest effect on larvae and are slow. Insecticidal soap sprayed on the compost surface kills what it contacts and has no residual action.
Both are more useful against foliage pests than against something living in compost.
The practical conclusion
Surface drying, a top-dressing and sticky traps handle most infestations. Nematodes or Bti handle the rest. Everything else on the list is either unnecessary or a distraction, and hydrogen peroxide in particular is used far more often than its benefits justify.
Why so many remedies circulate
Fungus gnat populations fluctuate naturally, and adults live only a week. Almost any intervention will coincide with a decline at some point, which generates confident testimony for measures that did nothing.
The life cycle also means a treatment appears to work for a fortnight and then fails, which produces a cycle of trying the next remedy on the list.
The test to apply
Ask which stage a remedy targets. Adults only, and the population regenerates. Larvae, and it will work if sustained across two cycles. Neither, and it will not work at all.
That question disposes of most of the list quickly, and it explains why the effective measures are the ones aimed at the compost rather than at the flies.