.github
.husky
assets
docs
Neo4j.md
adb.md
adobe-lightroom.md
adobe-photoshop.md
adobe-xd.md
android-studio.md
ansible.md
apt.md
ascii-code.md
aspect-ratio.md
awk.md
bash.md
blender.md
c.md
cargo.md
chmod.md
chown.md
cmake.md
cmd.md
cocoapods.md
colors-named.md
conan.md
conda.md
cpp.md
cron.md
cs.md
css.md
curl.md
dart.md
django.md
docker.md
dockerfile.md
ejs.md
elasticsearch.md
electron.md
elixir.md
emacs.md
emmet.md
emoji.md
es6.md
expressjs.md
fastapi.md
feds.md
ffmpeg.md
figma.md
find.md
finder.md
firefox.md
flask.md
flutter.md
ftp.md
gdb.md
git.md
github-actions.md
github-copilot.md
github.md
gitlab-ci.md
gitlab.md
gmail.md
golang.md
google-chrome.md
graphql.md
grep.md
homebrew.md
html-char.md
html.md
htmx.md
htop.md
http-status-code.md
ini.md
intelli-j-idea.md
iptables.md
iso-3166-1.md
iso-639-1.md
java.md
javascript.md
jest.md
jq.md
jquery.md
json.md
julia.md
justfile.md
koajs.md
kotlin.md
kubernetes.md
laravel.md
latex.md
lerna.md
lessjs.md
linux-command.md
lsof.md
lua.md
make.md
markdown.md
matlab.md
mime.md
mitmproxy.md
mongodb.md
mysql.md
neo4j.md
nestjs.md
netcat.md
netstat.md
nextjs.md
nginx.md
npm.md
nvm.md
openssl.md
oracle.md
package.json.md
pacman.md
pandoc.md
php.md
phpstorm.md
pm2.md
postgres.md
ps.md
pycharm.md
python.md
pytorch.md
quickreference.md
r.md
react-native.md
react.md
reactrouter.md
redis.md
regex.md
resolutions.md
ruby.md
rust.md
sass.md
scala.md
screen.md
sdkman.md
sed.md
semver.md
sketch.md
ssh.md
styled-components.md
stylus.md
sublime-text.md
subversion.md
swift.md
swiftui.md
symbol-code.md
sysdig.md
systemd.md
tailwindcss.md
tar.md
taskset.md
tauri.md
tmux.md
toml.md
twitter.md
typescript.md
vim.md
vscode.md
vue.md
vue2.md
webstorm.md
xcode.md
xpath.md
yaml.md
yarn.md
yum.md
zip.md
.dockerignore
.editorconfig
.gitattributes
.gitignore
.lintstagedrc
.markdownlint.json
.npmrc
.prettierignore
.prettierrc
.refsrc.json
CONTRIBUTING.md
Dockerfile
LICENSE
README.md
package.json
renovate.json

* format: fix markdown * update: fix markdown * update: fix cron problems * update: delete .markdownlintignore * update * chore: add tab -> 4 space * chore: fix tab -> 2 in the .editorconfig
4.3 KiB
4.3 KiB
Netstat 备忘清单
此快速参考备忘单提供了各种使用 netstat 命令的方法
入门
入门实例
端口 80 上的所有连接
$ netstat -anp | grep :80
网络统计帮助
$ netstat -h
监听
选项 | 说明 |
---|---|
netstat -ltunp |
所有监听端口 |
netstat -ltn |
监听 TCP 端口 |
netstat -lun |
监听 UDP 端口 |
netstat -lx |
监听 Unix 端口 |
netstat -lt |
仅列出侦听 TCP 端口 |
netstat -lu |
仅列出侦听 UDP 端口 |
netstat -l |
列出所有监听条件 |
连接
选项 | 说明 |
---|---|
netstat -a |
所有连接 |
netstat -at |
所有 TCP 连接 |
netstat -au |
所有 UDP 连接 |
netstat -ant |
显示没有反向 DNS 查找的 IP 地址 |
选项 | 说明 |
---|---|
netstat |
活动连接 |
netstat -a |
所有连接 |
netstat -at |
所有 TCP 连接 |
netstat -au |
所有 UDP 连接 |
netstat -ant |
显示没有反向 DNS 查找的 IP 地址 |
netstat -tnl |
监听 TCP 端口 |
netstat -unl |
监听 UDP 端口 |
网络
选项 | 说明 |
---|---|
netstat -i |
显示网络接口 |
netstat -ie |
显示网络接口扩展信息 |
netstat -n |
仅显示 IP 地址 |
netstat -F |
尽可能显示 IP 地址的域名 |
路由
选项 | 说明 |
---|---|
netstat -r |
显示路由表 |
netstat -rn |
显示路由表,不解析主机 |
统计数据
选项 | 说明 |
---|---|
netstat -s |
显示统计信息 |
netstat -st |
显示 TCP 统计信息 |
netstat -su |
显示 UDP 统计信息 |
netstat -ltpe |
使用进程信息和扩展信息显示 TCP 的侦听连接 |
netstat -tp |
显示带有 PID 编号的服务名称 |
sudo netstat -nlpt |
列出进程名称/PID 和用户 ID |
netstat -nlptue |
所有带有 PID 和扩展信息的侦听端口 |
netstat -M |
显示伪装的连接 |
显示没有域名的 TCP 连接
$ netstat --tcp --numeric
显示活动/已建立的连接
$ netstat -atnp | grep ESTA
获取活动连接的连续列表
$ watch -d -n0 "netstat -atnp | grep ESTA"
显示到特定端口的所有打开连接
$ netstat -anp | grep":"
插入端口
号(上图)代替冒号 :
检查服务是否正在运行
$ sudo netstat -aple | grep ntp
你可以用http
、smtp
代替ntp
Netstat – 安全命令
显示具有大量连接的 IP
$ netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
连接到端口 80 的 IP 地址
$ netstat -tn 2>/dev/null | grep ':80 ' | awk '{print $5}' |sed -e 's/::ffff://' | cut -f1 -d: | sort | uniq -c | sort -rn | head
显示端口 80 上的活动连接数
$ netstat -an |grep :80 |wc -l
仅显示外部 IP 地址
$ netstat -antu | grep :80 | grep -v LISTEN | awk '{print $5}'
显示活动 SYNC_REC
以下命令将输出服务器上正在发生和正在发生的活动 SYNC_REC
数量。数量应该很低(小于 5
)。如果该数字为两位数,则您可能正在遭受 DoS
攻击或被邮件轰炸。
$ netstat -n -p|grep SYN_REC | wc -l
列出发送 SYN_REC 连接的唯一 IP 地址
$ netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'
与上面的命令一样,该命令也列出了发送 SYN_REC
连接状态的节点的所有唯一 IP
地址
每个远程 IP 的连接数
$ netstat -antu | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
或者
$ netstat -antu | awk '$5 ~ /[0-9]:/{split($5, a, ":"); ips[a[1]]++} END {for (ip in ips) print ips[ip], ip | "sort -k1 -nr"}'
检查开放端口(ipv4 和 ipv6)
$ netstat -plntu
检查开放端口(ipv4 和 ipv6)
$ netstat -plnt
每个 IP 的打开连接数
$ netstat -an | grep 80 | wc -l
活跃的互联网连接
$ netstat -pnut -w | column -t -s $'\t'