Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 806
will Avatar asked Sep 14 '11 21:09

will


People also ask

How do I block iptables ports?

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.

How do I add an iptables rule?

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.

What is the iptables Linux?

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.


1 Answers

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 
like image 98
Jon Bright Avatar answered Sep 19 '22 01:09

Jon Bright