Installing the knockd daemon, and configuring the sequence and packet types to be used to open and close ports, and using the knock client to actually do it from the other side:
https://www.howtogeek.com/442733/how-to-use-port-knocking-on-linux-and-why-you-shouldnt/