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 01-21-2007, 12:14 AM   #1
owbr4dh02
LQ Newbie
 
Registered: Jan 2007
Posts: 14

Rep: Reputation: 0
Question iptables - interfaces, ports restrictions


Hi All,

How can I

1. restrict port 22 traffic to the x.x.x.x interface to only allow incoming traffic from x.x.x.0/25

2. allow all incoming port 22 traffic to the y.y.y.y interface

Thanks for any help.
 
Old 01-21-2007, 12:35 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
assuming a default drop policy

1. you want ssh connection from your machine to be allowed, but only from a particular net? I think that's something like:
iptables -A INPUT -p tcp -i eth1 -s x.x.x.0\24 -j ACCEPT -dport 22

2. so similarily:
iptables -A INPUT -p tcp -i eth0 -j ACCEPT -dport 22

if eth1 is x.x.x.x and eth0 is y.y.y.y

Last edited by Simon Bridge; 02-04-2007 at 05:46 PM.
 
Old 01-21-2007, 11:37 PM   #3
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
Quote:
Originally Posted by owbr4dh02
Hi All,

2. allow all incoming port 22 traffic to the y.y.y.y interface

Thanks for any help.

In the configuration file for the ssh server /etc/ssh/sshd.config you can set the ssh server to only listen on the ipaddress of the interface you specify, it will then refuse connection on any other interface. For example if you ssh server runs and ipaddress of 192.168.1.1 you would have something like this:

Code:
ListenAddress 192.168.1.1
 
Old 01-22-2007, 10:53 PM   #4
owbr4dh02
LQ Newbie
 
Registered: Jan 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Hi Simon Bridge, fotoguy !

Thank you very much for your help!
 
Old 01-23-2007, 04:07 AM   #5
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
Quote:
Originally Posted by owbr4dh02
Hi Simon Bridge, fotoguy !

Thank you very much for your help!

Glad to help out, if you would like to make it even more secure you can change the default port that ssh listens on to a completely different port. In the /etc/ssh/sshd.config you will see the #Port 22, just remove the hash symbol (uncomment), change the port to anything eg. Port 6893 then restart the ssh server and it will now listen to port 6893 for connectiosn.
 
Old 01-23-2007, 10:14 AM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by fotoguy
Glad to help out, if you would like to make it even more secure you can change the default port that ssh listens on to a completely different port. In the /etc/ssh/sshd.config you will see the #Port 22, just remove the hash symbol (uncomment), change the port to anything eg. Port 6893 then restart the ssh server and it will now listen to port 6893 for connectiosn.
hi, i don't mean to nit-pick, but i just wanted to comment that, technically speaking, changing the port ssh listens on has absolutely no effect as far as security is concerned... obscurity doesn't give more security...

but yes, having it listen on another port does have its benefits, such as making an ssh daemon less prone to getting picked-up by spiders, etc... but that's not in any way shape or form an increase in the security level...
 
Old 01-23-2007, 09:55 PM   #7
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
Quote:
Originally Posted by win32sux
hi, i don't mean to nit-pick, but i just wanted to comment that, technically speaking, changing the port ssh listens on has absolutely no effect as far as security is concerned... obscurity doesn't give more security...

but yes, having it listen on another port does have its benefits, such as making an ssh daemon less prone to getting picked-up by spiders, etc... but that's not in any way shape or form an increase in the security level...

Yes that is true, I should have said that it will help to minimise the threats from automated programs/scripts which target port 22 by default.
 
Old 01-25-2007, 04:58 AM   #8
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
Thank you very much for your help!
Glad to be of assistance (as the door said to Zaphod Beeblebrox)... so did this actually work?
 
Old 02-04-2007, 12:44 AM   #9
Sertys
Member
 
Registered: Oct 2006
Posts: 42

Rep: Reputation: 15
It ain't working, just because "-t" stands for "table".

so the rules gotta be :
iptables -P INPUT DROP
#default policy of the chain
iptables -A INPUT -p tcp --dport 22 -i eth1 -s x.x.x.x -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -i eth0 -j ACCEPT
#any other allowed ports go below(may use multiport..)
iptables -A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
 
Old 02-04-2007, 05:46 PM   #10
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
I'm sorry, that should be -p (protocol). I'll edit the previous post so folk don't get confused.
 
  


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 and virtual interfaces redhat_help Linux - Security 2 03-19-2006 03:24 PM
iptables on rh9 with 3 interfaces doza Linux - Networking 0 08-05-2005 02:54 PM
IPTables and multiple interfaces MaverickApollo Linux - Networking 7 12-28-2003 04:19 PM
two interfaces IPTABLES forwarding weazy Linux - Networking 1 03-18-2003 08:27 AM
netfilter iptables and multiple interfaces raypen Linux - Networking 1 07-23-2002 09:07 PM

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

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