The magnet/dielectric composites with tunable structure and composition have drawn much attention because of their particular merits in magnetoelectric properties compared with the sole dielectric or magnetic composites. In addition, porous materials at the nanoscale can satisfy the growing requirements in many industries. Therefore, constructing porous metal alloy/carbon nanocomposites is to be an admirable option. Unfortunately, traditional synthesis methods involve multistep routes and complicated insert-and-remove templates approaches. Here we report a facile process to synthesize CoNi/C composites via a spontaneous cross-linking reaction and subsequent calcination process, during which multiple processes, including reducing polyvalent metal ions, forming alloy, and encapsulating alloy nanoparticles into porous carbon matrix, are achieved almost simultaneously. By adjusting the feed ratio of Co to Ni ions, controllable composition of CoNi/C composites can be gained. It should be noted that the CoNi/C composites are demonstrated to be excellent microwave absorbers from every aspect of assessment criteria including reflection loss, effective bandwidth, thickness, and weight of absorber. Our study opens up a promising technique for the synthesis of alloy/carbon composites with porous nanostructures with target functionalities.