LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 12-27-2008, 01:13 PM   #1
nausicaavow
LQ Newbie
 
Registered: Dec 2008
Posts: 2

Rep: Reputation: 0
simple Iptables filter script


After looking through the Iptables tutorial I think a simple example will help me to get started with learning this.

Can someone show me what a simple IP filter script would look like for use in order to block all inbound (unsolicited) traffic by default.

I only want TCP port 22 open (ssh) to the world.
And TCP port 21 open (ftp) to the local network (192.168.1.xxx).

I want port 80 and 443 to function normally for browser use.

Thanks for the help!
 
Old 12-27-2008, 04:05 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by nausicaavow View Post
After looking through the Iptables tutorial I think a simple example will help me to get started with learning this.

Can someone show me what a simple IP filter script would look like for use in order to block all inbound (unsolicited) traffic by default.

I only want TCP port 22 open (ssh) to the world.
And TCP port 21 open (ftp) to the local network (192.168.1.xxx).

I want port 80 and 443 to function normally for browser use.

Thanks for the help!
Code:
# block all inbound (unsolicited) traffic by default:
iptables -P INPUT DROP

iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT

# I only want TCP port 22 open (ssh) to the world:
iptables -A INPUT -p TCP --dport 22 --syn -m state --state NEW -j ACCEPT

# And TCP port 21 open (ftp) to the local network (192.168.1.xxx):
iptables -A INPUT -p TCP --dport 21 -s 192.168.1.0/24 --syn -m state --state NEW -j ACCEPT
This assumes you only have one NIC, otherwise you should specify which NIC to match against.

As for outbound connections to ports 80 and 443, that would be done in the OUTPUT chain. But since these rules here aren't touching that chain then they will be allowed by default, so web browsing should work just fine.

Last edited by win32sux; 12-27-2008 at 04:22 PM.
 
  


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
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
iptables v1.3.8: can't initialize iptables table `filter' sebastien.lorandel Linux - Networking 11 09-22-2007 06:34 AM
Simple iptables script problem. rookiepaul Linux - Security 4 05-01-2006 03:25 AM
iptables problem in a very simple script max_sipos Linux - Security 2 08-10-2004 06:58 AM
Differences between a simple packet filter, and a firewall... Grim Reaper Linux - Networking 9 03-06-2003 01:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 04:06 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
Open Source Consulting | Domain Registration