What size of lumber should I use for the mounting rail for shelves and cabinets?
Several different factors weigh in to what size of board you need.


Weight - Definitely the major factor.
Stud spacing - I'm assuming you've got standard 16" OC studs, and that you're attaching the support board to every one it spans.
Location of Mounting Points - The closer the mounts for the shelving are to centered between studs, the higher the bending load on the board.
Fastener Type - The thicker the fasteners used to fasten the board to the wall and the shelves to the board, the higher the stress concentration at those areas. Standard wood screws should be fine for fastening the board to the wall.
Use a Wide Board - The bending strength of a board goes up by a factor of width squared, and only linearly with thickness. So if you're flush mounting against a wall and don't have to worry about torsion, a 1x6 will be stronger than a 2x4.


Did you have a rough order of magnitude for the weight you'd like to hang? Just shooting from the hip, I'd think you'd be OK with a 1x4, or a 1x6 if you wanted to be safe.