How do we know there are intergalactic clouds between a distant quasar and earth?
We know this because of the Lyman-alpha forest.
As light from a distant quasar passes through clouds of intergalactic gas, the gas will absorb light at very specific wavelengths, including the Lyman alpha line of hydrogen at 122 nm (in the ultraviolet).
Since each one of these clouds will be at a different redshift, with the closest clouds having the smallest redshift and the furthest clouds having the largest redshift, you will see a whole bunch of absorption lines at slightly different wavelengths. In fact, there are so many absorption lines, it looks like a "forest".
A simplified diagram:
The big hump on the right is the Lyman alpha emission line from the quasar. All of the other lines are the "Lyman-alpha forest". Each one of the absorption lines (dips) is a Lyman alpha absorption line from a different cloud of gas that light from the quasar has passed through. The smaller the wavelength, the close the cloud is to us.