A novel nitrogen doped porous onion carbon (NDPOC) material was prepared by using [HMIm]N(CN)2 as carbon and nitrogen source. The transmission electron microscopy (TEM) and scanning electron microscopy (SEM) revealed that the NDPOC had a uniform porous structure and was wrapped by onion structured carbon. When used as the anode material for lithium ion batteries, this material not only prevented the collapse and breakage of the pores, but also facilitated the lithium ion migration and electron transfer. The NDPOC anode showed excellent discharge specific capacity (805 mAh g−1 of 0.1C after 50 cycles), rate performance, and cycle stability (306 and 267 mAh g−1 at 5 and 10C after 300 and 500 cycles, respectively).