Sodium nitrite (NaNO2) is a common chemical oilfield tracer in the field of reservoir geological analysis. A simple, sensitive, and accurate electrochemical detection method for detection of NaNO2 has been studied. The electrode carbon porous material was based on coal tar pitch n-pentane insoluble extractants (CTPNI) and doped with the elements of fluorine (F) and boron (B) and labeled as FB-CTPNI-PC and an electrochemical sensor modified with FB-CTPNI-PC material was constructed for rapid detection of NaNO2. The characterization results of SEM and TEM indicate that this material has certain number of pore structures, also the BET analysis showed that has main pore size distribution is around the range of 2–20 nm, with abundant mesoporous structure. Moreover, the modified electrode has a good electrocatalytic effect on NaNO2. The electrochemical reaction mechanism of NaNO2 on the surface of the modified electrode was a diffusion-controlled process involving protons. The detection range of NaNO2 can reach 0.1 mM–9.5 mM. When the S/N is 3, the sensitivity is 219.8592 A·L·cm2·mol−1 and the detection limit (LOD) is 0.011 μM. The constructed electrochemical sensor has been applied to the rapid detection of NaNO2 in real oilfield water, with recovery rates ranging from 99.7 % to 103.4 %. It is also roughly consistent with the results of ion chromatography (IC) in detecting NaNO2 in oilfield water, indicating that the sensor has high accuracy. This has provided a new prospect for oil filed tracer and detection technologies.