Smell, or olfaction, as scientists call it, is an important sense for many fish. Those little holes that look like nostrils are called nares. Nares don't lead to the throat the way nostrils do in mammals, but open up into a chamber lined with sensory pads.
Olfactory Systems Of A Fish
Not all fish move water in and out through these nares in quite the same ways, but key to a strong sense of smell for fish is the ability to move water rapidly over these sensory pads.
Some fish can pick up chemical signals when immobile by pumping water through their olfactory system via tiny hairs called cilia.
Other fish can pump water by a muscular movement. Some fish, such as smaller species of mackerel, have an olfactory system that requires them to swim in order to get water moving through their nares.
When the sensory pads pick up chemical signals, they transmit them to the fish's forebrain, which interprets the signal and incites the fish to respond appropriately.
If the chemicals signal food, the fish will pursue the food. Or if the chemicals signal danger, it'll flee. But fish use chemical cues in all sorts of ways. For instance, a large group of fishes release a chemical when they're wounded that incites other fish to flee.
And then there are salmon, which are known for a superb sense of smell that enables them to sense the stream where they were born, so that they may return to it to spawn.