If the pipe is as long as the rail drill or cut a small hole in the top so you can reach through and drill the pipe to the 2x4. If you don't have like an extended drill bit just drill the pipe to the wood at the ends. Use the 4x4 for legs(sometimes putting all the wood together is easier than after the pipe is on.) I usually cut up the 4x4 so a pieces go along with the 2x4 upright and then use renaming pieces flat as like feet to it if that makes sense.