firewalliptables

iptables block access to port 8000 except from IP address


I've never used iptables, and the documentation online seems a bit opaque.

I'd like to block all requests to port 8000 on my server except those coming from a specific IP address. How do I do that using iptables?


Solution

  • This question should be on Server Fault. Nevertheless, the following should do the trick, assuming you're talking about TCP and the IP you want to allow is 1.2.3.4:

    iptables -A INPUT -p tcp --dport 8000 -s 1.2.3.4 -j ACCEPT
    iptables -A INPUT -p tcp --dport 8000 -j DROP