Are the thirty-one planes of existence real places or just metaphors? And How the buddha know all of these things. I suppose he knew from meditation until enlighten? So it is possible that just by mediation alone one can know about other realm of existence.

http://www.accesstoinsight.org/ptf/dhamma/sagga/loka.html
Here's my personal interpretation.
A belief in hell, devas, and rebirth preceded (existed before) Buddhism and the Buddha. So when the Buddha was born, lived, and taught, people (non-Buddhists) already had a belief in hell, devas, rebirth, etc.
According to the page you referenced (see also Wikipedia's Buddhist cosmology of the Theravada school) there isn't any one source e.g. a single sutta which identifies the 31 planes ... instead commentators have collected the 31 planes from several sources.
For example one of the suttas, which mentions the arupa-loka, is the Saleyyaka Sutta (MN 41). This starts as follows:


The brahman householders of Sala went to the Blessed One; etc.

When they were seated, they said to the Blessed One: &quot;Master Gotama, what is the reason, what is the condition, why some beings here, on the dissolution of the body, after death, reappear in states of deprivation, in an unhappy destination, in perdition, even in hell; and what is the reason, what is the condition, why some beings here, on the dissolution of the body, after death, reappear in a happy destination, even in the heavenly world?&quot;



In other words, the brahman householders open the discussion by asking, &quot;Why are some people reborn in hell and some in heaven?&quot;
Note that the question assumes/presumes the existence of heaven and hell.
In reply, the Buddha teaches them Dhamma: he defines or gives examples of good and bad bodily conduct, verbal conduct, mental conduct.
Incidentally, the sutta's message ends by saying that &quot;deliverance here and now&quot; is also possible (and is implicitly better than a heavenly rebirth):


&quot;If a householder who observes conduct in accordance with the Dhamma, righteous conduct, should wish: 'Oh, that by realization myself with direct knowledge, I may here and now enter upon and abide in the deliverance of the heart and the deliverance by wisdom that are taint-free with exhaustion of taints!' it is possible that, by realization himself with direct knowledge, he may here and now enter upon and abide in the deliverance of the heart and the deliverance by wisdom that are taint-free with exhaustion of taints. Why is that? Because he observes conduct in accordance with the Dhamma, righteous conduct.&quot;


My personal opinion is that the purpose or intent of this sutta, is not to teach us about the various kinds of Gods (though it does list various kinds), rather it is to teach examples of good and bad conduct, and teach that each person's future (destination) depends on their conduct. Whether or not that's really the &quot;sutta's intent&quot;, that's what I get out of it when I read it using my personal set of biases.
I see it as being similar to verse 393 of the Dhammapada, i.e. the Buddha uses the existing belief and vocubulary (e.g. the word &quot;brahmin&quot;), he redefines those words, and he reuses their language and belief-system to speak to people (who have pre-existing beliefs).
In other words I think that people of his day believed in rebirth, heaven, and hell, and he used that as a &quot;hook&quot; to tell them about good conduct, e.g. to say that their destination depended on their own behaviour.
I think you can see other examples where the Buddha selects his message to match the audience. When talking to a lay audience, for example, he talked about the six directions; when talking to monks, he talked about renunciation -- different messages to suit different audiences.

I think that a belief in or a doctrine of rebirth is tightly integrated into the Pali canon, for example a literal interpretation of the Four stages of enlightenment including &quot;once-returner&quot; and &quot;non-returner&quot; presume rebirth and rebirth in heaven.
IMO trying to remove a belief in &quot;planes of existence&quot; from Theravada might be like trying to remove a belief in &quot;heaven&quot; from Christianity i.e. it's not easy or a natural way to interpret the scripture.

One way to answer this is to say that, inline with the reasoning I gave in this answer, it might be useful to behave as if the realms exist, i.e. behave as if our conduct has future consequence.

Also, so far as I know, an orthodox answer from a Theravadin (i.e. a type of answer that I have seen from other users on this site) might be that you should practice to perfect yourself and your spiritual abilities until you can know/see the truth for yourself.