Sample Header Ad - 728x90

Why using grep for some netstat commands require sudo priv?

0 votes
2 answers
277 views
System: - Ubuntu 20.04.06 - net-tools 2.10-alpha - grep (GNU grep) 3.4 If I run netstat without sudo I see port information and no process information. This is expected as process information requires elevated privileges.
$ netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:43445         0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:41933         0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:42649         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:46059         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:45983         0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:5001            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:5433            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:34903         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:37257         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:37081         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:38445         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:38335         0.0.0.0:*               LISTEN      -
tcp6       0      0 ::1:3350                :::*                    LISTEN      -
tcp6       0      0 ::1:631                 :::*                    LISTEN      -
tcp6       0      0 :::2377                 :::*                    LISTEN      -
tcp6       0      0 :::3389                 :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 :::25                   :::*                    LISTEN      -
tcp6       0      0 :::111                  :::*                    LISTEN      -
tcp6       0      0 :::443                  :::*                    LISTEN      -
tcp6       0      0 :::7946                 :::*                    LISTEN      -
tcp6       0      0 :::5001                 :::*                    LISTEN      -
tcp6       0      0 :::5433                 :::*                    LISTEN      -
tcp6       0      0 :::5432                 :::*                    LISTEN      -
udp        0      0 127.0.0.53:53           0.0.0.0:*                           -
udp        0      0 0.0.0.0:111             0.0.0.0:*                           -
udp        0      0 0.0.0.0:631             0.0.0.0:*                           -
udp        0      0 0.0.0.0:4789            0.0.0.0:*                           -
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -
udp        0      0 0.0.0.0:43294           0.0.0.0:*                           -
udp6       0      0 :::52206                :::*                                -
udp6       0      0 :::111                  :::*                                -
udp6       0      0 :::5353                 :::*                                -
udp6       0      0 :::7946                 :::*                                -
But if I try to send that output to grep I get an error that I need sudo priv. Why? None of the process information was shown on stdout, why would grep change that?
$ netstat -tulpn | grep 8080
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
**TROUBLESHOOTING:** - This does not happen if I dont include -p (i.e. netstat -tuln | grep 8080) - This does not happen if I use smaller grep string (i.e. netstat -tulpn | grep 8) - Using ss does not show the same problem (i.e. ss -tulpn | grep 8080) What is going on here? Note: Yes I know netstat is deprecated and I should use ss instead, I am just curious why this behavior is happening.
Asked by Dave (700 rep)
Feb 4, 2024, 03:12 PM
Last activity: Feb 4, 2024, 10:00 PM