Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 0 down vote accepted
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
share|improve this answer
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.

share|improve this answer
    
i marked the other answer, he was faster. but thank you for your answer :-) –  user1015314 Mar 21 '12 at 12:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.