Undergrad for sure. By graduate school I was married (master's) or had child(ren) (PhD), and I did not live near campus.
During my master's degree I was basically working full-time so I only went to campus for class and then left, I didn't make any friends at all. I'm sure it's different if it's Med School or Law School, especially if you go right after undergrad like most do.
My best friends 30 years later are my friends from where I went to undergrad and I've been to multiple college reunions.