Gnats might be small, but when they’re buzzing around your house, they’re a big nuisance. That’s true whether they’re swarming around your fruit bowl or loitering by your houseplants. Although these bugs won’t bite, sting, or cause structural damage, they pose a health risk if they transfer bacteria to your food. No matter what type of gnat you’re dealing with—fungus gnats, fruit flies, or drain flies—you’re probably wondering how to get rid of them.

There are three different types of tiny, flying insects underneath the “gnat” umbrella, so identifying the type of pest you have will help you figure out the right solution. If a group of black bugs with long legs is lingering around your potted plants, you have fungus gnats. But if your kitchen counter or trash can has been getting round, brown visitors with red eyes, fruit flies are the culprit. Then, there are drain flies, fuzzy, moth-like pests that congregate in sinks and drains.

Once you’ve pinpointed the type of gnat that’s been infesting your home, you can move onto the fix. According to Dr. Zachary DeVries, PhD, associate professor of urban entomology at the University of Kentucky, the most effective gnat elimination tactic involves targeting the breeding grounds: an overripe banana, a clogged drain, an overwatered houseplant. After finding the source, you could spray a pesticide to repel the swarm, but a more eco-friendly and cost-effective method is creating a DIY solution with everyday ingredients sitting in your panty. To get rid of pesky gnats for good, here are the best household solutions for each type.

Watering houseplant by window with watering can
Ekaterina Vasileva-Bagler//Getty Images

How to Get Rid of Fungus Gnats with Pantry Items

Since fungus gnats typically lay eggs in moist potting soil, keeping your houseplants dry while targeting the adults will help get rid of them.

Adjust Your Watering Frequency

Overwatering is the top cause of fungus gnats, so changing up your watering routine will naturally diminish the population. “Fungus gnats are controlled by letting the soil of houseplants dry completely before watering,” notes Kaitlin Chapman, extension educator of urban entomology at University of Nebraska-Lincoln. To prevent fungus gnats from reproducing, aim to hydrate your potted plants only when the top inch or two of soil is dry. While it isn’t necessarily a pantry solution, you won’t be able to target the swarm with a DIY solution unless you dry out the soil first.

Apply Apple Cider Vinegar

Because apple cider vinegar acts like a bug magnet, you can use the shelf-stable ingredient to your benefit. Pour a small amount of vinegar into a shallow bowl before adding a few drops of dish soap and placing the solution near the infestation. While the vinegar attracts the fungus gnats, the soap will cause the bugs to sink rather than escape.

Add a Dash of Cinnamon

Ground cinnamon gives dishes and baked goods a hint of sweetness, but thanks to its natural antifungal properties, the warm spice can also help eliminate the fungi that fungus gnats feed on. Simply sprinkle the pantry item over the surface of dry soil, and watch it work its magic.

Arranging kitchen fruit bowl
Nico De Pasquale Photography//Getty Images

How to Get Rid of Fruit Flies with Pantry Items

Fruit flies, on the other hand, are a type of gnat attracted to overripe fruits and vegetables, so you’ll need to toss the food source and concoct a household solution that effectively eliminates the adults.

Toss Overripe Produce

The fastest way to decrease the population of fruit flies? Tossing overripe fruits and veggies. In fact, DeVries says using up ripe produce right before it turns overripe will prevent your bug problem before it happens. Inspect your fruit bowl for fermenting produce that’s exceeded ripeness, especially bananas, melons, and tomatoes, and throw them in the trash before taking it out. In order for a pantry solution to work, this is the first step.

Keep Bins Clean

While fruit flies primarily feed on overripe fruits and vegetables, they’re also drawn to residue left in trash cans or recycling bins, according to Chapman. “This could be funk that leaked out of a garbage bag into the bottom of the can or an old potato that found its way to the back of the pantry,” cites Wizzie Brown, senior extension program specialist with Texas A&M AgriLife Extension Service. Regularly rinsing your bins with warm, soapy water, and promptly taking out the trash will cut off their food source.

Create a Vinegar Trap

Like fungus gnats, fruit flies get lured in by apple cider vinegar. After getting rid of the edible breeding grounds, Chapmon advises filling half a glass with apple cider vinegar and a drop or two of dish soap to break up the surface, then adding a paper funnel to trap the flies. Station this DIY trap next to the gnat infestation.

Running water from faucet draining down a stainless steel sink
Viktoriya Skorikova//Getty Images

How to Get Rid of Drain Flies With Pantry Items

Like their name suggests, drain flies are a type of gnat that nest and reproduce in drains, so targeting the adult population means you’ll have to dismantle their preferred habitat.

Scrub the Drain

Brown recommends regularly scrubbing your drains with a stiff brush to remove the slimy, sticky biofilm that drain flies love. If you aren’t sure which drain is infected, she suggests placing clear tape or a clear cup over the drain and checking for gnats the next morning.

Flush It With Baking Soda and Vinegar

Another way to loosen the organic buildup that drain flies feed on entails pouring half a cup of baking soda down the drain, followed by one cup of white vinegar. After letting the solution fizz for at least 15 minutes, flush it with boiling water.

Whatever type of gnat is pestering you and your family, these at-home remedies made with pantry items you already have on hand will work wonders—often better than store-bought cleaners!

Headshot of Lilly Blomquist
Lilly Blomquist
Associate Editor

Lilly Blomquist is the associate editor at The Pioneer Woman, where she writes lifestyle stories across a wide range of topics—including news, entertainment, holidays, food, and more.