My server keeps going offline after hours of it been stable. I believe it is DoS attacks but I'm really unsure how to block them, would I need to get a firewall? if I do would this help the problem?

I really need help with this guys.