LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2004, 12:09 AM   #1
jamiguel77
LQ Newbie
 
Registered: May 2004
Distribution: red hat
Posts: 24

Rep: Reputation: 15
block putty.exe(ssh) with iptables


hi all i want block all ip's that try connect via putty.exe ssh from windows to my server, only need gave permission to ip: 192.168.0.88 to can connect to my server.


NOTE: i need user iptables because i offer internet to all pc's in my lan.

thanks
 
Old 09-13-2004, 12:33 AM   #2
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
you can put a rule in /etc/hosts.allow as

sshd: 127. 192.168.0.88

You need 127. in case you want to tryout ssh from the linux machine itself
 
Old 09-13-2004, 09:38 AM   #3
jamiguel77
LQ Newbie
 
Registered: May 2004
Distribution: red hat
Posts: 24

Original Poster
Rep: Reputation: 15
i follow your advice.

i followed:

you can put a rule in /etc/hosts.allow as

sshd: 127. 192.168.0.88


i try from 192.168.0.88 and can enter but to try from 192.168.0.49 and too can enter, why?

thanks
 
Old 09-13-2004, 10:39 AM   #4
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
That would only work if sshd was run from inetd/xinetd..

If sshd is a standalone daemon, do ps ax | grep sshd to find it's running PID, you will need to make an iptables rule or place a restriction in /etc/ssh/sshd.conf, eg

iptables - I INPUT -i ethx -p tcp --dport 22 -s ! 192.168.0.88 -j REJECT

or in sshd.config..
AllowUsers user1 user2 user3
and make a user just for ssh, eg mgwkptt4@g and use authorized keys
This will allow you to login from anywhere and su to root user..
See man man ssh for details..
 
Old 09-13-2004, 10:45 AM   #5
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
shouldn't work that way ....

adding 127. and 192.168.0.88 should allow access to sshd only from these two IPs...

do you have any other entry in your hosts.allow? Something like a

ALL:ALL

You cantry this ... although hosts.allow should work all by itself ...

edit hosts.deny and add

ALL:ALL

This will deny access to all services that are running ... except the ones you have allowed in hosts.allow.
 
Old 09-13-2004, 10:57 AM   #6
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
Quote:
That would only work if sshd was run from inetd/xinetd..
I have sshd running as a standalone daemon and adhereing to hosts.allow.
 
Old 09-13-2004, 11:14 AM   #7
jamiguel77
LQ Newbie
 
Registered: May 2004
Distribution: red hat
Posts: 24

Original Poster
Rep: Reputation: 15
worked with hosts.allow and hosts.deny

worked with hosts.allow and hosts.deny

i add these entry for hosts.deny

ALL:ALL

and tested from .99 and i can enter, and try tested form .49 and i cant

worked, but i have fear not know if is the good way because:
i am chatting to in mirc in Undernet redhat channel.

<jak2000> Fiver: see again please: http://www.linuxquestions.org/questi...76#post1172576
<jak2000> Fiver, now worked....
* DrAgOn0FF has quit IRC (Signed off)
<jak2000> with access.deny
<jak2000> is good way? in hosts.access and hosts.deny ?
<Fiver> no
<Fiver> they will not work for you
<jak2000> Fiver, worked, why not is a good WAY for me?
<Fiver> what version of redhat are you running?
<Fiver> recent versions, including fedora, do not run sshd from xinetd, so hosts.allow and hosts.deny are ignored for that service
* drkhero has quit IRC (Ping timeout)
<jak2000> rh 9
<Fiver> well, if it's working the way you want, that's fine, but hosts.allow and hosts.deny won't affect it
<Fiver> unless you've changed how sshd is run


peter_robb:

i typed:

ps ax | grep sshd

[root@ServerGLN root]# ps ax | grep sshd
1034 ? S 0:00 /usr/sbin/sshd
10743 ? R 0:00 /usr/sbin/sshd
10811 pts/1 S 0:00 grep sshd
[root@ServerGLN root]#



any coments?
 
