1

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.

5
  • "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, 2011 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! Apr 27, 2011 at 3:00
  • possible duplicate of Iptables: How to allow only one ip through specific port? Apr 27, 2011 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, 2011 at 8:21
  • I think the flaw in your reasoning is that you assume I am 100% effective at configuring EC2 security groups Apr 27, 2011 at 17:08

3 Answers 3

4

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
1
  • I want to verify that I am protected from other instances. I don't think this is excessive Apr 27, 2011 at 3:01
1

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.

0

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

1
  • Right on, voting to close as dupe Apr 27, 2011 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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