# snmpwalk -v3 -u siemens -l authNoPriv -a MD5 -x DES -A '<user>' -X '<password>' localhost
[命令] Linux 命令 tcpdump (网络抓包)
内容一:tcpdump 命令格式
# tcpdump <option> <proto> <dir> <type>
内容二:tcpdump 命令选项 (option)
1) -A use ASCII print all data, it is convenient for read website date.
2) -c <number>, number of packet captures
3) -C <file size>,size of file
4) -e, display data link layer
5) -G <second>, create a new file after these seconds
6) -l, send the output to next command, example: tcpdump -i eth0 -s0 | grep 'Server:'
7) -n, do not resolve domain only display IP address
8) -nn, do not resolve domain and port only display IP address
9) -i <interface>, such as internet card and can use: -i any
10) -p, only display the data which point it self
11) -r <file>, read data from file
12) -s <snaplen>, size of length of the network package and can use: -s 0 to ulimite the length, the default value is 96B
13) -v , display detail
14) -vv, display detail more than -v
15) -vvv, display detail more than -vv
16) -w <file>, write the output result into a file
17) -W <number>, how many files will output result into
内容三:tcpdump 命令协议 (proto)
1) tcp or proto 6
2) udp or proto 17
3) icmp, example: proto \\icmp is icmp
4) ip
5) ip6
6) arp
7) rarp
8) ether
9) wlan
内容四:tcpdump 命令方向 (dir)
1) src
2) dst
内容五:tcpdump 命令种类 (type)
1) host <IP address>
2) net <network segment>, example: 10 is 10.x.x.x/8 , 192.168.0 is 192.168.0.0/24
3) port <port>
4) portrange <port range>
内容六:tcpdump 命令逻辑
1) and or &&
2) or or ||
3) not or !
内容七:tcpdump 命令的使用案例
7.1 显示发送到某个 IP 地址的某个端口的网络数据包
# tcpdump -i any dst 192.168.0.1 and udp port 514
(补充:这里以显示发送到 IP 地址 192.168.0.1 的 UDP 514 端口的数据包为例,如果有这类网络数据包的话则详细信息会在命令输出后显示出来)
7.2 显示从某个 IP 地址发送来的网络数据包
# tcpdump -vv src host 192.168.0.1
(补充:这里以显示从 IP 地址 192.168.0.1 发送来的网络数据包为例,如果有这类网络数据包的话则详细信息会在命令输出后显示出来)
7.3 显示从某个 IP 地址发送来,发送到某个 IP 地址的某个端口的网络数据包
# tcpdump -i any src 192.168.0.1 and dst 192.168.0.2 and udp port 22
(补充:这里以显示从 IP 地址 192.168.0.1 发送来,发送到 IP 地址 192.168.0.2 的 UDP 22 端口的数据包为例,如果有这类网络数据包的话则详细信息会在命令输出后显示出来)
7.4 将所有抓到的网络数据包导入到某个文件里
# tcpdump -i any -w /tmp/telnet.cap
(补充:这里以将所有抓到的数据包导出到文件 /tmp/telnet.cap 为例)
7.5 将某个网卡抓到的网络数据包导入到某个文件里
# tcpdump -i eth0 -s 0 -w /tmp/$(hostname)-$(date +"%Y-%m-%d-%H-%M-%S").pcap host 192.168.1.1 or host 192.168.1.2
(补充:这里以将网卡 eth0 网卡上抓到的来源或目的是 192.168.1.1 或 192.168.1.2 的数据包导出到文件 /tmp/$(hostname)-$(date +”%Y-%m-%d-%H-%M-%S”).pcap 为例)
[内容] 全球公共免费 DNS
AdGuard
94.140.14.14
94.140.14.15
94.140.15.15
94.140.15.16
Cloudflare
1.0.0.1
1.0.0.2
1.0.0.3
1.1.1.1
1.1.1.2
1.1.1.3
COMODO
8.20.247.20
8.26.56.26
DNS Watch
84.200.69.80
84.200.70.40
Dyn
216.146.35.35
216.146.36.36
Level 3
209.244.0.3
209.244.0.4
Neustar
156.154.70.1
156.154.71.1
FreeDNS
37.235.1.174
37.235.1.177
8.8.4.4
8.8.8.8
OpenDNS
208.67.220.220
208.67.222.222
SAFEDNS
195.46.39.39
195.46.39.40
Symantec
199.85.126.10
199.85.137.10
[排错] 解决 SSH 远程登录时很慢但 ping 时延迟很低
报错命令
# ssh ......
报错代码
登录时很慢
分析
ssh 远程某台服务器时很慢,但是 ping 时延迟却很低。这可能是 DNS 解析出现问题造成的,禁用服务器上 sshd 的 GSSAPIAuthentication 参数和 UseDNS 参数可以解决,这两个参数的作用是:
1) GSSAPIAuthentication,当服务器的 sshd 服务此参数处于开启状态时,客户端 SSH 登录此服务器时,客户端会对服务器的 IP 地址进行 PTR 反解析,获得服务器的域名,再通过服务器的域名对服务器进行 DNS A 正向 IP 地址解析,通过此方法来防止欺骗。
2) UseDNS,当服务器的 sshd 服务此参数处于开启状态时,客户端 SSH 登录此服务器时,服务器会对客户端的 IP 地址进行反解析,获得客户端的域名,再通过客户端的域名对客户端进行 DNS A 正向 IP 地址解析,通过此方法来防止欺骗。
解决方法
方法一:忽略 DNS
1.1 修改 SSH 的配置文件
# vim /etc/ssh/sshd_conf
将以下内容:
......
UseDNS yes
......
GSSAPIAuthentication yes
......
修改为:
......
UseDNS no
......
GSSAPIAuthentication no
......
1.2 让修改的 SSH 配置文件生效
# systemctl restart sshd
方法二:重启 systemd-logind
2.1 重启 dbus
# systemctl restart dbus
2.2 重启 systemd-logind
# systemctl restart systemd-logind
(注意:如果不重启 dbus 直接重启 systemd-logind 则可能会报错)
[排错] 解决 Linux 运行 authselect apply-changes 命令时报错 “[error] [/etc/authselect/system-auth] has unexpected content!” 或者 “[error] [/etc/authselect/password-auth] has unexpected content!”
报错命令
# authselect apply-changes
报错代码
[error] [/etc/authselect/system-auth] has unexpected content!
[error] [/etc/authselect/password-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.
或者:
[error] [/etc/authselect/system-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.
或者:
[error] [/etc/authselect/password-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.
分析
/etc/authselect/system-auth 文件或 /etc/authselect/password-auth 文件是不应该被手动修改的,如果被手动修改了,再使用 authselect select sssd 命令或者 authselect apply-changes 命令时则会有此类报错
解决方法
# authselect apply-changes
(注意:此方法会刷新 /etc/authselect/system-auth 文件和 /etc/authselect/password-auth 文件里的所有内容)
