LinuxQuestions.org
Visit Jeremy's Blog.
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-09-2007, 03:57 AM   #1
skate
Member
 
Registered: Aug 2003
Location: Bulgaria
Distribution: OpenSuse 10.3, Debian 4.0r3 "Etch", FreeBSD 7.1, Ubuntu
Posts: 210

Rep: Reputation: 30
Question iptables allow / deny ??!!??


Hey all..

I have a simple quest.

How can I deny the access via ssh to everybody except me...

I mean nobody else will be able to connect via ssh except ip: xx.xx.xx.xx and/or xx.xx.xx.xx

 
Old 03-09-2007, 04:39 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
It would be a good idea if you did some general review of how iptables/netfilter work (with HOWTOs or something) to get a general feel for this and to make sure you have tailored things to your needs, but to block all but one IP address (assuming ssh is listening on port 22), you can

iptables -A INPUT -s ! xx.xx.xx.xx -p tcp --dport 22 -j DROP

or to allow multiple addresses:


iptables -A INPUT -s xx.xx.xx.xx -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s yy.yy.yy.yy -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s zz.zz.zz.zz -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP


If you have other firewall rules to merge with, or if you want to do state tracking and/or logging you might want to do something slightly different.
 
Old 03-09-2007, 04:57 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
use /etc/hosts.allow and hosts.deny to specify this at aplication level, or just use a firewall to block those ports before it gets anywhere near ssh. you've given a slightly confusing explanation there though, as "me" and "nobody" imply a user name, but an ip is obviosuly unrelated to a username
 
Old 03-09-2007, 04:59 AM   #4
timdsmith
Member
 
Registered: Nov 2003
Location: The Colony, TX
Distribution: Slackware, Debian Etch, FreeBSD, MicroSh*t free.
Posts: 209

Rep: Reputation: 30
OR....
You could put this in /etc/hosts.deny
Code:
#
# /etc/hosts.deny
#

ALL: ALL: DENY

# End of file
Then add something like this to /etc/hosts.allow
Code:
#
# /etc/hosts.allow
#
sshd:xxx.xxx.xxx.xxx

# End of file
Where xxx.xxx.xxx.xxx is the ip address of the computer you want allowed in.
 
Old 03-21-2007, 02:36 AM   #5
skate
Member
 
Registered: Aug 2003
Location: Bulgaria
Distribution: OpenSuse 10.3, Debian 4.0r3 "Etch", FreeBSD 7.1, Ubuntu
Posts: 210

Original Poster
Rep: Reputation: 30
Thank you ALL it worked perfectly

God Bless You
 
Old 03-21-2007, 03:25 AM   #6
digen
Member
 
Registered: Dec 2005
Location: India
Distribution: Ubuntu Feisty Fawn
Posts: 107

Rep: Reputation: 15
Glad it's working for you. Just FYI, for making use of Tcp wrappers for any daemon, the daemon needs to be compiled with the library libwrap.so if not already. Or else /etc/hosts.allow and /etc/hosts.deny won't work. You may check whether the daemon is compiled with libwrap.so.0 using the command ldd.

Quote:
root@southcarolina [~]# ldd /usr/sbin/sshd
libwrap.so.0 => /usr/lib/libwrap.so.0 (0x00468000)
libpam.so.0 => /lib/libpam.so.0 (0x004b1000)
libdl.so.2 => /lib/libdl.so.2 (0x0038d000)
libaudit.so.0 => /lib/libaudit.so.0 (0x006f9000)
libcrypto.so.4 => /lib/libcrypto.so.4 (0x00cc2000)
libutil.so.1 => /lib/libutil.so.1 (0x00111000)
libz.so.1 => /usr/lib/libz.so.1 (0x00115000)
libnsl.so.1 => /lib/libnsl.so.1 (0x008af000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x00f87000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00667000)
libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x0081d000)
libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x00222000)
libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x00bd2000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0x00344000)
libresolv.so.2 => /lib/libresolv.so.2 (0x007d4000)
libc.so.6 => /lib/tls/libc.so.6 (0x00514000)
/lib/ld-linux.so.2 (0x004f2000)
Do correct me if I'm wrong. Thanks.
 
Old 03-21-2007, 03:42 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you are the only user allowed to log into ssh, another layer of security is to use the "AllowUsers" entry in /etc/ssh/sshd_config. Also disable root logins.
 
  


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
how to deny nfs with iptables=? eder_michael11 Linux - General 1 04-19-2006 07:11 AM
iptables v. hosts.deny/allow vswr31 Linux - Security 3 04-22-2005 04:16 PM
iptables vs hosts.deny ryedunn Linux - Security 2 01-11-2005 06:56 PM
implicit deny in iptables tarheel92x Linux - Networking 2 11-13-2003 09:02 PM
Using iptables and hosts.deny? Poetics Linux - Security 8 07-19-2003 02:31 PM

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

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