0

My server has multiple IPs,

1.1.1.1
1.1.1.2

and i have a service which listens to a port e.g. 88

Now i want,

when somebody from outside, wants to connect to the port, that he can only connect, to that port, if he connects to the ip 1.1.1.2:88 but if he tries to connect to 1.1.1.1:88 it should not react and it should look like that it dont exists and drops all connections.

Ok, than i need for 1.1.1.2:88 that only allows a specific ip range outside connecters.

for example only 9.*.*.* can connect to that port and ip.

I'm using Centos. Thank you for your help.

2 Answers 2

0
iptables -A INPUT -s 9.0.0.0/8 -d 1.1.1.2 -p tcp -m tcp --dport 88 -j ACCEPT
iptables -A INPUT -d 1.1.1.2 -p tcp -m tcp --dport 88 -j DROP
iptables -A INPUT -d 1.1.1.1 -p tcp -m tcp --dport 88 -j DROP
2
iptables -A INPUT -s 9.0.0.0/8 -d 1.1.1.2 -p tcp --dport 88 -j ACCEPT

will restrict the source address (ie, who's making the connection) to 9.0.0.0/8, which is 9.*.*.* in your notation; it will restrict the destination address (ie, where they're connecting to) to 1.1.1.2; and it will only permit these for connections to the destination TCP port 88.

This assumes that (a) you already have a ruleset that forbids connections which aren't permitted, and (b) you get the rule in the right place in your ruleset. If you want more specific guidance than that, please amend your question with the output of iptables -L -n -v --line-number.

1
  • i marked the other answer, he was faster. but thank you for your answer :-) Mar 21, 2012 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .