I'm trying to determine which ports are in use with my machine. I found, online an article that listed one method as follows:
$ sudo nmap -sT -O localhost
I believedthis would give me a list of all ports listening for TCP packets. However, when I enter this command, I get the following result:
Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-02 21:07 EDT
socket troubles in HostOsScan: Permission denied (13)
If I'm running as sudo, how can I lack permission to run something on my machine??
I tried running just:
$ sudo nmap -sT localhost
and got:
Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-02 21:28 EDT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000094s latency).
Not shown: 999 closed ports
PORT STATE SERVICE
631/tcp open ipp
Just tried nmap
without arguments and again was denied permission !?
$ sudo nmap localhost
Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-03 11:05 EDT
Couldn't open a raw socket. Error: Permission denied (13)
Looking at nmap's
--help
option, I see that -O
enables OS detection. Why should I not have permission to use this option - especially with sudo
? (Note: I'm currently running Ubuntu 18.04 & 20.04)
(Note: Accepted answer solves my root problem - looking at ports, but answer in comments section explains why I was having trouble with nmap
. Apparently, because I installed with snap
, I needed to also execute:
$ sudo snap connect nmap:network-control
before nmap
would work correctly
dpkg -S /usr/bin/nmap
returns a line starting with nmap: then it's not through snap.