分类 Linux 相关 下的文章

tcpdump

tcpdump - dump traffic on a network

tcpdump [ -AbdDefhHIJKlLnNOpqStuUvxX# ] [ -B buffer_size ]

  • -w 写入文件
  • -r 从文件读入 -F 读入的文件
  • -V 从一批文件读入
  • -c 处理多少 package
  • -D or --list-interfaces 列出接口列表
  • -i --interface= 制定接口
  • -K --dont-verify-checksums 不验证 checksum 加快速度
  • -n 不转换数字为地址
  • -Q --direction=in|out|inout

samples here
sudo tcpdump host 10.102.196.239 -w /tmp/tcpdump.log.cap
sudo tcpdump -C 50 -W 10 -w /tmp/tcp.cap ##循环写 10个文件, 每个 50M
sudo tcpdump'(host 10.135.250.186 or host 10.189.248.238 or host 10.20.170.138 or host 10.21.233.128 or port 53)' -w /tmp/tcp.cap # 多个 IP 或者 DNS 查询

ping:
sudo tcpdump -e icmp[icmptype] == 8 //ping echo request
sudo tcpdump -e icmp[icmptype] == 0 //ping echo reply

network diagnosis commands 网络诊断命令

  1. wget
    -- wget -S --spider -T 1 -t 2 sellerprof.vip
    -- wget -S --spider -T 1 -t 2  --no-check-certificate https://esams.vip
  2. curl
    -- curl -I --retry 2 --connect-timeout 1 sellerprof.vip
    -- curl -I --retry 2 --connect-timeout 1 -k https://esams.vip
  3. telnet
  4. nslookup
    -- nslookup -query=hinfo  -timeout=1 -retry=1 esams.vip
  5. ping
    -- ping -c 10 -W 1 sellerprof.vip
  6. traceroute/tracert
    -- traceroute esams.vip
  7. mtr
    -- mtr -w --timeout=1 esams.vip
  8. dig 由 BIND(互联网上最广泛使用的 DNS 软件) 提供的查询 DNS 的辅助工具,替换原来老的 nslookup 和 host

    dig //不带任何参数查询root dns .
    dig -h //help
    dig +short www.tianxiaohui.com // 简化输出
    dig +trace www.tianxiaohui.com //输出迭代式所有来回
    dig @8.8.8.8 tianxiaohui.com
    dig -x 54.222.60.252 //反向查询
    dig -f query.txt +short //从文件读
    dig google.com ANY //查询所有记录

  9. netstat
    来自于 net-tools 软件包. 已不推荐使用, 由 ss 命令来替换此命令.
    -- netstat -t --wide
    -- netstat -t -l
    -- netstat -s
  10. nstat
    来自于 iproute2 软件包
    -- nstat -a
    -- nstat #可以提供2 次使用间的 delta
    -- nstat --json #以 json 格式输出
  11. ss
    来自 iproute2 软件包, 用以替换 netstat. 更偏重于 socket 连接, 数据来自 /proc/net/tcp.
    -- ss -t -l
    -- ss --info
    -- ss -it state syn-sent #根据状态查
    -- ss -it dst abc.tianxiaohui.com #根据地址过滤
    -- ss -it '( dport = :443 )' #根据目标端口查, 一定要注意这里面的空格, 括号里的空格每处都需要
    -- ss -it '( dport = :443 or dport = :80 )' #或者
    -- ss -it '( sport = :45321 )' #根据源端口查,
  12. routetable
    -- netstat -r
  13. ifconfig/ipconfig

ss linux command

ss 是比 netstat 更强大的后续版本.
The ss command is capable of showing more information than the netstat and is faster. The netstat command reads various /proc files to gather information. However this approach falls weak when there are lots of connections to display. This makes it slower. The ss command gets its information directly from kernel space.

ss -l
ss -t
ss -u
ss -nt
ss -ltp
ss -nt '( dst :443 or dst :80 )'

ss -r -t | grep 11210 | awk '{print $5}'
ss -r -t | grep 11210 | awk '{print $5}' | sort | uniq -c
ss -r -t | grep 11210 | awk '{print $5}' | sort | uniq -c | wc -l

使用 -i 参数能显示更多关于每个 socket 的信息,比如接受/发送多少字节, 最后发送/接收/ack 了多久了, 采用了什么算法.
-p 显示进程信息, -e 显示用户信息. -m 显示内存信息.

http://man7.org/linux/man-pages/man8/ss.8.html

about DNS cache

如何查看系统 DNScache 的 TTL (time to live). 如下,dig 命令的 hostname 之后就是 DNS server 返回的 TTL

 eric$ dig tianxiaohui.com

;; ANSWER SECTION:
tianxiaohui.com.    10    IN    A    118.184.11.30

如何查看浏览器 DNS TTL 时间:
chrome : chrome://net-internals/#dns
https://stackoverflow.com/questions/36917513/how-long-google-chrome-and-firefox-cache-dns-records

java 里面如何设置 DNS TTL:
https://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-jvm-ttl.html

参考:

https://apple.stackexchange.com/questions/93949/how-long-does-the-dns-cache-last-in-mac-os-x

http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-jvm-ttl.html

iostat, vmstat, prstat, mpstat, nicstat, netstat

iostat reports CPU, disk I/O, and NFS statistics.
vmstat reports virtual memory statistics.
mpstat reports processors statictics.

vmstat: Virtual Memory statistic. 实时收集并报告主内存,交换分区(SWAP)以及 CPU 的使用情况. 用来查找和定位内存的性能问题.

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0  90175    239   1434    0    0     0     1    3    2  0  0 100  0  0
 0  0      0  90175    239   1434    0    0     0     0  153  176  0  0 100  0  0
 1  0      0  90151    239   1434    0    0     0     4 3068 1961  1  2 97  0  0

r: process running
b: process blocked
swpd: swapped to swap
free: memory free
buff: memory committed
cache: declared or can be swapped to swap
si: swap in
so: swap out
bi: block in (read disk unit is block, memory unit is page)
bo: block out
in: interrupt
cs: context switch
us: user, sd: system/kernel, id: idle, ws: waste

https://www.linode.com/docs/uptime/monitoring/use-vmstat-to-monitor-system-performance

占位
http://www.thegeekstuff.com/2011/07/iostat-vmstat-mpstat-examples/