Many research efforts on application of ontology in network security have been done in the past decade. However, they mostly stop at initial proposal or focus on framework design without detailed representation of intrusion or attack and relevant detection knowledge with ontology. In this paper, the design and implementation of ontology-based knowledge representation for a peer-to-peer multi-agent distributed intrusion detection system (ontology-based MADIDS) are introduced. An example which demonstrates the representation of an attack with ontology and the relevant detection process is also presented. In ontology-Based MADIDS, ontology technique enables peers in the system and agents in one peer to share common understanding of information. In addition, benefited from agent technology and P2P architecture, agents in ontology-based MADIDS not only detect attacks on a single host but also in a distributed domain. These features make the ontology-based MADIDS more flexible and robust.