LinuxQuestions.org
Review your favorite Linux distribution.
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 05-27-2008, 11:38 PM   #1
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Rep: Reputation: 15
2 IPs - need to block different ports on each


Hello all.

Here is my setup.

eth0 - 192.168.0.50
eth0:1 - 192.168.0.60


I would like to let my specified trafic to eth0.
( listed below )

But only allow eth0:1 to use ftp-data:ftp


iptables -L
Code:
Chain INPUT (policy DROP)
target     prot opt source               destination
DROP       tcp  --  anywhere             anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN state NEW
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN/FIN,SYN
DROP       tcp  --  anywhere             anywhere            tcp flags:SYN,RST/SYN,RST
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,PSH,URG
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG
ACCEPT     all  --  localhost            localhost
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  default              anywhere
ACCEPT     all  --  anywhere             anywhere            state ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request state NEW,RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:sftp
ACCEPT     tcp  --  cpe-76-174-0-0.socal.res.rr.com/76.174.0.0  anywhere            tcp dpt:www
ACCEPT     tcp  --  192-168-0-74.mydomain.com  anywhere            tcp dpt:mysql
DROP       all  --  192.168.0.60  	 anywhere
ACCEPT     tcp  --  192.168.0.60  	 anywhere            tcp dpts:ftp-data:ftp



Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
Is this close to correct?

I can still ping eth0:1 (192.168.0.60)

Does the order they are listed in matter?

Also my sftp not working.


Any help is appreciated.

Jon
 
Old 05-28-2008, 01:03 AM   #2
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Original Poster
Rep: Reputation: 15
[solved] as far as I know...

Ok, I needed to be more specific in writing the rules.
I had not used -d for the destination IP.

iptables -A INPUT -p all -s 0.0.0.0 -d 192.168.0.50 -j ACCEPT


Here is the result.

iptables -L
Code:
Chain INPUT (policy DROP)
target     prot opt source               destination
DROP       tcp  --  anywhere             anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN state NEW
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN/FIN,SYN
DROP       tcp  --  anywhere             anywhere            tcp flags:SYN,RST/SYN,RST
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,PSH,URG
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG
ACCEPT     all  --  anywhere             anywhere            state ESTABLISHED
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  localhost            localhost
ACCEPT     all  --  192.168.1.0/24       192.168.1.3
ACCEPT     all  --  default              192.168.0.50
ACCEPT     icmp --  default              192.168.0.50 icmp echo-request state NEW,RELATED,ESTABLISHED
ACCEPT     tcp  --  default              192.168.0.50 tcp dpt:ssh
ACCEPT     tcp  --  default              192.168.0.50 tcp dpt:sftp
ACCEPT     tcp  --  default		 192.168.0.50 tcp dpt:www
ACCEPT     tcp  --  mysql.mydomain.com   192.168.0.50 tcp dpt:mysql
ACCEPT     tcp  --  default              192.168.0.60 tcp dpts:ftp-data:ftp

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Everything seems to be working well now and 192.168.0.60 only use the ftp ports.

I may need to add
-m state --state NEW,ESTABLISHED,RELATED
to the rest of my rules.


Thank you for taking the time to view the post.

Jon
 
Old 05-28-2008, 12:31 PM   #3
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Glad to see you got it working. BTW, another approach could be to stick the alias IP rule(s) at the top, and remove the destination IP from the real IP rules. That way you wouldn't need to worry about changing the rules if the real IP ever changes. Also, in cases such as this I would usually create a dedicated chain for the alias IP, with a DROP or REJECT rule at the end. Just a thought.
 
Old 05-30-2008, 10:49 PM   #4
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Original Poster
Rep: Reputation: 15
Hi Win32Sux and thanks for the reply.

I tried the approach from this post.
http://www.linuxquestions.org/questi...5/#post3162072

Now were you talking about creating another chain for the ftp IP only?
Not sure if I am following you or not...

iptables -L -n
Code:
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  127.0.0.1            127.0.0.1
ACCEPT     all  --  192.168.1.0/24       192.168.1.3         state NEW,RELATED,ESTABLISHED
tcp_packets  tcp  --  0.0.0.0/0            0.0.0.0/0
udp_packets  udp  --  0.0.0.0/0            0.0.0.0/0
icmp_packets  icmp --  0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state NEW,RELATED,ESTABLISHED

Chain icmp_packets (1 references)
target     prot opt source               destination
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           state ESTABLISHED
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 8

Chain tcp_packets (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            192.168.0.50       tcp dpt:22 state NEW,RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            192.168.0.50       tcp dpt:115 state NEW,RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            192.168.0.50       tcp dpt:80 state NEW,RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            192.168.0.60       tcp dpts:21:22 state NEW,RELATED,ESTABLISHED
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:!0x17/0x02 state NEW
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x03/0x03
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x06
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x29
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x01
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x3F

Chain udp_packets (1 references)
target     prot opt source               destination
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           state ESTABLISHED
ACCEPT     udp  --  0.0.0.0/0            192.168.0.50       udp dpts:50000:50004
ACCEPT     udp  --  0.0.0.0/0            192.168.0.50       udp dpt:554
ACCEPT     udp  --  0.0.0.0/0            192.168.0.50       udp dpt:8554
I read in your post you thought this method was more complicated, maybe than it needs to be. But I figure if there is any benefit I will try it.

Jon
 
Old 05-31-2008, 01:59 AM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by jchambers View Post
Now were you talking about creating another chain for the ftp IP only?
Not sure if I am following you or not...
Yeah, I was talking about creating a chain specifically for packets heading into 192.168.0.60, as that IP was meant to get special treatment. Keep in mind that, when I said that, you had only the INPUT chain, unlike what you have now which is chains for each protocol.

If I was you, I'd probably just stick with two user-built chains - a bad packet one and the alias IP one. But that's just me. That said, even with all the protocol-specific chains you now have, I do see a lot of redundant and unnecessary rules. For example, there's no reason why you would need more than one rule for packets in ESTABLISHED or RELATED states. Also, the RELATED match doesn't directly apply to any of your rules (aside from the FTP one) - so I'm not sure why you are specifying it per-rule.

Quote:
I read in your post you thought this method was more complicated, maybe than it needs to be. But I figure if there is any benefit I will try it.
There are benefits sometimes. Some are technical, others are subjective. For example, if you have a crapload of UDP packets coming into your box (like, say you run a popular video game or DNS server or something), there's no reason why they should have to traverse a bunch of rules which are written to check for bad TCP packets. So having a rule that lets UDP packets bypass all of those TCP packet checks can be a good idea. It's just an example, of course.

As for the subjective benefits, some people find scripts easier to manage with a bunch of chains. Others find them easier to manage without any user-built chains, or with a minimal amount of them. There are differences in the types and purposes of chains people prefer, too. For example, I tend to lean more toward chains made per IP, privilege level, etc. and not so much for traffic type. But like everything, it depends.

Last edited by win32sux; 05-31-2008 at 02:06 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
i want to block a range of ips using iptables... Vasili Linux - Security 18 09-19-2006 06:31 AM
block ips in valknut kb_ganesh Linux - Networking 0 12-01-2005 10:36 AM
want to block some prots on some IPs......? shahg_shahg Linux - Networking 1 07-01-2005 12:38 PM
How to block specific IPs? cranium2004 Linux - Networking 3 04-01-2005 09:02 AM
block all IPs except one how in my setup?? cranium2004 Linux - Networking 3 03-20-2005 03:24 PM

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

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