Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 654  / 3 Years ago, fri, may 28, 2021, 8:30:40

I'm testing my webapplication which connects to two DBs. I can't stop them but I want to simulate outage of one of them.



So I opened one terminal where I'm pinging DB server:



 ping 172.21.7.188


In the second terminal I did:



sudo iptables -A INPUT -s 172.21.7.188 -j DROP
sudo iptables -A OUTPUT -d 172.21.7.188 -j DROP


But I don't see any change - pings still return. What am I doing wrong?


More From » networking

 Answers
6

While you may be using Ubuntu, this question is not Ubuntu-specific, but Linux-specific, so I think it would be better to ask it on ServerFault.






Answer to the original question (before OP edited it)



Your rule in INPUT chain is correct, but the rule in OUTPUT chain is wrong. You want to drop there packets addressed to the mentioned IP, not the ones coming from it (which is pointless in this chain).



That's why you have to change -s (--source) to -d (--destination) in the rule:



# iptables -A OUTPUT -d 172.21.7.188 -j DROP


But even when you were dropping only incoming packets, it was kind of enough, one could say. It's true that ping was returning (ICMP echo reply was reaching your host) without above line, and consulting tcpdump or wireshark would show ping-related datagrams (i.e. outgoing and incoming), but the ping application wasn't receiving incoming datagrams, because they were dropped.



Obviously it's rather unwise to drop only incoming packets in most of the cases, because it leads to different state on both ends of the connection (at connection level or at application level).






Answer to edited question



If after correction it still doesn't work, then I suspect your firewall has already some rules that make your new rules unreachable. The way you added your rules makes them appended at the end of the chain. You should remove your new rules first (same commands as for appending, but change -A to -D).



Now add your rules to the beginning of chains (i.e. insert them at given rule number 1) they are suited for (same commands as for appending, change -A to -I):



# iptables -I INPUT  -s 172.21.7.188 -j DROP
# iptables -I OUTPUT -d 172.21.7.188 -j DROP


Now it should work.


[#28985] Sunday, May 30, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
throecember

Total Points: 274
Total Questions: 118
Total Answers: 132

Location: India
Member since Thu, Jun 11, 2020
4 Years ago
;