Old 09-13-2004, 11:22 AM   #8
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
I must admit I havn't seen a fedora script ever, so I'd like to know how hosts.allow & .deny get to be involved..

Can then add that to the wiki instructions, (and stop me giving bad advice)
 
Old 09-13-2004, 12:49 PM   #9
jamiguel77
LQ Newbie
 
Registered: May 2004
Distribution: red hat
Posts: 24

Original Poster
Rep: Reputation: 15
arghhhh hosts.deny

my server of email not work because in hosts.deny i have:

ALL:ALL

if i remove these line my email server work, any advice?

of course putty can enter.... from any pc.


thanks
 
Old 09-13-2004, 03:18 PM   #10
scowles
Member
 
Registered: Sep 2004
Location: Texas, USA
Distribution: Fedora
Posts: 620

Rep: Reputation: 31
Re: arghhhh hosts.deny

Quote:
Originally posted by jamiguel77
my server of email not work because in hosts.deny i have:

ALL:ALL

if i remove these line my email server work, any advice?

of course putty can enter.... from any pc.


thanks
First, IMO, the best way to implement your question is through iptable rules. Let the script kiddies of the world attack layer 3 of your firewall (iptables), not layer 7 user applications running behind it. Unless of course, you have no choice (like an e-mail MTA).

With the above in mind... If an application is compiled with tcpwrapper support (like sendmail), then that application will check the hosts.allow/deny files to determine access rules.

With regards to the quoted text above... you added ALL:ALL to hosts.deny. Because of this, you would then need to add each service that you want to grant access to in hosts.allow. Something like:

sendmail: ALL
sshd: 192.168.9.10

Further reading should include: man hosts.allow

There are a couple of examples (mostly closed/mostly open) in this particular man page that should help you meet the goals of your post.
 
Old 09-13-2004, 04:21 PM   #11
jamiguel77
LQ Newbie
 
Registered: May 2004
Distribution: red hat
Posts: 24

Original Poster
Rep: Reputation: 15
not work....

/etc/hosts.deny


#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
ALL:ALL
~

/etc/hosts.allow

#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
sshd: 127. 192.168.0.88
smtp: ALL
pop3: ALL
sendmail: ALL
~


i try check mi email via outlookexpress and say me errors, i put an # in /etc/hosts.deny in the line ALL:ALL and try again check the email and work.....


any advice?

thanks for your time
 
Old 09-13-2004, 08:59 PM   #12
netopia
LQ Newbie
 
Registered: Sep 2004
Location: Boston, MA
Distribution: fedora core 2
Posts: 28

Rep: Reputation: 15
Everyone please note what the hosts.allow file says - I don't think it's true that /etc/hosts.allow and hosts.deny only affect xinetd under any circumstances. The man page for tcpd says it monitors any services that have a one-to-one mapping onto executable files. Pop3 is likely not the name of the executable file that runs your email server - it is probably pop3d or any number of other things depending on which email server you are running...
 
Old 09-14-2004, 03:52 AM   #13
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
jamiguel

can you netstat -lap - to get a list of service that are listening. You will have to give the exact daemonname.

 
Old 09-14-2004, 10:13 AM   #14
jamiguel77
LQ Newbie
 
Registered: May 2004
Distribution: red hat
Posts: 24

Original Poster
Rep: Reputation: 15
finally i apply these iptable rules

iptables -A INPUT -i eth0 -p tcp --dport 22 -s 192.168.0.88 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 22 -s 0/0 -j REJECT


and then: service iptables save


and work good good


Much Thanks
 
  


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
Accessing pc with putty (ssh) Wozl Linux - Networking 1 10-10-2005 03:44 PM
IPTables and PPTPD :S (to block or not to block) thewonka Linux - Networking 0 03-24-2005 06:58 PM
Bypassing College EXE Block Boffy General 6 11-25-2004 03:04 PM
putty SSH connection deWin Linux - Newbie 3 03-26-2004 09:47 AM
SSH using putty rkemp Linux - Networking 3 03-06-2004 05:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

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