网络管理
ifconfig
ifconfig 命令被用于配置和显示Linux内核中网络接口的网络参数。
add<地址>:设置网络设备IPv6的ip地址;
del<地址>:删除网络设备IPv6的IP地址;
down:关闭指定的网络设备;
<hw<网络设备类型><硬件地址>:设置网络设备的类型与硬件地址;
io_addr<I/O地址>:设置网络设备的I/O地址;
irq<IRQ地址>:设置网络设备的IRQ;
media<网络媒介类型>:设置网络设备的媒介类型;
mem_start<内存地址>:设置网络设备在主内存所占用的起始地址;
metric<数目>:指定在计算数据包的转送次数时,所要加上的数目;
mtu<字节>:设置网络设备的MTU;
netmask<子网掩码>:设置网络设备的子网掩码;
tunnel<地址>:建立IPv4与IPv6之间的隧道通信地址;
up:启动指定的网络设备;
-broadcast<地址>:将要送往指定地址的数据包当成广播数据包来处理;
-pointopoint<地址>:与指定地址的网络设备建立直接连线,此模式具有保密功能;
-promisc:关闭或启动指定网络设备的promiscuous模式;
IP地址:指定网络设备的IP地址;
网络设备:指定网络设备的名称。
[root@localhost hello]# ifconfig
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.101.66 netmask 255.255.255.0 broadcast 192.168.101.255
inet6 fe80::30f3:dfc2:af2d:658a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c3:a7:8e txqueuelen 1000 (Ethernet)
RX packets 109611 bytes 120604912 (115.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 84283 bytes 10780813 (10.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 202 bytes 17356 (16.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 202 bytes 17356 (16.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
只显示指定网卡
[root@localhost hello]# ifconfig ens192
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.101.66 netmask 255.255.255.0 broadcast 192.168.101.255
inet6 fe80::30f3:dfc2:af2d:658a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c3:a7:8e txqueuelen 1000 (Ethernet)
RX packets 109648 bytes 120607948 (115.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 84301 bytes 10784085 (10.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
启动关闭指定网卡
ifconfig ens192 up
ifconfig ens192 down
telnet
telnet 命令用于登录远程主机,对远程主机进行管理。telnet因为采用明文传送报文,安全性不好,很多Linux服务器都不开放telnet服务,而改用更安全的ssh方式了。但仍然有很多别的系统可能采用了telnet方式来提供远程登录,因此弄清楚telnet客户端的使用方式仍是很有必要的。
-8:允许使用8位字符资料,包括输入与输出;
-a:尝试自动登入远端系统;
-b<主机别名>:使用别名指定远端主机名称;
-c:不读取用户专属目录里的.telnetrc文件;
-d:启动排错模式;
-e<脱离字符>:设置脱离字符;
-E:滤除脱离字符;
-f:此参数的效果和指定"-F"参数相同;
-F:使用Kerberos V5认证时,加上此参数可把本地主机的认证数据上传到远端主机;
-k<域名>:使用Kerberos认证时,加上此参数让远端主机采用指定的领域名,而非该主机的域名;
-K:不自动登入远端主机;
-l<用户名称>:指定要登入远端主机的用户名称;
-L:允许输出8位字符资料;
-n<记录文件>:指定文件记录相关信息;
-r:使用类似rlogin指令的用户界面;
-S<服务类型>:设置telnet连线所需的ip TOS信息;
-x:假设主机有支持数据加密的功能,就使用它;
-X<认证形态>:关闭指定的认证形态。
也可以用于测试端口是否可以连通
通
[root@localhost hello]# telnet 192.168.101.66 22
Trying 192.168.101.66...
Connected to 192.168.101.66.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
不通
[root@localhost hello]# telnet 192.168.101.66 8888
Trying 192.168.101.66...
telnet: connect to address 192.168.101.66: Connection refused
ifup
ifup命令用于激活指定的网络接口。
ifup ens192
ifdown
ifdown 命令用于禁用指定的网络接口。
ifdown ens192
dhclient
dhclient命令使用动态主机配置协议动态的配置网络接口的网络参数。
0:指定dhcp客户端监听的端口号;
-d:总是以前台方式运行程序;
-q:安静模式,不打印任何错误的提示信息;
-r:释放ip地址。
dhclient -r #释放IP
dhclient #获取IP
ip
ip 命令用来显示或操纵Linux主机的路由、网络设备、策略路由和隧道,是Linux下较新的功能强大的网络配置工具。
-V:显示指令版本信息;
-s:输出更详细的信息;
-f:强制使用指定的协议族;
-4:指定使用的网络层协议是IPv4协议;
-6:指定使用的网络层协议是IPv6协议;
-0:输出信息每条记录输出一行,即使内容较多也不换行显示;
-r:显示主机时,不使用IP地址,而使用主机的域名。
显示核心路由表
[root@localhost ~]# ip route list
default via 192.168.101.1 dev ens192
default via 192.168.101.1 dev ens192 proto dhcp metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.101.0/24 dev ens192 proto kernel scope link src 192.168.101.15
192.168.101.0/24 dev ens192 proto kernel scope link src 192.168.101.15 metric 100
netstat
netstat 命令用来打印Linux中网络系统的状态信息。
-a或--all:显示所有连线中的Socket;
-A<网络类型>或--<网络类型>:列出该网络类型连线中的相关地址;
-c或--continuous:持续列出网络状态;
-C或--cache:显示路由器配置的快取信息;
-e或--extend:显示网络其他相关信息;
-F或--fib:显示FIB;
-g或--groups:显示多重广播功能群组组员名单;
-h或--help:在线帮助;
-i或--interfaces:显示网络界面信息表单;
-l或--listening:显示监控中的服务器的Socket;
-M或--masquerade:显示伪装的网络连线;
-n或--numeric:直接使用ip地址,而不通过域名服务器;
-N或--netlink或--symbolic:显示网络硬件外围设备的符号连接名称;
-o或--timers:显示计时器;
-p或--programs:显示正在使用Socket的程序识别码和程序名称;
-r或--route:显示Routing Table;
-s或--statistice:显示网络工作信息统计表;
-t或--tcp:显示TCP传输协议的连线状况;
-u或--udp:显示UDP传输协议的连线状况;
-v或--verbose:显示指令执行过程;
-V或--version:显示版本信息;
-w或--raw:显示RAW传输协议的连线状况;
-x或--unix:此参数的效果和指定"-A unix"参数相同;
--ip或--inet:此参数的效果和指定"-A inet"参数相同。
列出所有端口
[root@localhost ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdoma:ssh 192.168.248.18:53787 ESTABLISHED
tcp 0 0 localhost.localdoma:ssh 192.168.248.18:53414 ESTABLISHED
tcp6 0 0 [::]:http [::]:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 localhost:smtp [::]:* LISTEN
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 localhost:323 0.0.0.0:*
udp6 0 0 localhost:323 [::]:*
raw6 0 0 [::]:ipv6-icmp [::]:* 7
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 43276 /var/run/NetworkManager/private-dhcp
unix 3 [ ] DGRAM 7448 /run/systemd/notify
unix 2 [ ] DGRAM 7450 /run/systemd/cgroups-agent
unix 2 [ ACC ] STREAM LISTENING 19497 /run/lvm/lvmetad.socket
unix 2 [ ACC ] STREAM LISTENING 7465 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 34544 private/rewrite
unix 2 [ ACC ] STREAM LISTENING 34547 private/bounce
unix 6 [ ] DGRAM 7468 /run/systemd/journal/socket
unix 2 [ ACC ] STREAM LISTENING 34550 private/defer
unix 2 [ ACC ] STREAM LISTENING 34553 private/trace
unix 14 [ ] DGRAM 7470 /dev/log
...
列出所有tcp端口
[root@localhost ~]# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdoma:ssh 192.168.248.18:53787 ESTABLISHED
tcp 0 0 localhost.localdoma:ssh 192.168.248.18:53414 ESTABLISHED
tcp6 0 0 [::]:http [::]:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 localhost:smtp [::]:* LISTEN
列出所有udp端口
[root@localhost ~]# netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 localhost:323 0.0.0.0:*
udp6 0 0 localhost:323 [::]:*
只显示监听端口
[root@localhost ~]# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN
tcp6 0 0 [::]:http [::]:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 localhost:smtp [::]:* LISTEN
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 localhost:323 0.0.0.0:*
udp6 0 0 localhost:323 [::]:*
raw6 0 0 [::]:ipv6-icmp [::]:* 7
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 43276 /var/run/NetworkManager/private-dhcp
unix 2 [ ACC ] STREAM LISTENING 19497 /run/lvm/lvmetad.socket
unix 2 [ ACC ] STREAM LISTENING 7465 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 34544 private/rewrite
unix 2 [ ACC ] STREAM LISTENING 34547 private/bounce
unix 2 [ ACC ] STREAM LISTENING 34550 private/defer
...
列出所有监听tcp端口
[root@localhost ~]# netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN
tcp6 0 0 [::]:http [::]:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 localhost:smtp [::]:* LISTEN
列出所有监听udp端口
[root@localhost ~]# netstat -lu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 0.0.0.0:bootpc 0.0.0.0:*
udp 0 0 localhost:323 0.0.0.0:*
udp6 0 0 localhost:323 [::]:*
列出所有监听的unix端口
[root@localhost ~]# netstat -lx
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 43276 /var/run/NetworkManager/private-dhcp
unix 2 [ ACC ] STREAM LISTENING 19497 /run/lvm/lvmetad.socket
unix 2 [ ACC ] STREAM LISTENING 7465 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 34544 private/rewrite
unix 2 [ ACC ] STREAM LISTENING 34547 private/bounce
unix 2 [ ACC ] STREAM LISTENING 34550 private/defer
unix 2 [ ACC ] STREAM LISTENING 34553 private/trace
unix 2 [ ACC ] STREAM LISTENING 34556 private/verify
unix 2 [ ACC ] STREAM LISTENING 34562 private/proxymap
unix 2 [ ACC ] STREAM LISTENING 34565 private/proxywrite
unix 2 [ ACC ] STREAM LISTENING 34568 private/smtp
unix 2 [ ACC ] STREAM LISTENING 34571 private/relay
unix 2 [ ACC ] STREAM LISTENING 34577 private/error
unix 2 [ ACC ] STREAM LISTENING 34580 private/retry
unix 2 [ ACC ] STREAM LISTENING 34583 private/discard
unix 2 [ ACC ] STREAM LISTENING 34586 private/local
unix 2 [ ACC ] STREAM LISTENING 34589 private/virtual
unix 2 [ ACC ] STREAM LISTENING 34592 private/lmtp
unix 2 [ ACC ] STREAM LISTENING 34595 private/anvil
unix 2 [ ACC ] STREAM LISTENING 34598 private/scache
unix 2 [ ACC ] STREAM LISTENING 19534 /run/lvm/lvmpolld.socket
unix 2 [ ACC ] STREAM LISTENING 234351 /var/run/docker.sock
unix 2 [ ACC ] SEQPACKET LISTENING 19579 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 234623 /run/docker/libnetwork/a4ce099d1b167ea4ee8ed534d61a013ff1bd2c80047b02e670c1eed3e9cb459d.sock
unix 2 [ ACC ] STREAM LISTENING 234367 /var/run/docker/libcontainerd/docker-containerd.sock
unix 2 [ ACC ] STREAM LISTENING 34529 public/pickup
unix 2 [ ACC ] STREAM LISTENING 34534 public/cleanup
unix 2 [ ACC ] STREAM LISTENING 34537 public/qmgr
unix 2 [ ACC ] STREAM LISTENING 34559 public/flush
unix 2 [ ACC ] STREAM LISTENING 34574 public/showq
unix 2 [ ACC ] STREAM LISTENING 34541 private/tlsmgr
unix 2 [ ACC ] STREAM LISTENING 19377 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 29926 /run/dbus/system_bus_socket
显示所有端口的统计信息
[root@localhost ~]# netstat -s
Ip:
1162792 total packets received
0 forwarded
0 incoming packets discarded
1157932 incoming packets delivered
982159 requests sent out
49 outgoing packets dropped
25 dropped because of missing route
Icmp:
169 ICMP messages received
2 input ICMP message failed.
ICMP input histogram:
destination unreachable: 106
echo requests: 1
echo replies: 62
171 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 106
redirect: 2
echo request: 62
echo replies: 1
IcmpMsg:
InType0: 62
InType3: 106
InType8: 1
OutType0: 1
OutType3: 106
OutType5: 2
OutType8: 62
Tcp:
229 active connections openings
34 passive connection openings
7 failed connection attempts
23 connection resets received
2 connections established
1155423 segments received
968914 segments send out
12738 segments retransmited
0 bad segments received.
226 resets sent
Udp:
1700 packets received
103 packets to unknown port received.
0 packet receive errors
1926 packets sent
0 receive buffer errors
0 send buffer errors
UdpLite:
TcpExt:
2 invalid SYN cookies received
162 TCP sockets finished time wait in fast timer
8 packets rejects in established connections because of timestamp
7623 delayed acks sent
91 delayed acks further delayed because of locked socket
Quick ack mode was activated 1117 times
7356 packets directly queued to recvmsg prequeue.
749489 bytes directly in process context from backlog
16216371 bytes directly received in process context from prequeue
186725 packet headers predicted
4624 packets header predicted and directly queued to user
501178 acknowledgments not containing data payload received
229909 predicted acknowledgments
6339 times recovered from packet loss by selective acknowledgements
610 congestion windows recovered without slow start by DSACK
2357 congestion windows recovered without slow start after partial ack
TCPLostRetransmit: 90
2395 timeouts after SACK recovery
2 timeouts in loss state
6484 fast retransmits
184 forward retransmits
24 retransmits in slow start
79 other TCP timeouts
TCPLossProbes: 5004
TCPLossProbeRecovery: 3109
87 SACK retransmits failed
1125 DSACKs sent for old packets
1066 DSACKs received
61 DSACKs for out of order packets received
17 connections reset due to unexpected data
14 connections reset due to early user close
8 connections aborted due to timeout
TCPDSACKIgnoredNoUndo: 201
TCPSpuriousRTOs: 2312
TCPSackShifted: 215
TCPSackMerged: 676
TCPSackShiftFallback: 24410
TCPDeferAcceptDrop: 10
TCPRcvCoalesce: 175962
TCPOFOQueue: 18148
TCPChallengeACK: 1
TCPSpuriousRtxHostQueues: 3
TCPAutoCorking: 18546
TCPFromZeroWindowAdv: 101
TCPToZeroWindowAdv: 101
TCPWantZeroWindowAdv: 97
TCPSynRetrans: 4
TCPOrigDataSent: 739720
TCPACKSkippedSeq: 1
IpExt:
InNoRoutes: 22
InMcastPkts: 2
InBcastPkts: 5353
InOctets: 820793465
OutOctets: 139084042
InMcastOctets: 72
InBcastOctets: 949654
InNoECTPkts: 1249499
InECT0Pkts: 213844
显示所有tcp端口的统计信息
[root@localhost ~]# netstat -st
IcmpMsg:
InType0: 62
InType3: 106
InType8: 1
OutType0: 1
OutType3: 106
OutType5: 2
OutType8: 62
Tcp:
229 active connections openings
34 passive connection openings
7 failed connection attempts
23 connection resets received
2 connections established
1159183 segments received
972142 segments send out
12788 segments retransmited
0 bad segments received.
226 resets sent
UdpLite:
TcpExt:
2 invalid SYN cookies received
162 TCP sockets finished time wait in fast timer
8 packets rejects in established connections because of timestamp
7672 delayed acks sent
91 delayed acks further delayed because of locked socket
Quick ack mode was activated 1124 times
7356 packets directly queued to recvmsg prequeue.
749489 bytes directly in process context from backlog
16216371 bytes directly received in process context from prequeue
187109 packet headers predicted
4624 packets header predicted and directly queued to user
503127 acknowledgments not containing data payload received
230636 predicted acknowledgments
6365 times recovered from packet loss by selective acknowledgements
610 congestion windows recovered without slow start by DSACK
2369 congestion windows recovered without slow start after partial ack
TCPLostRetransmit: 90
2407 timeouts after SACK recovery
2 timeouts in loss state
6509 fast retransmits
184 forward retransmits
24 retransmits in slow start
79 other TCP timeouts
TCPLossProbes: 5026
TCPLossProbeRecovery: 3120
[root@localhost ~]# netstat -st
IcmpMsg:
InType0: 62
InType3: 106
InType8: 1
OutType0: 1
OutType3: 106
OutType5: 2
OutType8: 62
Tcp:
229 active connections openings
34 passive connection openings
7 failed connection attempts
23 connection resets received
2 connections established
1159353 segments received
972286 segments send out
12790 segments retransmited
0 bad segments received.
226 resets sent
UdpLite:
TcpExt:
2 invalid SYN cookies received
162 TCP sockets finished time wait in fast timer
8 packets rejects in established connections because of timestamp
7674 delayed acks sent
91 delayed acks further delayed because of locked socket
Quick ack mode was activated 1124 times
7356 packets directly queued to recvmsg prequeue.
749489 bytes directly in process context from backlog
16216371 bytes directly received in process context from prequeue
187124 packet headers predicted
4624 packets header predicted and directly queued to user
503217 acknowledgments not containing data payload received
230669 predicted acknowledgments
6366 times recovered from packet loss by selective acknowledgements
610 congestion windows recovered without slow start by DSACK
2370 congestion windows recovered without slow start after partial ack
TCPLostRetransmit: 90
2408 timeouts after SACK recovery
2 timeouts in loss state
6510 fast retransmits
184 forward retransmits
24 retransmits in slow start
79 other TCP timeouts
TCPLossProbes: 5026
TCPLossProbeRecovery: 3120
88 SACK retransmits failed
1132 DSACKs sent for old packets
1066 DSACKs received
61 DSACKs for out of order packets received
17 connections reset due to unexpected data
14 connections reset due to early user close
8 connections aborted due to timeout
TCPDSACKIgnoredNoUndo: 201
TCPSpuriousRTOs: 2324
TCPSackShifted: 215
TCPSackMerged: 676
TCPSackShiftFallback: 24527
TCPDeferAcceptDrop: 10
TCPRcvCoalesce: 176295
TCPOFOQueue: 18150
TCPChallengeACK: 1
TCPSpuriousRtxHostQueues: 3
TCPAutoCorking: 18622
TCPFromZeroWindowAdv: 101
TCPToZeroWindowAdv: 101
TCPWantZeroWindowAdv: 97
TCPSynRetrans: 4
TCPOrigDataSent: 742534
TCPACKSkippedSeq: 1
IpExt:
InNoRoutes: 22
InMcastPkts: 2
InBcastPkts: 5353
InOctets: 821060393
OutOctets: 139598022
InMcastOctets: 72
InBcastOctets: 949654
InNoECTPkts: 1252310
InECT0Pkts: 214966
显示udp端口的统计信息
[root@localhost ~]# netstat -su
IcmpMsg:
InType0: 62
InType3: 106
InType8: 1
OutType0: 1
OutType3: 106
OutType5: 2
OutType8: 62
Udp:
1703 packets received
103 packets to unknown port received.
0 packet receive errors
1929 packets sent
0 receive buffer errors
0 send buffer errors
UdpLite:
IpExt:
InNoRoutes: 22
InMcastPkts: 2
InBcastPkts: 5353
InOctets: 821170745
OutOctets: 139824942
InMcastOctets: 72
InBcastOctets: 949654
InNoECTPkts: 1253475
InECT0Pkts: 215428
显示进程pid和进程名称
[root@localhost ~]# netstat -atp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 5994/sshd
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN 6561/master
tcp 0 0 localhost.localdoma:ssh 192.168.248.18:53787 ESTABLISHED 16393/sshd: root@pt
tcp 0 52 localhost.localdoma:ssh 192.168.248.18:53414 ESTABLISHED 32537/sshd: root@pt
tcp6 0 0 [::]:http [::]:* LISTEN 14493/httpd
tcp6 0 0 [::]:ssh [::]:* LISTEN 5994/sshd
tcp6 0 0 localhost:smtp [::]:* LISTEN 6561/master
显示IP地址和端口
[root@localhost ~]# netstat -atpn
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5994/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6561/master
tcp 0 0 192.168.101.15:22 192.168.248.18:53787 ESTABLISHED 16393/sshd: root@pt
tcp 0 52 192.168.101.15:22 192.168.248.18:53414 ESTABLISHED 32537/sshd: root@pt
tcp6 0 0 :::80 :::* LISTEN 14493/httpd
tcp6 0 0 :::22 :::* LISTEN 5994/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6561/master
显示监听的端口
[root@localhost ~]# netstat -antpl
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5994/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6561/master
tcp 0 0 192.168.101.15:22 192.168.248.18:53787 ESTABLISHED 16393/sshd: root@pt
tcp 0 0 192.168.101.15:22 192.168.248.18:53414 ESTABLISHED 32537/sshd: root@pt
tcp6 0 0 :::80 :::* LISTEN 14493/httpd
tcp6 0 0 :::22 :::* LISTEN 5994/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6561/master
每隔一秒输出一次
使用-c参数
[root@localhost ~]# netstat -antplc
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5994/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6561/master
tcp 0 0 192.168.101.15:22 192.168.248.18:53787 ESTABLISHED 16393/sshd: root@pt
tcp 0 0 192.168.101.15:22 192.168.248.18:53414 ESTABLISHED 32537/sshd: root@pt
tcp6 0 0 :::80 :::* LISTEN 14493/httpd
tcp6 0 0 :::22 :::* LISTEN 5994/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6561/master
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5994/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6561/master
tcp 0 0 192.168.101.15:22 192.168.248.18:53787 ESTABLISHED 16393/sshd: root@pt
tcp 0 0 192.168.101.15:22 192.168.248.18:53414 ESTABLISHED 32537/sshd: root@pt
tcp6 0 0 :::80 :::* LISTEN 14493/httpd
tcp6 0 0 :::22 :::* LISTEN 5994/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6561/master
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5994/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6561/master
tcp 0 0 192.168.101.15:22 192.168.248.18:53787 ESTABLISHED 16393/sshd: root@pt
tcp 0 0 192.168.101.15:22 192.168.248.18:53414 ESTABLISHED 32537/sshd: root@pt
tcp6 0 0 :::80 :::* LISTEN 14493/httpd
tcp6 0 0 :::22 :::* LISTEN 5994/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6561/master
...
显示网络接口列表
[root@localhost ~]# netstat -i
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
docker0 1500 4 0 0 0 3 0 0 0 BMU
ens192 1500 1541549 0 0 0 1006881 0 0 0 BMRU
lo 65536 244 0 0 0 244 0 0 0 LRU
ethtool
ethtool 命令用于获取以太网卡的配置信息,或者修改这些配置。这个命令比较复杂,功能特别多。
-a 查看网卡中 接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。
-A 修改网卡中 接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。
-c display the Coalesce information of the specified ethernet card。
-C Change the Coalesce setting of the specified ethernet card。
-g Display the rx/tx ring parameter information of the specified ethernet card。
-G change the rx/tx ring setting of the specified ethernet card。
-i 显示网卡驱动的信息,如驱动的名称、版本等。
-d 显示register dump信息, 部分网卡驱动不支持该选项。
-e 显示EEPROM dump信息,部分网卡驱动不支持该选项。
-E 修改网卡EEPROM byte。
-k 显示网卡Offload参数的状态:on 或 off,包括rx-checksumming、tx-checksumming等。
-K 修改网卡Offload参数的状态。
-p 用于区别不同ethX对应网卡的物理位置,常用的方法是使网卡port上的led不断的闪;N指示了网卡闪的持续时间,以秒为单位。
-r 如果auto-negotiation模块的状态为on,则restarts auto-negotiation。
-S 显示NIC- and driver-specific 的统计参数,如网卡接收/发送的字节数、接收/发送的广播包个数等。
-t 让网卡执行自我检测,有两种模式:offline or online。
-s 修改网卡的部分配置,包括网卡速度、单工/全双工模式、mac地址等。
查看机器上网卡的速度:百兆还是千兆
[root@localhost ~]# ethtool ens192
Settings for ens192:
Supported ports: [ TP ]
Supported link modes: 1000baseT/Full
10000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: No
Supported FEC modes: Not reported
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Advertised FEC modes: Not reported
Speed: 10000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
MDI-X: Unknown
Supports Wake-on: uag
Wake-on: d
Link detected: yes
将千兆网卡降速为百兆
[root@localhost ~]# ethtool -s ens192 speed 100
Cannot set new settings: Operation not supported
not setting speed
nslookup
nslookup 命令是常用域名查询工具,就是查DNS信息用的命令。
[root@localhost ~]# nslookup www.baidu.com
Server: 119.29.29.29
Address: 119.29.29.29#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 112.80.248.76
Name: www.a.shifen.com
Address: 112.80.248.75
wget
wget命令用来从指定的URL下载文件。wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。
-a<日志文件>:在指定的日志文件中记录资料的执行过程;
-A<后缀名>:指定要下载文件的后缀名,多个后缀名之间使用逗号进行分隔;
-b:进行后台的方式运行wget;
-B<连接地址>:设置参考的连接地址的基地地址;
-c:继续执行上次终端的任务;
-C<标志>:设置服务器数据块功能标志on为激活,off为关闭,默认值为on;
-d:调试模式运行指令;
-D<域名列表>:设置顺着的域名列表,域名之间用“,”分隔;
-e<指令>:作为文件“.wgetrc”中的一部分执行指定的指令;
-h:显示指令帮助信息;
-i<文件>:从指定文件获取要下载的URL地址;
-l<目录列表>:设置顺着的目录列表,多个目录用“,”分隔;
-L:仅顺着关联的连接;
-r:递归下载方式;
-nc:文件存在时,下载文件不覆盖原有文件;
-nv:下载时只显示更新和出错信息,不显示指令的详细执行过程;
-q:不显示指令执行过程;
-nh:不查询主机名称;
-v:显示详细执行过程;
-V:显示版本信息;
--passive-ftp:使用被动模式PASV连接FTP服务器;
--follow-ftp:从HTML文件中下载FTP连接文件。
下载单个文件
[root@localhost ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-06-13 03:06:49-- http://nginx.org/download/nginx-1.18.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1039530 (1015K) [application/octet-stream]
正在保存至: “nginx-1.18.0.tar.gz”
100%[===================================================================================================================================================>] 1,039,530 217KB/s 用时 4.7s
2020-06-13 03:06:55 (217 KB/s) - 已保存 “nginx-1.18.0.tar.gz” [1039530/1039530])
下载并以指定的文件名保存
[root@localhost ~]# wget -O nginx.tar.gz http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-06-13 03:08:31-- http://nginx.org/download/nginx-1.18.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1039530 (1015K) [application/octet-stream]
正在保存至: “nginx.tar.gz”
100%[===================================================================================================================================================>] 1,039,530 213KB/s 用时 4.8s
2020-06-13 03:08:37 (213 KB/s) - 已保存 “nginx.tar.gz” [1039530/1039530])
[root@localhost ~]# ls
nginx.tar.gz
限速下载
当你执行wget的时候,它默认会占用全部可能的宽带下载。但是当你准备下载一个大文件,而你还需要下载其它文件时就有必要限速了。
[root@localhost ~]# wget --limit-rate=10k http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-06-13 03:10:59-- http://nginx.org/download/nginx-1.18.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|3.125.197.172|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1039530 (1015K) [application/octet-stream]
正在保存至: “nginx-1.18.0.tar.gz.2”
3% [====> ] 40,960 9.99KB/s 剩余 98s
断点续传
使用
wget -c重新启动下载中断的文件,对于我们下载大文件时突然由于网络等原因中断非常有帮助,我们可以继续接着下载而不是重新下载一个文件。需要继续中断的下载时可以使用-c参数。
[root@localhost ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-06-13 03:15:07-- http://nginx.org/download/nginx-1.18.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1039530 (1015K) [application/octet-stream]
正在保存至: “nginx-1.18.0.tar.gz”
17% [========================> ] 178,277 123KB/s ^C
[root@localhost ~]# wget -c http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-06-13 03:15:15-- http://nginx.org/download/nginx-1.18.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|3.125.197.172|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 206 Partial Content
长度:1039530 (1015K),剩余 782053 (764K) [application/octet-stream]
正在保存至: “nginx-1.18.0.tar.gz”
100%[++++++++++++++++++++++++++++++++++++===============================================================================================================>] 1,039,530 434KB/s 用时 1.8s
2020-06-13 03:15:17 (434 KB/s) - 已保存 “nginx-1.18.0.tar.gz” [1039530/1039530])
后台下载文件
对于下载非常大的文件的时候,我们可以使用参数
-b进行后台下载
[root@localhost ~]# wget --limit-rate=1m -b http://nginx.org/download/nginx-1.18.0.tar.gz
继续在后台运行,pid 为 26030。
将把输出写入至 “wget-log”。
[root@localhost ~]# tail -f wget-log
长度:1039530 (1015K) [application/octet-stream]
正在保存至: “nginx-1.18.0.tar.gz”
0K .......... .......... .......... .......... .......... 4% 69.7K 14s
50K .......... .......... .......... .......... .......... 9% 139K 10s
100K .......... .......... .......... .......... .......... 14% 61.3M 6s
150K .......... .......... .......... .......... .......... 19% 139K 6s
200K .......... .......... .......... .......... .......... 24% 173M 4s
250K .......... .......... .......... .......... .......... 29% 139K 4s
300K .......... .......... .......... .......... .......... 34% 60.9K 5s
350K .......... .......... .......... .......... .......... 39% 179M 4s
400K .......... .......... .......... .......... .......... 44% 186M 3s
450K .......... .......... .......... .......... .......... 49% 196K 3s
500K .......... .......... .......... .......... .......... 54% 139K 3s
550K .......... .......... .......... .......... .......... 59% 41.2M 2s
600K .......... .......... .......... .......... .......... 64% 139K 2s
650K .......... .......... .......... .......... .......... 68% 140K 2s
700K .......... .......... .......... .......... .......... 73% 5.62M 1s
750K .......... .......... .......... .......... .......... 78% 142K 1s
800K .......... .......... .......... .......... .......... 83% 486K 1s
850K .......... .......... .......... .......... .......... 88% 194K 1s
900K .......... .......... .......... .......... .......... 93% 489K 0s
950K .......... .......... .......... .......... .......... 98% 193K 0s
1000K .......... ..... 100% 7.50M=5.0s
2020-06-13 03:19:36 (202 KB/s) - 已保存 “nginx-1.18.0.tar.gz” [1039530/1039530])
伪装代理名称下载
有些网站能通过根据判断代理名称不是浏览器而拒绝你的下载请求。不过你可以通过
--user-agent参数伪装。
[root@localhost ~]# wget --user-agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16" http://nginx.org/download/nginx-1.18.0.tar.gz
测试下载链接
当你打算进行定时下载,你应该在预定时间测试下载链接是否有效。我们可以增加
--spider参数进行检查。
[root@localhost ~]# wget --spider http://nginx.org/download/nginx-1.18.0.tar.gz
开启 Spider 模式。检查是否存在远程文件。
--2020-06-13 03:23:14-- http://nginx.org/download/nginx-1.18.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
正在连接 nginx.org (nginx.org)|3.125.197.172|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1039530 (1015K) [application/octet-stream]
存在远程文件。
[root@localhost ~]# wget --spider http://nginx.org/download/helloasdfasklfjaldfjlaksdjflasdf.asfs
开启 Spider 模式。检查是否存在远程文件。
--2020-06-13 03:23:25-- http://nginx.org/download/helloasdfasklfjaldfjlaksdjflasdf.asfs
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 404 Not Found
远程文件不存在 -- 链接失效!!!
增加重试次数
如果网络有问题或下载一个大文件也有可能失败。wget默认重试20次连接下载文件。如果需要,你可以使用
--tries增加重试次数。
wget --tries=40 http://nginx.org/download/nginx-1.18.0.tar.gz
下载多个文件
[root@localhost ~]# ls
downlist.txt
[root@localhost ~]# cat downlist.txt
http://nginx.org/download/nginx-1.18.0.tar.gz
https://mirrors.huaweicloud.com/python/3.8.6/Python-3.8.6.tgz
[root@localhost ~]#
[root@localhost ~]# wget -i downlist.txt
--2020-06-13 03:29:08-- http://nginx.org/download/nginx-1.18.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1039530 (1015K) [application/octet-stream]
正在保存至: “nginx-1.18.0.tar.gz”
100%[===================================================================================================================================================>] 1,039,530 149KB/s 用时 7.3s
2020-06-13 03:29:16 (139 KB/s) - 已保存 “nginx-1.18.0.tar.gz” [1039530/1039530])
--2020-06-13 03:29:16-- https://mirrors.huaweicloud.com/python/3.8.6/Python-3.8.6.tgz
正在解析主机 mirrors.huaweicloud.com (mirrors.huaweicloud.com)... 117.78.24.36, 117.78.24.32, 117.78.24.34
正在连接 mirrors.huaweicloud.com (mirrors.huaweicloud.com)|117.78.24.36|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:24377280 (23M) [application/octet-stream]
正在保存至: “Python-3.8.6.tgz”
100%[===================================================================================================================================================>] 24,377,280 3.25MB/s 用时 30s
2020-06-13 03:29:48 (792 KB/s) - 已保存 “Python-3.8.6.tgz” [24377280/24377280])
FINISHED --2020-06-13 03:29:48--
Total wall clock time: 40s
Downloaded: 2 files, 24M in 37s (664 KB/s)
[root@localhost ~]# ls
downlist.txt nginx-1.18.0.tar.gz Python-3.8.6.tgz
证书问题下载不了文件
[root@localhost ~]# wget https://download.redis.io/releases/redis-6.0.8.tar.gz
--2020-06-13 03:32:35-- https://download.redis.io/releases/redis-6.0.8.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 45.60.125.1
正在连接 download.redis.io (download.redis.io)|45.60.125.1|:443... 已连接。
错误: 无法验证 download.redis.io 的由 “/C=BE/O=GlobalSign nv-sa/CN=GlobalSign HV RSA DV SSL CA 2018” 颁发的证书:
颁发的证书还未生效。
要以不安全的方式连接至 download.redis.io,使用“--no-check-certificate”。
[root@localhost ~]# wget https://download.redis.io/releases/redis-6.0.8.tar.gz --no-check-certificate
--2020-06-13 03:34:23-- https://download.redis.io/releases/redis-6.0.8.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 45.60.125.1
正在连接 download.redis.io (download.redis.io)|45.60.125.1|:443... 已连接。
警告: 无法验证 download.redis.io 的由 “/C=BE/O=GlobalSign nv-sa/CN=GlobalSign HV RSA DV SSL CA 2018” 颁发的证书:
颁发的证书还未生效。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2247528 (2.1M) [application/octet-stream]
正在保存至: “redis-6.0.8.tar.gz”
100%[===================================================================================================================================================>] 2,247,528 54.2KB/s 用时 44s
2020-06-13 03:35:08 (50.1 KB/s) - 已保存 “redis-6.0.8.tar.gz” [2247528/2247528])
这个参数会让你在 wget 进行对 https 站点的请求时不再检查证书(不推荐)。但是可能会受到HTTP劫持。
下载镜像网站, 下载整个网站到本地。
--miror 开户镜像下载。
-p 下载所有为了html页面显示正常的文件。
--convert-links 下载后,转换成本地的链接。
-P ./site 保存所有文件和目录到本地指定目录。
wget --mirror -p --convert-links -P ./site https://goframe.org/index
过滤指定格式下载
下载一个网站,但你不希望下载图片和html,可以使用这条命令。
wget --mirror -p --convert-links -P ./site https://goframe.org/index --reject=jpg,html
把下载信息存入日志文件
不希望下载信息直接显示在终端而是在一个日志文件,可以使用。
[root@localhost ~]# wget -o download.log http://nginx.org/download/nginx-1.18.0.tar.gz
[root@localhost ~]# ls
download.log nginx-1.18.0.tar.gz
下载指定格式的文件
下载一个网站的所有图片。
下载一个网站的所有视频。
下载一个网站的所有PDF文件。
wget -r -A.jpg http://pic.netbian.com/
下载ftp文件, 使用用户名密码认证下载
wget ftp-url
wget --ftp-user=用户名 --ftp-password=密码 url连接地址
使用wget匿名ftp下载
wget ftp-url
curl
curl 命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称curl为下载工具。作为一款强力工具,curl支持包括HTTP、HTTPS、ftp等众多协议,还支持POST、cookies、认证、从指定偏移处下载部分文件、用户代理字符串、限速、文件大小、进度条等特征。
-a/--append 上传文件时,附加到目标文件
-A/--user-agent <string> 设置用户代理发送给服务器
-anyauth 可以使用“任何”身份验证方法
-b/--cookie <name=string/file> cookie字符串或文件读取位置
--basic 使用HTTP基本验证
-B/--use-ascii 使用ASCII /文本传输
-c/--cookie-jar <file> 操作结束后把cookie写入到这个文件中
-C/--continue-at <offset> 断点续转
-d/--data <data> HTTP POST方式传送数据
--data-ascii <data> 以ascii的方式post数据
--data-binary <data> 以二进制的方式post数据
--negotiate 使用HTTP身份验证
--digest 使用数字身份验证
--disable-eprt 禁止使用EPRT或LPRT
--disable-epsv 禁止使用EPSV
-D/--dump-header <file> 把header信息写入到该文件中
--egd-file <file> 为随机数据(SSL)设置EGD socket路径
--tcp-nodelay 使用TCP_NODELAY选项
-e/--referer 来源网址
-E/--cert <cert[:passwd]> 客户端证书文件和密码 (SSL)
--cert-type <type> 证书文件类型 (DER/PEM/ENG) (SSL)
--key <key> 私钥文件名 (SSL)
--key-type <type> 私钥文件类型 (DER/PEM/ENG) (SSL)
--pass <pass> 私钥密码 (SSL)
--engine <eng> 加密引擎使用 (SSL). "--engine list" for list
--cacert <file> CA证书 (SSL)
--capath <directory> CA目录 (made using c_rehash) to verify peer against (SSL)
--ciphers <list> SSL密码
--compressed 要求返回是压缩的形势 (using deflate or gzip)
--connect-timeout <seconds> 设置最大请求时间
--create-dirs 建立本地目录的目录层次结构
--crlf 上传是把LF转变成CRLF
-f/--fail 连接失败时不显示http错误
--ftp-create-dirs 如果远程目录不存在,创建远程目录
--ftp-method [multicwd/nocwd/singlecwd] 控制CWD的使用
--ftp-pasv 使用 PASV/EPSV 代替端口
--ftp-skip-pasv-ip 使用PASV的时候,忽略该IP地址
--ftp-ssl 尝试用 SSL/TLS 来进行ftp数据传输
--ftp-ssl-reqd 要求用 SSL/TLS 来进行ftp数据传输
-F/--form <name=content> 模拟http表单提交数据
--form-string <name=string> 模拟http表单提交数据
-g/--globoff 禁用网址序列和范围使用{}和[]
-G/--get 以get的方式来发送数据
-H/--header <line> 自定义头信息传递给服务器
--ignore-content-length 忽略的HTTP头信息的长度
-i/--include 输出时包括protocol头信息
-I/--head 只显示请求头信息
-j/--junk-session-cookies 读取文件进忽略session cookie
--interface <interface> 使用指定网络接口/地址
--krb4 <level> 使用指定安全级别的krb4
-k/--insecure 允许不使用证书到SSL站点
-K/--config 指定的配置文件读取
-l/--list-only 列出ftp目录下的文件名称
--limit-rate <rate> 设置传输速度
--local-port<NUM> 强制使用本地端口号
-m/--max-time <seconds> 设置最大传输时间
--max-redirs <num> 设置最大读取的目录数
--max-filesize <bytes> 设置最大下载的文件总量
-M/--manual 显示全手动
-n/--netrc 从netrc文件中读取用户名和密码
--netrc-optional 使用 .netrc 或者 URL来覆盖-n
--ntlm 使用 HTTP NTLM 身份验证
-N/--no-buffer 禁用缓冲输出
-o/--output 把输出写到该文件中
-O/--remote-name 把输出写到该文件中,保留远程文件的文件名
-p/--proxytunnel 使用HTTP代理
--proxy-anyauth 选择任一代理身份验证方法
--proxy-basic 在代理上使用基本身份验证
--proxy-digest 在代理上使用数字身份验证
--proxy-ntlm 在代理上使用ntlm身份验证
-P/--ftp-port <address> 使用端口地址,而不是使用PASV
-q 作为第一个参数,关闭 .curlrc
-Q/--quote <cmd> 文件传输前,发送命令到服务器
-r/--range <range> 检索来自HTTP/1.1或FTP服务器字节范围
--range-file 读取(SSL)的随机文件
-R/--remote-time 在本地生成文件时,保留远程文件时间
--retry <num> 传输出现问题时,重试的次数
--retry-delay <seconds> 传输出现问题时,设置重试间隔时间
--retry-max-time <seconds> 传输出现问题时,设置最大重试时间
-s/--silent 静默模式。不输出任何东西
-S/--show-error 显示错误
--socks4 <host[:port]> 用socks4代理给定主机和端口
--socks5 <host[:port]> 用socks5代理给定主机和端口
--stderr <file>
-t/--telnet-option <OPT=val> Telnet选项设置
--trace <file> 对指定文件进行debug
--trace-ascii <file> Like --跟踪但没有hex输出
--trace-time 跟踪/详细输出时,添加时间戳
-T/--upload-file <file> 上传文件
--url <URL> Spet URL to work with
-u/--user <user[:password]> 设置服务器的用户和密码
-U/--proxy-user <user[:password]> 设置代理用户名和密码
-w/--write-out [format] 什么输出完成后
-x/--proxy <host[:port]> 在给定的端口上使用HTTP代理
-X/--request <command> 指定什么命令
-y/--speed-time 放弃限速所要的时间,默认为30
-Y/--speed-limit 停止传输速度的限制,速度时间
文件下载
[root@localhost ~]# curl http://nginx.org/download/nginx-1.18.0.tar.gz -O
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1015k 100 1015k 0 0 215k 0 0:00:04 0:00:04 --:--:-- 240k
[root@localhost ~]# ls
nginx-1.18.0.tar.gz
下载文件不显示进度信息使用--silent选项。
[root@localhost ~]# curl http://nginx.org/download/nginx-1.18.0.tar.gz -O --silent
[root@localhost ~]# ls
nginx-1.18.0.tar.gz
-o 将下载数据写入到指定名称的文件中,并使用--progress显示进度条
[root@localhost ~]# curl http://nginx.org/download/nginx-1.18.0.tar.gz -o nginx1.8.tar.gz --progress
######################################################################## 100.0%
[root@localhost ~]# ls
nginx1.8.tar.gz
设置user-agent
curl URL --user-agent "Mozilla/5.0"
curl URL -A "Mozilla/5.0"
限速下载
curl URL --limit-rate 50k
tcpdump
需要安装 yum -y install tcpdump
tcpdump 命令是一款sniffer工具,它可以打印所有经过网络接口的数据包的头信息,也可以使用-w选项将数据包保存到文件中,方便以后分析。
-a:尝试将网络和广播地址转换成名称;
-c<数据包数目>:收到指定的数据包数目后,就停止进行倾倒操作;
-d:把编译过的数据包编码转换成可阅读的格式,并倾倒到标准输出;
-dd:把编译过的数据包编码转换成C语言的格式,并倾倒到标准输出;
-ddd:把编译过的数据包编码转换成十进制数字的格式,并倾倒到标准输出;
-e:在每列倾倒资料上显示连接层级的文件头;
-f:用数字显示网际网络地址;
-F<表达文件>:指定内含表达方式的文件;
-i<网络界面>:使用指定的网络截面送出数据包;
-l:使用标准输出列的缓冲区;
-n:不把主机的网络地址转换成名字;
-N:不列出域名;
-O:不将数据包编码最佳化;
-p:不让网络界面进入混杂模式;
-q :快速输出,仅列出少数的传输协议信息;
-r<数据包文件>:从指定的文件读取数据包数据;
-s<数据包大小>:设置每个数据包的大小;
-S:用绝对而非相对数值列出TCP关联数;
-t:在每列倾倒资料上不显示时间戳记;
-tt: 在每列倾倒资料上显示未经格式化的时间戳记;
-T<数据包类型>:强制将表达方式所指定的数据包转译成设置的数据包类型;
-v:详细显示指令执行过程;
-vv:更详细显示指令执行过程;
-x:用十六进制字码列出数据包资料;
-w<数据包文件>:把数据包数据写入指定的文件。
监控指定网络接口的数据包
[root@localhost ~]# tcpdump -i ens192
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens192, link-type EN10MB (Ethernet), capture size 262144 bytes
10:13:47.908280 IP localhost.localdomain.ssh > 192.168.248.18.53414: Flags [P.], seq 2041358619:2041358783, ack 3277515920, win 281, options [nop,nop,TS val 287603295 ecr 464535749], length 164
10:13:47.909437 IP localhost.localdomain.42944 > pdns.dnspod.cn.domain: 22722+ PTR? 18.248.168.192.in-addr.arpa. (45)
10:13:47.914940 IP 192.168.248.18.53414 > localhost.localdomain.ssh: Flags [.], ack 164, win 2045, options [nop,nop,TS val 464535772 ecr 287603295], length 0
10:13:47.942160 IP pdns.dnspod.cn.domain > localhost.localdomain.42944: 22722 0/0/0 (45)
10:13:47.944626 IP localhost.localdomain.52387 > pdns.dnspod.cn.domain: 11789+ PTR? 15.101.168.192.in-addr.arpa. (45)
10:13:48.159052 ARP, Request who-has 192.168.101.79 tell 192.168.101.17, length 46
10:13:48.385986 IP localhost.localdomain.ssh > 192.168.248.18.53414: Flags [P.], seq 164:232, ack 1, win 281, options [nop,nop,TS val 287603772 ecr 464535772], length 68
10:13:48.386479 IP localhost.localdomain.ssh > 192.168.248.18.53414: Flags [P.], seq 232:268, ack 1, win 281, options [nop,nop,TS val 287603773 ecr 464535772], length 36
10:13:48.391759 IP localhost.localdomain.ssh > 192.168.248.18.53414: Flags [P.], seq 268:320, ack 1, win 281, options [nop,nop,TS val 287603778 ecr 464535772], length 52
10:13:48.394809 IP 192.168.248.18.53414 > localhost.localdomain.ssh: Flags [.], ack 232, win 2046, options [nop,nop,TS val 464536213 ecr 287603772], length 0
10:13:48.394850 IP localhost.localdomain.ssh > 192.168.248.18.53414: Flags [P.], seq 320:460, ack 1, win 281, options [nop,nop,TS val 287603781 ecr 464536213], length 140
10:13:48.395047 IP 192.168.248.18.53414 > localhost.localdomain.ssh: Flags [.], ack 268, win 2047, options [nop,nop,TS val 464536213 ecr 287603773], length 0
...
截获所有112.80.248.75 的主机收到的和发出的所有的数据包
tcpdump host 112.80.248.75