You didn't give us much detail to go on.
If the cabinet is just going to have normal things like TP, paper towels, tooth paste, hair spray, you know stuff like that it is not likely going to be all that much weight. If you are going to store heavy stuff then it might be another story.
You did not mention the construction of the cabinet, if the back is say 1/2" plywood that is a lot different then just frame and open back.
How well the back is attached can be another issue, assuming it has a back.
So despite the missing information you did give us the measurements so I did a very ruff sketch to get the feel for what you have.

It is pretty clear to me that if it has a back that is well attached and at least 1/4" thick plywood and if it will be a reasonable uniform load then just screw it to the 2x4 with cabinet head screws like maybe 4 or 5 places and you are good to go.
Ed