― Mitch Albom
Loneliness is a bodily function, like hunger. Hunger make you pay attention to your physical needs; loneliness makes you pay attention to your social needs.
Your body cares about your social needs, because millions of years ago, it was a great indicator of how likely you were to survive. Natural selection rewarded our ancestors for collaboration, and for forming connections with each other.
Our brains grew and became more and more fine-tuned to recognize what others thought and felt, and to form and sustain social bonds. Being social became part of our biology You were born into groups of 50 to 150 people, which you usually stayed with for the rest of your life.
Getting enough calories, staying safe and warm, or caring for offspring was practically impossible alone. Being together meant survival, being alone meant death.
So it was crucial that you got along with others. For you ancestors, the most dangerous threat to survival was not being eaten by a lion, but not getting the social vibe of your group and being excluded. To avoid that, your body came up with "social pain".
Pain of this kind is is an evolutionary adaptation to rejection. A sort of early warning system to make sure you stop behaviour that would isolate you.
Your ancestors who experienced rejection as more painful were more likely to change their behaviour when they got rejected, and thus stayed in the tribe, while those who did not got kicked out and most likely died.
That's why rejections hurt, and even more so, why loneliness is so painful. These mechanisms for keeping us connected worked great for most of our history, until humans began building a new world for themselves.
The first thing you can do to escape it is to accept that loneliness is a totally normal feeling and nothing to be ashamed of.