Back to the learning path

iptables

iptables: IP (packet filter) tables Command details
Step 1/1: Block a port

iptables manages the kernel's firewall rules (root needed). Rules live in chains: INPUT for incoming packets, OUTPUT outgoing, FORWARD passing through. -A CHAIN appends a rule, -p tcp --dport PORT -d HOST matches packets, -j REJECT refuses them (the other side knows at once), -j DROP drops them (it has to time out). iptables -S lists the rules, -D deletes one.

$ sudo iptables -A OUTPUT -p tcp --dport 5432 -j REJECT
Advancediptablesncnetwork
Block the database port
In the internal network db01 serves a database on port 5432 (try nc db01 5432 first; Ctrl+C quits). Add an iptables rule so this machine cannot reach port 5432 on db01 (REJECT or DROP, either works). Needs sudo.

This exercise needs real Linux

The commands it uses (processes, networking and more) are not in the simulator. Switch to real Linux and the exercise runs in a real Linux system inside your browser.

rsync