LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-29-2006, 09:03 PM   #1
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 504

Rep: Reputation: 31
Smile Need Iptables command for a particular cond.


Dear friend,

Suppose I ahve a Network 192.168.10.0/24 . I have a Linux/Nat Server which IP is
192.168.10.1 . Now i have 5 clients whose IP is serially 192.168.10.2 3 4 5 & 6 .
In this moment when i write the following IPTABLES command ,

iptables -A INPUT -p tcp -s 192.168.10.0/24 --dport 80 -j REJECT

Then all of my Network pc cannot connect with my Linux Server . But i want to make a
situation where only 192.168.10.5 can access 80 port of my linux server and any other
machine cannot use 80 port of my linux machine . Is there any IPTABLES Command in this
condition ?
 
Old 03-29-2006, 09:08 PM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Just make two rules. The first rule specifies to accept the connection from that specific IP address, the second rule then denies access (just as you have it now). Just make sure the "accept" rule comes before the "reject" rule.
 
Old 03-29-2006, 09:13 PM   #3
Jeiku
Member
 
Registered: Jul 2005
Posts: 64

Rep: Reputation: 18
iptables -A INPUT -p tcp -s ! 192.168.10.5 --dport 80 -j REJECT

 
Old 03-31-2006, 01:57 AM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Jeiku
iptables -A INPUT -p tcp -s ! 192.168.10.5 --dport 80 -j REJECT
this is not such a good idea... you'd be sending answers to queries on the WAN side also... your best bet is to set the INPUT policy to DROP, and then use use more specific rules for your LAN, like this (assuming your LAN interface is eth1):
Code:
iptables -P INPUT DROP

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

iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -p TCP -i eth1 -s 192.168.10.5 \
--dport 80 -m state --state NEW -j ACCEPT

iptables -A INPUT -p TCP -i eth1 -s 192.168.10.0/24 \
--dport 80 -m state --state NEW -j REJECT
of course this assumes that you want to send a REJECT to the non-authorized machines on your LAN so that they don't hang or whatever... cuz you really don't *need* any REJECT rule to do this, as the --dport 80 packets which aren't from 192.168.10.5 will run smack into the DROP policy either way...

Last edited by win32sux; 03-31-2006 at 02:26 AM.
 
  


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
An error occured getting IPtables status from the command /etc/rc.d/init.d/iptables s CrazyMAzeY Linux - Newbie 10 08-12-2010 05:25 AM
Iptables command cmptrguru7 Linux - Networking 9 03-06-2006 10:08 AM
Redirect cond mail ? michaelsanford Linux - Newbie 2 07-23-2005 01:00 PM
iptables command/iptables GUI? basketkase999 Linux - Security 5 04-12-2005 02:43 PM
need iptables command for... di11rod Linux - Security 5 01-28-2004 04:34 PM

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

All times are GMT -5. The time now is 03:21 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