Skip to content

Networking

iptables

install iptables in fedora os

sudo dnf install -y iptables iptables-services
sudo systemctl enable iptables
sudo systemctl start iptables

Allow traffic from a specific host on port 3002

sudo iptables -A INPUT -p tcp -s <ALLOWED_HOST_IP> --dport 3002 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 3002 -j DROP

View rules

sudo iptables -L INPUT -n --line-numbers

Insert a rule before an existing rule

sudo iptables -I INPUT 5 -p tcp -s <ALLOWED_HOST_IP>  --dport 3002 -j ACCEPT

Delete a rule by line number

sudo iptables -D INPUT 9

Save the rules so they persist after reboot

sudo iptables-save | sudo tee /etc/sysconfig/iptables

Ensure the iptables service starts on boot

sudo systemctl enable iptables

Useful Commands

displays all processes listening on TCP and UDP sockets, along with their numeric IP addresses, port numbers, and associated PIDs/program names.

sudo ss -ltunp | grep :3002

#or

sudo lsof -nP -iTCP -sTCP:LISTEN -iUDP  -i :3002

#or

sudo netstat -tulnp | grep :3002

Connectivity check

Command Description
nc -zv <SERVER_IP> 3002 Tests whether a TCP connection can be established to port 3002 on the remote host.
telnet <SERVER_IP> 3002 Attempts to establish a TCP connection to port 3002 on the remote host.
curl http://<SERVER_IP>:3002 Sends an HTTP request to the service listening on port 3002.
nc -zvu <SERVER_IP> 3002 Sends a UDP probe to port 3002 to verify UDP connectivity (best-effort; UDP has no connection handshake).