To test TCP connectivity

In the server machine

nc -lvk 8989

In client machine ( is the server address)

nc 8989 -v

Flag explanation

  • -l: listening instead of request
  • -v: verbose
  • -k: keep connection after one client exits. Note: in an UDP connection, this flag implies listening to multiple clients.

After connected, type some text from the client or server to send data. The connection can be terminated with EOF character via Ctrl-D key stroke.

To test an UDP connection

Add -u flag to both commands.

Allow/disallow a port with ufw tool

Check status: sudo ufw status

If the status is inactive, you need to activate it with sudo ufw enable. To disable it after experiment, use sudo ufw disable.

To open a TCP port: sudo ufw allow 8989/tcp. Similarly, to open an UDP port sudo ufw allow 1191/dcp.

To close a TCP/UDP port, change the action word from allow to disallow.

sudo ufw disallow 8989/tcp
sudo ufw disallow 8989/udp

Happy code <3