Getting your socks to turn out like a matching pair isn't always easy in self-striping yarn, especially if it's a large repeat of various color stripes. The other day, I was looking down at my feet and realized that this pair I had made for myself matched up just about perfectly. Not only that, but look how random those stripes look, since it's such a long time before the pattern repeats again.
So, goofy as I am, I rolled up my pant legs and took a picture.
Yes, there's an element of luck in this. If you are unlucky enough to get yarn that isn't dyed evenly, it isn't going to match up. However, most high-quality sock yarn that is dyed in stripes will have the same length stripes each time the striping pattern repeats.
When you start the sock, start just at the beginning of a new color, that is, try to make that first stitch be knitted in that first bit of the new color. When you start the second sock, you have to wind off enough of the yarn to get to that same point in the repeat, and then use that same color for your first stitch. That starts both socks with the same stripe, and the rest follows along. Yes, it usually wastes some yarn, but you can use that yarn later for something else. I find that when I purchase two 50-gram balls of yarn for a pair of socks in my size (ladies' medium - I wear a size 8 show) that I always leftover yarn.
One more thought - if you rewind the yarn before knitting the socks, make sure that you rewind each ball the same number of times. That is, if you elect to wind the yarn more than once - for instance, because you think it's wound too tightly or you had to rip out, well, rewinding will reverse the direction of the yarn.