LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-01-2011, 03:59 PM   #1
PinoyAko
LQ Newbie
 
Registered: May 2011
Posts: 28

Rep: Reputation: 0
iptables - block a port


I am currently using this to block ports in my server but I think this is not the best way. Can you please give the proper way to do this?

Code:
iptables -A FORWARD -j DROP -p tcp --dport $PORT -i eth+
iptables -A FORWARD -j DROP -p tcp --dport $PORT -o eth+
iptables -A INPUT -j DROP  -p tcp --dport $PORT -i eth+
iptables -A OUTPUT -j DROP - -p tcp --dport $PORT -o eth+
Thank you
 
Old 06-01-2011, 04:13 PM   #2
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 115Reputation: 115
Set the default policy for INPUT to DROP.

Then only create ACCEPT rules for specific ports you want to block.


For FORWARD set the default policy to DROP unless you know you need otherwise.

For OUTPUT leave the default policy at ACCEPT and create specific rules if needed for blocking outbound ports or port ranges.
 
Old 06-02-2011, 09:22 AM   #3
PinoyAko
LQ Newbie
 
Registered: May 2011
Posts: 28

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by zordrak View Post
Set the default policy for INPUT to DROP.

Then only create ACCEPT rules for specific ports you want to block.
I believe this to be the ports I want to OPEN?
 
Old 06-02-2011, 09:42 AM   #4
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 115Reputation: 115
Yeah, my bad.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to block port 139 using iptables bkcreddy17 Linux - Security 22 09-30-2008 12:18 AM
How can I block all traffic to port 110 to and IP using IPtables? abefroman Linux - Networking 8 11-16-2005 08:26 PM
Iptables help, block port to outside but open to inside. Brian1 Linux - Networking 2 09-27-2005 09:41 PM
iptables, block port 80? frank2 Linux - Security 4 09-12-2004 10:14 AM
Block incoming port Iptables cli_man Linux - Networking 5 08-11-2003 09:32 PM


All times are GMT -5. The time now is 03:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration