Test connectivity between two machines with netcat
To test TCP connectivity
In the server machine
nc -lvk 8989
In client machine (
example.com is the server address)
nc example.com 8989 -v
-l: listening instead of request
-k: keep connection after one client exits. Note: in a 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 the EOF character via
To test a UDP connection
-u flag to both commands.
Allow/disallow a port with
sudo ufw status
If the status is inactive, you need to activate it with
sudo ufw enable. To disable it after the experiment, use
sudo ufw disable.
To open a TCP port:
sudo ufw allow 8989/tcp. Similarly, to open a UDP port
sudo ufw allow 1191/dcp.
To close a TCP/UDP port, change the action word from
sudo ufw disallow 8989/tcp sudo ufw disallow 8989/udp
Happy code <3