A method of stacking network devices, wherein the method comprising: determining, by a network device, a device role of the network device, wherein the device role has been customized according to a type of the network device; sending, by the network device, a first neighbor discovery message to a neighbor device, wherein the first neighbor discovery message carries at least the device role and a bridge Media Access Control, MAC, address of the network device; receiving, by the network device, a second neighbor discovery message sent by the neighbor device which carries at least a device role and a bridge MAC address of the neighbor device; determining, by the network device, whether a topological structure between the network device and the neighbor device changes or not according to the second neighbor discovery message; determining, by the network device, whether a stacking condition to trigger stacking the network device and the neighbor device is satisfied or not when it is determined that the topological structure changed; determining, by the network device, a stacking configuration for stacking the network device and the neighbor device when it is determined that the stacking condition is satisfied; and stacking, by the network device, the network device and the neighbor device according to the stacking configuration, wherein the stacking condition comprises that: the device role of the network device is the same as the device role of the neighbor device; and the bridge MAC address of the network device is different from the bridge MAC address of the neighbor device. determining, by a network device, a device role of the network device, wherein the device role has been customized according to a type of the network device; sending, by the network device, a first neighbor discovery message to a neighbor device, wherein the first neighbor discovery message carries at least the device role and a bridge Media Access Control, MAC, address of the network device; receiving, by the network device, a second neighbor discovery message sent by the neighbor device which carries at least a device role and a bridge MAC address of the neighbor device; determining, by the network device, whether a topological structure between the network device and the neighbor device changes or not according to the second neighbor discovery message; determining, by the network device, whether a stacking condition to trigger stacking the network device and the neighbor device is satisfied or not when it is determined that the topological structure changed; determining, by the network device, a stacking configuration for stacking the network device and the neighbor device when it is determined that the stacking condition is satisfied; and stacking, by the network device, the network device and the neighbor device according to the stacking configuration, wherein the stacking condition comprises that: the device role of the network device is the same as the device role of the neighbor device; and the bridge MAC address of the network device is different from the bridge MAC address of the neighbor device. the device role of the network device is the same as the device role of the neighbor device; and the bridge MAC address of the network device is different from the bridge MAC address of the neighbor device.