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 09-27-2001, 08:07 AM   #1
adamrau
Member
 
Registered: Sep 2001
Posts: 42

Rep: Reputation: 15
How do i insure that all ports are closed except 80 and 22


Is there a way to make sure all ports are closed except certain ones.
Thanks in advance.
Adam
 
Old 09-28-2001, 09:32 AM   #2
raz
Member
 
Registered: Apr 2001
Location: London
Posts: 408

Rep: Reputation: 31
Yes.

First find out which ports are open.
as Root type:

netstat -natp

example output below shows only sshd running and open for all access 0.0.0.0.*
---------------
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 511/sshd2
---------------

then switch off all the ones you don't want by going into the following directory.

/etc/xinetd.d/

create a directory in here called old

/etc/xinetd.d/old

then move every service you don't want to this "old" directory.

mv wu-ftpd old
etc etc etc

then restart the inetd service.

/etc/rc.d/init.d/xinetd restart

then type netstat -natp again to see what's left.
Any service that you don't want, might be started in other places by rc.local or other run level file other then xinetd.conf

so for example you see that sshd is running on port 22 and hasn't stop, if you wanted to stop it and don't know the location of the file that started it type this:

"or the port number of the service your looking for, in this case I'm looking for port 22"
fuser -n tcp 22

"displays"
22/tcp: 511 13607

Now type the last number which is the pid number of the service.

ps -ef | grep 13607

"displays"
root 13607 511 0 11:11 ? 00:00:00 /usr/local/sbin/sshd2

now you know it's the sshd2 service running from /usr/local/sbin/sshd2

so type:
/usr/local/sbin/sshd2 stop

If this doesn't help stop the service required then it's run from run level 3 or started in the /etc/rc.d/rc.local file.
Type this to show you the services started from the different run levels.

chkconfig --list

find the name of the service that is running, from the corresponding port number listed in the netstat -natp output and type it's name in the following format:

The example below is to stop auth port 113 service.

chkconfig --level 23 identd off


It's that easy.

/Raz
 
  


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
Apache, closed ports Sapient Linux - Software 2 08-30-2005 06:38 AM
Closed Ports? ZingSter Linux - Software 1 01-21-2005 12:08 PM
Help getting my ports filtered/closed.... BmxFace Linux - Security 3 02-04-2004 11:07 AM
how can i open closed ports? doublefailure Linux - Networking 7 07-10-2002 12:38 AM
Closed ports? Greg21 Linux - Networking 4 01-14-2002 11:37 PM

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

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