Open and Close Port in Linux

For more secure server, we have to close some ports to users. If need access to this ports, we can give permission to our IP address. We need static IP address for this operation. Please dont forget, “iptables” can be block all IP address but when you restart the server it will be clean all of this commands. (I am using Fedora)

Closing FTP port except xxx.xxx.xxx.xxx

iptables -t filter -I INPUT 1 -p tcp -s ! xxx.xxx.xxx.xxx –dport 21 -j REJECT –reject-with icmp-host-prohibited

Closing SSH port except xxx.xxx.xxx.xxx

iptables -t filter -I INPUT 1 -p tcp -s ! xxx.xxx.xxx.xxx –dport ssh -j REJECT –reject-with icmp-host-prohibited

Closing MySQL port except localhost

iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp –destination-port 3306 -j ACCEPT

Listing iptables list

iptables -L

Removing iptables data (Removing first one in list, type 2 for second one)

iptables -D INPUT 1

Share and Enjoy:
  • StumbleUpon
  • Digg
  • TwitThis
  • FriendFeed
  • del.icio.us
  • MySpace
  • Technorati
  • Facebook
  • Google Bookmarks
  • Live

Enjoy this article?

Consider subscribing to our RSS feed!

Share us Facebook, FriendFeed, Digg

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

1 Comment

  1. admin
    03:32 on May 29th, 2009

    Test comment.

Sorry, the comment form is closed at this time.