Active site implantation and morphology manipulation are efficient protocols for boosting the electrochemical performance of carbon nitrides. As a promising sulfur host for lithium–sulfur batteries (LSBs), in this study, C3N5 porous nanostructure incorporated with both boron (B) atoms and nitrogen (N) defects was constructed (denoted as ND–B–C3N5) using a two-step strategy, i.e., pyrolysis of the mixture of 3-amino-1,2, 4-triazole and boric acid to obtain B-doped C3N5 porous nanostructure and then KOH etching under hydrothermal condition to generate N defects. The doped B atoms in the C3N5 porous nanostructure are in the form of B–N bonds and grafted B–O bonds. N defects are primarily created at the CN–C positions of the triazine unit, leaving behind some N vacancies and cyano groups. Benefiting from the involvement of B dopants and N defects, the optimized ND–B–C3N5–12 sample exhibits ameliorative conductivity, mass transport, lithium polysulfides (LiPSs) adsorption ability, diffusion of Li+ ions, Li2S deposition capacity, sulfur redox polarization, and a reversible solid–solid sulfur redox process. Consequently, the ND–B–C3N5–12/S cathode delivers accelerated redox performance of polysulfides for LSBs, revealing capacities of 1091 ± 44 and 753 ± 20 mAh/g at 0.2C for the initial and 300th cycles, respectively. The ND–B–C3N5–12/S cathode is also endowed with desired sulfur redox activity and stability at 2C for 1000 cycles, holding an initial discharging capacity of 788 ± 24 mAh/g and a low decay rate of 0.05 % per cycle.