the first one is grammatical, and is asking about a period of time in the past when you were gone.
The second one is not grammatical. you could be trying to say "How long have you been away?", i.e. you are away and have been away, and the questioner wants to know when you went away.