I am doing some testing and want to be able to test situations where my database goes down. Its running on the same box as my tests, and it appears that things like the following are not doing the trickiptables -A INPUT -p tcp --dport 25262 -j DROPiptables -A INPUT -p tcp --sport 25262 -j DROPiptables -A INPUT -p tcp --dport 25262 -i lo -j DROPiptables -A INPUT -p tcp --dport 25262 -s 127.0.0.1 -j DROPI am about to resort to killing my database process, move the file (because my database automatically comes back up on a crash), and let the test continue that way, but that seems like a terrible way to do it. What is the right way to block a port on loopback?
How do you block a port on your loopback?
networking;iptables
Command line command to DROP all loopback traffic (lo0)$ [sudo] iptables -I INPUT --dport 25262 -i lo -j DROPExplanationBecause iptables evaluates rules top to bottom and works on on a first match wins basis, you need to make sure your -i lo DROP rule is -I inserted to the top rather than -Aappended to the bottom of the rules, so it matches before another rule accepts the loopback traffic, e.g. if your DB was MySQL this rule might also matchINPUT -p tcp --dport 3306 ACCEPTso if you did command:$ [sudo] iptables -A INPUT --dport 25262 -i lo -j DROP                  ^^^ Notice the differenceyour rules would look like this:INPUT -p tcp --dport 3306 ACCEPT   ---> this wins and request is acceptedINPUT --dport 25262 -i lo -j DROPby running:$ [sudo] iptables -I INPUT --dport 25262 -i lo -j DROPyour final rules would look like:INPUT --dport 25262 -i lo -j DROP  ---> this wins and request is DROP'edINPUT -p tcp --dport 3306 ACCEPT ... all your other rules