LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 02: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, 03:13 PM   #2
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 116Reputation: 116
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, 08: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, 08:42 AM   #4
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

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


Reply



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-29-2008 11:18 PM
How can I block all traffic to port 110 to and IP using IPtables? abefroman Linux - Networking 8 11-16-2005 07:26 PM
Iptables help, block port to outside but open to inside. Brian1 Linux - Networking 2 09-27-2005 08:41 PM
iptables, block port 80? frank2 Linux - Security 4 09-12-2004 09:14 AM
Block incoming port Iptables cli_man Linux - Networking 5 08-11-2003 08:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:39 PM.

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
Open Source Consulting | Domain Registration