Real-time simulation of truck and trailer combinations can be applied to hardware-in-the-loop (HIL) systems for developing and testing electronic control units (ECUs). The large number of configuration variations in vehicle and axle types requires the simulation model to be adjustable in a wide range. This paper presents a modular multibody approach for the vehicle dynamics simulation of single track configurations and truck-and-trailer combinations. The equations of motion are expressed by a new formula which is a combination of Jourdain's principle and the articulated body algorithm. With the proposed algorithm, a robust model is achieved that is numerically stable even at handling limits. Moreover, the presented approach is suitable for modular modeling and has been successfully implemented as a basis for various system definitions. As a result, only one simulation model is needed for a large variety of track and trailer types. The number of simulated axles of the track and the trailer can be changed during ran time without model adaptations. In addition, the same model can be used to simulate single track configurations as well as truck-and-trailer combinations. The model's modularity makes it useful for the whole development process of electronic stability control (ESC): from model-based-design (MBD) to software-in-the-loop (SIL) and finally to HIL systems.