My friend is starting a Necron army, and I was going to start a Space Marine army, but Necrons are really an interesting army to play, while the Space Marines are very generic. Could I build a Necron army and fight his Necron army? Is this against the rules?
There is nothing in the rules to prevent two armies from the same codex from fighting one another. I would just be sure that you can tell who each model belongs to; this is not too difficult once they are painted, but it could be easy to lose track of who is on which side if there are all just bare plastic.
With the current fluff, Necrons Overlords have their own Dynasties and it is easy to justify a power struggle between two of them. Most other codexes can have fluff reasons to fight amongst themselves.
Any army can fight against any other army, even Space Marines of the same chapter.
It depends on how much you care about the story of your battles as to how odd this may feel.
If you are just playing games, it won't be an issue. If you want to run a coherent story or campaign then you'll need to justify why the two armies are fighting, and that may be difficult.
Short answer: If you both want to play with same armies, I don't see what the issue is; AS LONG as you know which models belong to who.
If you want to be a player that respects lore, then 2 players might not be able to play the same race v each other (haven't played for a while, but -> Imperials would not fight each other, whereas Orks totally would.) So Necrons could fight each other and it would make sense.