
我是 Ubuntu 新手,連接埠 6703 有問題
我執行了這個命令
ps -ef | grep 6703
並得到這個結果
user 4378 4308 0 09:40 pts/2 00:00:00 grep --color=auto 6703
但不明白那是什麼意思?
答案1
ps
不顯示網絡端口,至少據我所知。更合適的命令是netstat
or lsof
。
例如,如果我想查看我的伺服器是否ssh
正在偵聽連接埠 22,我可以這樣做:
xieerqi@eagle:~$ sudo netstat -tulpan | grep ":22"
[sudo] password for xieerqi:
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1012/sshd
tcp6 0 0 :::22 :::* LISTEN 1012/sshd
與 lsof 相同,如果我想檢查特定端口,例如 58732
xieerqi@eagle:~$ sudo lsof | grep ":58732"
[sudo] password for xieerqi:
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
firefox 2491 xieerqi 65u IPv4 1948841 0t0 TCP eagle:58732->104.16.113.188:http (ESTABLISHED)
至於為什麼你的命令會返回
user 4378 4308 0 09:40 pts/2 00:00:00 grep --color=auto 6703
這是 的輸出中唯一匹配的字串ps
,換句話說,grep 命令本身是該列表中唯一的字串。再說一遍,不會有任何其他內容,因為您正在尋找端口,並且ps
不顯示端口