The invention relates to a method and
system for testing optical modules by using one
server, and the method comprises the following steps: connecting two optical modules to be tested, which need to be streamed, to two
Ethernet ports of one
server, and connecting the two optical modules to be tested, which need to be streamed, with a switch through optical fibers; aiming at two
Ethernet ports connected with two to-be-tested optical modules needing streaming, two independent network namespaces are created on a
server, and the two
Ethernet ports are respectively distributed to the two network namespaces; allocating an IP (
Internet Protocol) for a network card in each network
namespace, setting default routes for the two network namespaces, respectively pointing to the IP of the logic port of the butted switch, and configuring the IP of the logic port corresponding to the switch, so that the network
namespace in which each Ethernet port is located and the logic port of the butted switch are located in the same
network segment; the network segments of the two network namespaces are different from each other, and the switch can forward the traffic of the two network segments; and testing the flow between the two optical modules to be tested.