In this paper, we solve a fundamental problem: how to use distributed random access to achieve the performance of centralized schedulers. We consider wireless networks with arbitrary topologies and spatial traffic distributions, where users can receive traffic from or send traffic to different users and different communication links may interfere with each other. The channels are assumed heterogeneous, and the random channel gains of different links may have different distributions. To resolve the network contention in a distributed way, each frame is divided into contention and transmission periods. The contention period is used to resolve conflicts, while the transmission period is used to send payload in collision-free scenarios. We design a multistage channel-aware Aloha scheme for the contention period to enable users with relatively better channel states to have higher probabilities of contention success while assuring fairness among all users. We show analytically that the proposed scheme completely resolves network contention and achieves throughput close to that of centralized schedulers. Furthermore, the proposed scheme is robust to any uncertainty in channel estimation. Simulation results demonstrate that it significantly improves network performance while maintaining fairness among different users. The proposed random access approach can be applied to different wireless networks, such as cellular, sensor, and mobile ad hoc networks, to improve quality of service.