How to Block an IP Address with iptables in Docker?

0
9
Asked By CuriousCoder42 On

I'm trying to block a specific IP address while using Docker, but I'm running into issues because Docker integrates with iptables. I attempted to use UFW, but it seems like the deny rules are placed outside of Docker's flow, meaning Docker processes the packet before it even hits the UFW rules.

I'm considering creating a new chain called BLACKLIST, adding the IP address there, and setting it up so that it returns if there's no match. The idea would be for the FORWARD chain to route through BLACKLIST before passing everything onto the Docker chains.

Does this sound like a good strategy? Also, will this setup remain in place after restarting the system or Docker itself?

2 Answers

Answered By TechSavvy112 On

You can use the DOCKER-USER chain and add your rule at the top like this: `iptables -I DOCKER-USER 1 -s -j DROP`. This ensures that your rule is evaluated first for incoming packets meant for Docker containers. Good luck making it persistent though! Let me know if you figure that part out!

Answered By DockerDude9 On

Give it a shot and let us know how it goes! It can help a lot of people who run into the same issue.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.