Minecraft wiki entry for Nether_survival, associated text: They do not actually chase the player (nor flee), even after being attacked. They just move randomly around the landscape, firing at any player who comes into the line of sight (and range).
Also, ghasts have 10 points of health (two fully charged shots with an unenchanted bow), so sniping them is not too difficult. A bow enchanted with even Power I or a critical hit can one-shot them.
The fireballs are fairly easy to dodge, but they also tear up the landscape, not to mention setting it afire. However, the player can also bounce a fireball away by hitting it (fist, weapon, tool, anything works) as comes near. The fireball usually goes in the direction of the player's gaze. If the player manages to hit the ghast with its own fireball, it dies instantly, awarding the player the "Return to Sender" achievement/advancement. Be forewarned that this takes practice, so don't expect to use this method as the sole defence against ghasts. The player can also deflect the fireball by hitting it with an arrow, a snowball or even an egg.
The classic defense is to build a mini-shelter out of cobblestone, 3 blocks high with a ladder to let the player poke their head (and bow) over the top, and preferably a 3×3 roof two squares above that for protection. Note that if the ghast can't see you, they don't fire.
If a ghast does come into reach the player can also hit them with a sword. This can happen when they spawn in a cave, or just randomly fly into one, or happen to fly close to the ground. Besides this being a rare opportunity, you may also need to dodge or bounce fireballs at close range.
If there is more than one ghast attacking the player, the best option is to run and/or hide. If the player sprints, fireballs cannot hit the player. If they can get out of sight from all but one, they can then focus on shooting down that one.
Ghasts don't spawn in crimson forests and warped forests. On the contrary, you may want to avoid soul sand valley biomes as ghast spawns are abundant there, however if a ghast spawns in a biome where ghasts can spawn, such as a Nether Waste or Soul Sand Valley, a ghast can end up drifting into a crimson forest or a warped forest, on random.
If a ghast is spotted in the distance and if you do not have any ranged weapons, It is recommended to leave the area, and take cover. tunneling into a wall and sealing the entrance, ghasts are unlikely to enter small or isolated areas, such as caves or ravines. Ghasts also do not enter structures, such as Nether Fortresses and Bastions, making these areas good places to hide from ghasts. Do not head directly to a nether portal to escape a ghast , ghast fireballs can destroy the portal, making it hard for players to return if they do not have a flint and steel.