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.

I'm lost in Linux, can somebody help me with an iptables command to allow only the IP Address 5.5.5.5 to access port 22?

I've got that port restricted to the same IP in the EC2 security group, but I need to block it on the instance itself as well.

share|improve this question
    
"I've got that port restricted to the same IP in the EC2 security group, but I need to block it on the instance itself as well." Why? –  ceejayoz Apr 27 '11 at 1:08
    
I want to verify that I am protected from other instances. I don't think this is excessive. If I am doubling up, then so be it. I'm a programmer daggumit! –  George W Bush Apr 27 '11 at 3:00
    
possible duplicate of Iptables: How to allow only one ip through specific port? –  George W Bush Apr 27 '11 at 3:02
1  
If you knew more about how virtual machines worked and how the network devices are "wired" together you would understand how un-necessary is. You will basically make an environment that is no more secure but with more points of failure and more difficult to troubleshoot and administer. Your time would be better spent making sure your ssh service itself was properly secured with keys and such. –  Caleb Apr 27 '11 at 8:21
    
I think the flaw in your reasoning is that you assume I am 100% effective at configuring EC2 security groups –  George W Bush Apr 27 '11 at 17:08
add comment

3 Answers

up vote 3 down vote accepted

Aren't you being a little excessive? Your instances on EC2 are nicely isolated from other traffic by their own private firewall on the virtual network device you are "plugged into" upstream.

iptables -A INPUT -p tcp -s 5.5.5.5/32 --destination-port 22 -j ACCEPT
iptables -A INPUT -p tcp --destination-port 22 -j REJECT
share|improve this answer
    
I want to verify that I am protected from other instances. I don't think this is excessive –  George W Bush Apr 27 '11 at 3:01
add comment

Try:

iptables -I INPUT 1 -p tcp --dport 22 -s 5.5.5.5 -j ACCEPT
iptables -I INPUT 2 -p tcp --dport 22 -j REJECT

This adds a rule which specifically allows access from that IP, then a rule which specifically denies it from everyone else.

share|improve this answer
add comment

This has also been covered in very similar posts: Iptables: How to allow only one ip through specific port?

Allow traffic on one port from one IP address with iptables

share|improve this answer
    
Right on, voting to close as dupe –  George W Bush Apr 27 '11 at 3:02
add comment

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.