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?
To block the port only on a specific interface use the -i option. To block port only for given IP or Subnet use the -s option to specify the subnet or IP addess. Save the iptables for rules to be persistent across reboots. Save the iptables for rules to be persistent across reboots.
To insert a new rule above a specific existing rule, simply use the index number of that existing rule. For example to insert a new rule to the top of the chain, use the following command with index number 1. It's also possible to flush all rules of a specific chain or even the whole iptables using the -F -parameter.
iptables is a user-space utility program that allows a system administrator to configure the IP packet filter rules of the Linux kernel firewall, implemented as different Netfilter modules. The filters are organized in different tables, which contain chains of rules for how to treat network traffic packets.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With