The construction of electronic devices from single molecular building blocks, which possess certain functions such as switching or rectifying and are connected by atomic-scale wires on a supporting surface, is an essential goal of molecular electronics. A key challenge is the controlled assembly of molecules into desired architectures by strong, that is, covalent, intermolecular connections, enabling efficient electron transport between the molecules and providing high stability. However, no molecular networks on surfaces 'locked' by covalent interactions have been reported so far. Here, we show that such covalently bound molecular nanostructures can be formed on a gold surface upon thermal activation of porphyrin building blocks and their subsequent chemical reaction at predefined connection points. We demonstrate that the topology of these nanostructures can be precisely engineered by controlling the chemical structure of the building blocks. Our results represent a versatile route for future bottom-up construction of sophisticated electronic circuits and devices, based on individual functionalized molecules.