The best way for you to get rid of gnats is to get rid of their homes. Fungus gnats are attracted to the fungus that grows in wet places. For example, if you soak your houseplants when you water them, fungus could grow on the leaves and attract gnats. Gnats are also attracted to rotting organic matter and sitting water in bathrooms or drains. Gnats only live about a week, but during this time they can lay up to 150 eggs. Plus, they bite, so you certainly don't want them buzzing around your house.
Make sure that all of the doors and windows of your house are sealed so that gnats don't get in. Fill any gaps around openings with silicone caulk and replace any torn or missing screens. You should avoid overwatering your houseplants and always provide your plants with good drainage. Be careful not to soak the leaves of your plants when you are watering and clean up any free standing water. Make repairs to any leaky plumbing as needed and make sure that your garbage disposal is working properly. Cover your trash cans with air tight lids and do not leave food sitting out on your counters. Out in your garden, avoid using incompletely composted, unpasteurized organic matter. Organic fertilizers, grass clippings and compost are gnat breeding grounds.
If you already have gnats in your house, you can use pyrethrums to provide you with fast relief. Pyrethrins are less toxic to your family and pets and come from chrysanthemums. Nevertheless, an insecticide should be your last resort. This could also kill beneficial insects. If your gnat problem is occurring in your garden outdoors or in your greenhouse, you can unleash a plague of ladybugs to eat the gnats. Rove beetles and ground beetles are also natural predators that should control gnat larvae.