Tuesday, March 31, 2009

Linux scan for open ports

A nice command to scan open ports for a host/ip is:

nmap -sS -O 127.0.0.1

You will get an answer like this:

PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
80/tcp open http
110/tcp open pop3
111/tcp open rpcbind
119/tcp open nntp
135/tcp filtered msrpc
137/tcp filtered netbios-ns
138/tcp filtered netbios-dgm
139/tcp filtered netbios-ssn
445/tcp filtered microsoft-ds
1720/tcp filtered H.323/Q.931
3306/tcp open mysql
8080/tcp open http-proxy
8081/tcp open blackice-icecap
8443/tcp open https-alt
Device type: general purpose


If you need to see the open ports from inside (your server) use netstat:

netstat -a

You will get something like:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:cvspserver *:* LISTEN
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:netbios-ssn *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:http-alt *:* LISTEN
tcp 0 0 *:microsoft-ds *:* LISTEN
tcp 0 0 *:www-http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 *:https *:* LISTEN
udp 0 0 *:netbios-ns *:*
udp 0 0 *:netbios-dgm *:*
udp 0 0 *:tftp *:*
.......

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 5170 @/tmp/hald-local/dbus-B cG6NtYfGm
unix 2 [ ACC ] STREAM LISTENING 7389 /var/lib/mysql/mysql.so ck
unix 2 [ ] DGRAM 8071089 /var/lib/dhcp/dev/log
unix 2 [ ] DGRAM 8071091 /var/lib/named/dev/log
unix 2 [ ] DGRAM 2177 @/org/kernel/udev/udevd
unix 2 [ ] DGRAM 5171 @/org/freedesktop/hal/u dev_event
............

No comments:

Post a Comment