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 02-06-2015, 06:27 PM   #1
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Rep: Reputation: Disabled
iptables block IP


I need to block ip address using iptables in my router. In my router I'm forwarding port 22 to my computer. If I use iptables -A INPUT -s xx.xx.xx.xx -j DROP then I'm still able to ssh to my computer. What's the proper iptable to block IP in my router even when it's forwarding to my computer?
 
Old 02-06-2015, 06:40 PM   #2
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
Answer to my own question.

Quote:
iptables -I FORWARD -s xx.xx.xx.xx -j DROP
If there are other better methods please let me know

Last edited by Almaz; 02-06-2015 at 06:51 PM.
 
Old 02-09-2015, 10:53 AM   #3
nixtree
LQ Newbie
 
Registered: Feb 2015
Distribution: Linux Mint
Posts: 2

Rep: Reputation: Disabled
Hello Almaz,

Are you setting the rules in the router or in your computer ?
 
Old 02-09-2015, 10:54 AM   #4
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
Router
 
Old 02-09-2015, 11:13 AM   #5
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
Quote:
Originally Posted by Almaz View Post
If there are other better methods please let me know
I have found this link to be a valuable resource to iptables:
https://www.frozentux.net/documents/iptables-tutorial/

As with all low level programs like this, there are multiple solutions to a problem. So I wouldn't say there's a better method then yours (You wanted to block a ip address and you blocked it - case solved)

However, do you want to be more specific? Should the source ip you blocked want to access its.. webserver it would also be blocked.

So perhaps this will limit only what you want to limit. However note that any other ips can still connect should your policy be set to accept. (If it's to drop, then both this and yours are irrevelvant.)

Code:
iptables -A FORWARD -p tcp -s xxx.xxxx.xxx --dport 22 -j REJECT
REJECT just means it says something along the lines of "Connection Refused". If you want to be stealthy, change to drop.
--dport means destination port, -p refers to a specific protocol.

Last edited by Miati; 02-09-2015 at 11:14 AM.
 
Old 02-12-2015, 04:58 PM   #6
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Just so you understand what you've just done: the reason why you needed to use the FORWARD chain and not the INPUT chain was that INPUT refers to the packets the destination of which is the router itself, packets that are filtered by the kernel. Whereas packets not destined for the router itself (if you don't specify it otherwise) and are assigned to a different route by the router go directly through the FORWARD chain and then outside towards their destination. So it's PREROUTING - FORWARD - POSTROUTING - it skips the INPUT chain altogether, so therefore it's a more efficient way to use resources.

You should really take a look at some iptables schemes and documentation.

Last edited by vincix; 02-12-2015 at 05:00 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 - block in/out help rlbeaver Linux - Security 1 08-05-2013 07:41 PM
Iptables - How to block sites with Iptables. hackum Linux - Software 1 11-15-2011 07:05 PM
Block and allow with Iptables help! conrado Slackware 2 10-26-2007 10:31 AM
IPTABLES BLOCK ALL NON-US IP's cachemonet Linux - Security 3 06-14-2006 03:57 PM
IPTables and PPTPD :S (to block or not to block) thewonka Linux - Networking 0 03-24-2005 06:58 PM

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

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