Well, let’s step back.
How do we measure the mass of the Earth?
We can look at an object orbiting the Earth, measure the speed of the orbit and how high up it is, and then calculate how massive an object it would have to orbiting to have that exact orbit. It wouldn’t matter if the Earth was a black hole, or a neutron star, or a cloud of gas. If we know the orbits of objects orbiting the the Earth, then we can pretty precisely measure the mass of the Earth.
Same with the Sun. We know how long it takes the Earth (or Venus or Mars) to orbit the Sun, we know how far they are from the Sun, so from that we know the mass of the Sun.
And same with a galaxy. Except it’s harder to measure the orbital velocity of the Sun, and it’s distance from the center of the galaxy. But we have lots of stars out there, so we start measuring them and figuring it out.
This is much more accurate than trying to count how many stars there are and figuring out their mass. And of course when we do both, we find that it seems like the galaxy is a lot more massive than it would be if we counted all the stars and their masses and added it all up. And this is the famous “dark matter”. Mass that we know must be there because we measure the orbits of stars around the galaxy and they’re orbiting too fast if the galaxy was just made up of stars.
And we don’t think the missing mass is gas, or dust, or interstellar planets, because those things would block a lot more light from the stars than we observe. We know there is some dust and gas, because we can see it blocking some areas of space. But for it to make up dark matter there would need to be a lot more, and so we don’t think that gas or dust or rogue planets could me more than a small fraction of dark matter.