They didn't know they were as far away as they are — that is a relatively recent discovery and hard to know without pretty advanced technology (telescopes of the sort only available in the last 200 years).
What they knew was what you can observe directly with the naked eye:
The stars are clearly behind the Moon, because the Moon passes in front of them.
The stars are "fixed" — they don't move relative to one another, except for the regular daily precession (which we now know is Earth's rotation)
The planets — "wanders" — are star-like (they look like little bright dots) but move around a lot. Some move faster than others.
I can't talk about all ancient civilizations but the Greeks generally interpreted the above to mean that the Earth was surrounded by successive layers of planets (where faster movement = closer), and the stars were some kind of fixed system beyond the planets (depending on the writer, it varied — some thought they were holds on the inside of a massive opaque sphere with a fire outside of it, some thought they were bright things embedded in the spheres).
None of these thinkers contemplated that the stars were anything like billions of light years away. Even the early modern astronomers like Copernicus, Tycho, Kepler, Galileo, Newton, etc. did not contemplate this. That realization did not come until the 19th century with the successful measurement of the stellar parallax (where you take two measurements of star locations 6 months apart, and get a "binocular" view of them; they are far-enough away that you need telescopes of fairly high precision to do this), and use of "standard candles" in the early 20th century (in which objects of known brightness can be compared to their actual brightness; this requires you to figure out what brightness something ought to be, which is tricky).