网络命令

nc
  • 帮助
  1. root@ubuntu:~# nc -h
  2. OpenBSD netcat (Debian patchlevel 1.105-7ubuntu1)
  3. This is nc from the netcat-openbsd package. An alternative nc is available
  4. in the netcat-traditional package.
  5. usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]
  6. [-P proxy_username] [-p source_port] [-q seconds] [-s source]
  7. [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]
  8. [-x proxy_address[:port]] [destination] [port]
  9. Command Summary:
  10. -4 Use IPv4
  11. -6 Use IPv6
  12. -b Allow broadcast
  13. -C Send CRLF as line-ending
  14. -D Enable the debug socket option
  15. -d Detach from stdin
  16. -h This help text
  17. -I length TCP receive buffer length
  18. -i secs Delay interval for lines sent, ports scanned
  19. -j Use jumbo frame
  20. -k Keep inbound sockets open for multiple connects
  21. -l Listen mode, for inbound connects
  22. -n Suppress name/port resolutions
  23. -O length TCP send buffer length
  24. -P proxyuser Username for proxy authentication
  25. -p port Specify local port for remote connects
  26. -q secs quit after EOF on stdin and delay of secs
  27. -r Randomize remote ports
  28. -S Enable the TCP MD5 signature option
  29. -s addr Local source address
  30. -T toskeyword Set IP Type of Service
  31. -t Answer TELNET negotiation
  32. -U Use UNIX domain socket
  33. -u UDP mode
  34. -V rtable Specify alternate routing table
  35. -v Verbose
  36. -w secs Timeout for connects and final net reads
  37. -X proto Proxy protocol: "4", "5" (SOCKS) or "connect"
  38. -x addr[:port] Specify proxy address and port
  39. -Z DCCP mode
  40. -z Zero-I/O mode [used for scanning]
  41. Port numbers can be individual or ranges: lo-hi [inclusive]
  • 常用参数
  1. # -l 监听
  2. # -p 端口号
  3. # -v 显示指令执行过程
  4. # -t 模拟telnet客户端
  5. # -x 使用代理服务器连接
  6. #
  • 常用命令
  1. # 监听8888端口
  2. nc -l -p 8888
  3. # 连接本机8888端口
  4. nc 127.0.0.1 8888
  5. # 查看连接本机8888端口详情 -v 查看指令执行过程
  6. nc -v 127.0.0.1 8888
  7. # 扫描本机1-65535端口情况,只显示打开的端口
  8. nc -w 1 -z 127.0.0.1 1-65535
  9. # 模拟telnet客户端
  10. nc -t 127.0.0.1 8888

curl
  • 帮助
  1. root@ubuntu:~# curl -h
  2. Usage: curl [options...] <url>
  3. Options: (H) means HTTP/HTTPS only, (F) means FTP only
  4. --anyauth Pick "any" authentication method (H)
  5. -a, --append Append to target file when uploading (F/SFTP)
  6. --basic Use HTTP Basic Authentication (H)
  7. --cacert FILE CA certificate to verify peer against (SSL)
  8. --capath DIR CA directory to verify peer against (SSL)
  9. -E, --cert CERT[:PASSWD] Client certificate file and password (SSL)
  10. --cert-status Verify the status of the server certificate (SSL)
  11. --cert-type TYPE Certificate file type (DER/PEM/ENG) (SSL)
  12. --ciphers LIST SSL ciphers to use (SSL)
  13. --compressed Request compressed response (using deflate or gzip)
  14. -K, --config FILE Read config from FILE
  15. --connect-timeout SECONDS Maximum time allowed for connection
  16. -C, --continue-at OFFSET Resumed transfer OFFSET
  17. -b, --cookie STRING/FILE Read cookies from STRING/FILE (H)
  18. -c, --cookie-jar FILE Write cookies to FILE after operation (H)
  19. --create-dirs Create necessary local directory hierarchy
  20. --crlf Convert LF to CRLF in upload
  21. --crlfile FILE Get a CRL list in PEM format from the given file
  22. -d, --data DATA HTTP POST data (H)
  23. --data-raw DATA HTTP POST data, '@' allowed (H)
  24. --data-ascii DATA HTTP POST ASCII data (H)
  25. --data-binary DATA HTTP POST binary data (H)
  26. --data-urlencode DATA HTTP POST data url encoded (H)
  27. --delegation STRING GSS-API delegation permission
  28. --digest Use HTTP Digest Authentication (H)
  29. --disable-eprt Inhibit using EPRT or LPRT (F)
  30. --disable-epsv Inhibit using EPSV (F)
  31. --dns-servers DNS server addrs to use: 1.1.1.1;2.2.2.2
  32. --dns-interface Interface to use for DNS requests
  33. --dns-ipv4-addr IPv4 address to use for DNS requests, dot notation
  34. --dns-ipv6-addr IPv6 address to use for DNS requests, dot notation
  35. -D, --dump-header FILE Write the headers to FILE
  36. --egd-file FILE EGD socket path for random data (SSL)
  37. --engine ENGINE Crypto engine (use "--engine list" for list) (SSL)
  38. --expect100-timeout SECONDS How long to wait for 100-continue (H)
  39. -f, --fail Fail silently (no output at all) on HTTP errors (H)
  40. --false-start Enable TLS False Start.
  41. -F, --form CONTENT Specify HTTP multipart POST data (H)
  42. --form-string STRING Specify HTTP multipart POST data (H)
  43. --ftp-account DATA Account data string (F)
  44. --ftp-alternative-to-user COMMAND String to replace "USER [name]" (F)
  45. --ftp-create-dirs Create the remote dirs if not present (F)
  46. --ftp-method [MULTICWD/NOCWD/SINGLECWD] Control CWD usage (F)
  47. --ftp-pasv Use PASV/EPSV instead of PORT (F)
  48. -P, --ftp-port ADR Use PORT with given address instead of PASV (F)
  49. --ftp-skip-pasv-ip Skip the IP address for PASV (F)
  50. --ftp-pret Send PRET before PASV (for drftpd) (F)
  51. --ftp-ssl-ccc Send CCC after authenticating (F)
  52. --ftp-ssl-ccc-mode ACTIVE/PASSIVE Set CCC mode (F)
  53. --ftp-ssl-control Require SSL/TLS for FTP login, clear for transfer (F)
  54. -G, --get Send the -d data with a HTTP GET (H)
  55. -g, --globoff Disable URL sequences and ranges using {} and []
  56. -H, --header LINE Pass custom header LINE to server (H)
  57. -I, --head Show document info only
  58. -h, --help This help text
  59. --hostpubmd5 MD5 Hex-encoded MD5 string of the host public key. (SSH)
  60. -0, --http1.0 Use HTTP 1.0 (H)
  61. --http1.1 Use HTTP 1.1 (H)
  62. --http2 Use HTTP 2 (H)
  63. --ignore-content-length Ignore the HTTP Content-Length header
  64. -i, --include Include protocol headers in the output (H/F)
  65. -k, --insecure Allow connections to SSL sites without certs (H)
  66. --interface INTERFACE Use network INTERFACE (or address)
  67. -4, --ipv4 Resolve name to IPv4 address
  68. -6, --ipv6 Resolve name to IPv6 address
  69. -j, --junk-session-cookies Ignore session cookies read from file (H)
  70. --keepalive-time SECONDS Wait SECONDS between keepalive probes
  71. --key KEY Private key file name (SSL/SSH)
  72. --key-type TYPE Private key file type (DER/PEM/ENG) (SSL)
  73. --krb LEVEL Enable Kerberos with security LEVEL (F)
  74. --libcurl FILE Dump libcurl equivalent code of this command line
  75. --limit-rate RATE Limit transfer speed to RATE
  76. -l, --list-only List only mode (F/POP3)
  77. --local-port RANGE Force use of RANGE for local port numbers
  78. -L, --location Follow redirects (H)
  79. --location-trusted Like '--location', and send auth to other hosts (H)
  80. --login-options OPTIONS Server login options (IMAP, POP3, SMTP)
  81. -M, --manual Display the full manual
  82. --mail-from FROM Mail from this address (SMTP)
  83. --mail-rcpt TO Mail to this/these addresses (SMTP)
  84. --mail-auth AUTH Originator address of the original email (SMTP)
  85. --max-filesize BYTES Maximum file size to download (H/F)
  86. --max-redirs NUM Maximum number of redirects allowed (H)
  87. -m, --max-time SECONDS Maximum time allowed for the transfer
  88. --metalink Process given URLs as metalink XML file
  89. --negotiate Use HTTP Negotiate (SPNEGO) authentication (H)
  90. -n, --netrc Must read .netrc for user name and password
  91. --netrc-optional Use either .netrc or URL; overrides -n
  92. --netrc-file FILE Specify FILE for netrc
  93. -:, --next Allows the following URL to use a separate set of options
  94. --no-alpn Disable the ALPN TLS extension (H)
  95. -N, --no-buffer Disable buffering of the output stream
  96. --no-keepalive Disable keepalive use on the connection
  97. --no-npn Disable the NPN TLS extension (H)
  98. --no-sessionid Disable SSL session-ID reusing (SSL)
  99. --noproxy List of hosts which do not use proxy
  100. --ntlm Use HTTP NTLM authentication (H)
  101. --oauth2-bearer TOKEN OAuth 2 Bearer Token (IMAP, POP3, SMTP)
  102. -o, --output FILE Write to FILE instead of stdout
  103. --pass PASS Pass phrase for the private key (SSL/SSH)
  104. --path-as-is Do not squash .. sequences in URL path
  105. --pinnedpubkey FILE/HASHES Public key to verify peer against (SSL)
  106. --post301 Do not switch to GET after following a 301 redirect (H)
  107. --post302 Do not switch to GET after following a 302 redirect (H)
  108. --post303 Do not switch to GET after following a 303 redirect (H)
  109. -#, --progress-bar Display transfer progress as a progress bar
  110. --proto PROTOCOLS Enable/disable PROTOCOLS
  111. --proto-default PROTOCOL Use PROTOCOL for any URL missing a scheme
  112. --proto-redir PROTOCOLS Enable/disable PROTOCOLS on redirect
  113. -x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port
  114. --proxy-anyauth Pick "any" proxy authentication method (H)
  115. --proxy-basic Use Basic authentication on the proxy (H)
  116. --proxy-digest Use Digest authentication on the proxy (H)
  117. --proxy-negotiate Use HTTP Negotiate (SPNEGO) authentication on the proxy (H)
  118. --proxy-ntlm Use NTLM authentication on the proxy (H)
  119. --proxy-service-name NAME SPNEGO proxy service name
  120. --service-name NAME SPNEGO service name
  121. -U, --proxy-user USER[:PASSWORD] Proxy user and password
  122. --proxy1.0 HOST[:PORT] Use HTTP/1.0 proxy on given port
  123. -p, --proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)
  124. --pubkey KEY Public key file name (SSH)
  125. -Q, --quote CMD Send command(s) to server before transfer (F/SFTP)
  126. --random-file FILE File for reading random data from (SSL)
  127. -r, --range RANGE Retrieve only the bytes within RANGE
  128. --raw Do HTTP "raw"; no transfer decoding (H)
  129. -e, --referer Referer URL (H)
  130. -J, --remote-header-name Use the header-provided filename (H)
  131. -O, --remote-name Write output to a file named as the remote file
  132. --remote-name-all Use the remote file name for all URLs
  133. -R, --remote-time Set the remote file's time on the local output
  134. -X, --request COMMAND Specify request command to use
  135. --resolve HOST:PORT:ADDRESS Force resolve of HOST:PORT to ADDRESS
  136. --retry NUM Retry request NUM times if transient problems occur
  137. --retry-delay SECONDS Wait SECONDS between retries
  138. --retry-max-time SECONDS Retry only within this period
  139. --sasl-ir Enable initial response in SASL authentication
  140. -S, --show-error Show error. With -s, make curl show errors when they occur
  141. -s, --silent Silent mode (don't output anything)
  142. --socks4 HOST[:PORT] SOCKS4 proxy on given host + port
  143. --socks4a HOST[:PORT] SOCKS4a proxy on given host + port
  144. --socks5 HOST[:PORT] SOCKS5 proxy on given host + port
  145. --socks5-hostname HOST[:PORT] SOCKS5 proxy, pass host name to proxy
  146. --socks5-gssapi-service NAME SOCKS5 proxy service name for GSS-API
  147. --socks5-gssapi-nec Compatibility with NEC SOCKS5 server
  148. -Y, --speed-limit RATE Stop transfers below RATE for 'speed-time' secs
  149. -y, --speed-time SECONDS Trigger 'speed-limit' abort after SECONDS (default: 30)
  150. --ssl Try SSL/TLS (FTP, IMAP, POP3, SMTP)
  151. --ssl-reqd Require SSL/TLS (FTP, IMAP, POP3, SMTP)
  152. -2, --sslv2 Use SSLv2 (SSL)
  153. -3, --sslv3 Use SSLv3 (SSL)
  154. --ssl-allow-beast Allow security flaw to improve interop (SSL)
  155. --ssl-no-revoke Disable cert revocation checks (WinSSL)
  156. --stderr FILE Where to redirect stderr (use "-" for stdout)
  157. --tcp-nodelay Use the TCP_NODELAY option
  158. -t, --telnet-option OPT=VAL Set telnet option
  159. --tftp-blksize VALUE Set TFTP BLKSIZE option (must be >512)
  160. -z, --time-cond TIME Transfer based on a time condition
  161. -1, --tlsv1 Use >= TLSv1 (SSL)
  162. --tlsv1.0 Use TLSv1.0 (SSL)
  163. --tlsv1.1 Use TLSv1.1 (SSL)
  164. --tlsv1.2 Use TLSv1.2 (SSL)
  165. --trace FILE Write a debug trace to FILE
  166. --trace-ascii FILE Like --trace, but without hex output
  167. --trace-time Add time stamps to trace/verbose output
  168. --tr-encoding Request compressed transfer encoding (H)
  169. -T, --upload-file FILE Transfer FILE to destination
  170. --url URL URL to work with
  171. -B, --use-ascii Use ASCII/text transfer
  172. -u, --user USER[:PASSWORD] Server user and password
  173. --tlsuser USER TLS username
  174. --tlspassword STRING TLS password
  175. --tlsauthtype STRING TLS authentication type (default: SRP)
  176. --unix-socket FILE Connect through this Unix domain socket
  177. -A, --user-agent STRING Send User-Agent STRING to server (H)
  178. -v, --verbose Make the operation more talkative
  179. -V, --version Show version number and quit
  180. -w, --write-out FORMAT Use output FORMAT after completion
  181. --xattr Store metadata in extended file attributes
  182. -q Disable .curlrc (must be first parameter)

route
  • 帮助
root@ubuntu:~# route -h
Usage: route [-nNvee] [-FC] [<AF>]           List kernel routing tables
       route [-v] [-FC] {add|del|flush} ...  Modify routing table for AF.

       route {-h|--help} [<AF>]              Detailed usage syntax for specified AF.
       route {-V|--version}                  Display version/author and exit.

        -v, --verbose            be verbose
        -n, --numeric            don't resolve names
        -e, --extend             display other/more information
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB

  <AF>=Use '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) 
    x25 (CCITT X.25)

chkconfig
chkconfig -list  查看开机自启动项

文本查看命令

cat

tail

grep
  • grep -v grep 忽略grep
  • grep是一个文本搜索工具,用来查找文本
# 从文件中逐行匹配,如果发现有 12345 则会输出
grep '12345' catalina.out
# 从文件中逐行匹配,如果发现有 12345 则会输出该行上下30行日志,类似的还有 -B(before) 和-A(after),代表输出之前行和之后行。
grep '12345' -C 30 catalina.out
# 因为grep一次只能匹配一种关键字,可以使用正则,也可以使用管道进行多次匹配,下面命令代表从匹配 12345 的行中再过滤出有6789的行。
grep '12345' catalina.out | grep '6789'

awk
  • awk是一个文本分析工具,用来解析文本
# 示例

# 以空格为分隔符获取第0列
awk '{printf $0}'

# 以:为分隔符获取第1列
awk -F ':' '{printf $1}'

# 根据端口号获得进程号
netstat -tlnp | grep 9999 | awk '{printf $7}' | awk -F '/' '{printf $1}'

sed
  • 功能:拼接,删除,替换,字符串

wc
# 统计行数
wc -l

traceroute
  • 功能:追踪网络数据包的路由途径
  • 原理:程序利用增加存活时间(TTL)值来实现其功能。每当数据包经过一个路由器,其存活时间就会减1。当其存活时间是0时,主机便取消数据包,并传送一个ICMP TTL数据包给原数据包的发出者。
    程序发出的首3个数据包TTL值是1,之后3个是2,如此类推,它便得到一连串数据包路径。注意IP不保证每个数据包走的路径都一样。
traceroute[参数][主机]

系统监控命令

ps
  • 查看系统实时状态

pstree
  • pstree查看进程树
  • pstree -p $PID 查看某进程ID的线程信息

df
  • 查看磁盘空间

du
  • du -ach * 查看当前目录下的所有文件占用磁盘大小和总大小
  • du -sh 查看当前目录的占用空间大小
  • du -sh * 查看所有子目录大小

lsof
  • 查看系统所有打开的文件,由于linux一切皆文件的思想,可以查看很多系统状态
[root@localhost ~]# lsof -h
lsof 4.78
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhlnNoOPRstUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]]
 [-p s] [+|-r [t]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [-Z [Z]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
  -c c  cmd c, /c/[bix]    +c w  COMMAND width (9)     
  +d s  dir s files        -d s  select by FD set     +D D  dir D tree *SLOW?*
                           +|-e s  exempt s *RISKY*   -i select IPv[46] files
  -l list UID numbers      -n no host names           -N select NFS files
  -o list file offset      -O avoid overhead *RISKY*  -P no port names
  -R list paRent PID       -s list file size          -t terse listing
  -T disable TCP/TPI info  -U select Unix socket      -v list version info
  -V verbose search        +|-w  Warnings (+)         -X skip TCP&UDP files
  -Z Z  context [Z]
  -- end option scan
  +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
  -F [f] select fields; -F? for help  
  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                        +m [m] use|create mount supplement
  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
  -T qs TCP/TPI Q,St (s) info
  -g [s] exclude(^)|select and print process group IDs
  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
  +|-r [t] repeat every t seconds (15); + until no files, - forever
  -u s   exclude(^)|select login|UID set s
  -x [fl] cross over +d|+D File systems or symbolic Links
  names  select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.

netstat
# netstat -h
usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vnNcaeol] [<Socket> ...]
       netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay]

        -r, --route                display routing table
        -I, --interfaces=[<Iface>] display interface table for <Iface>
        -i, --interfaces           display interface table
        -g, --groups               display multicast group memberships
        -s, --statistics           display networking statistics (like SNMP)
        -M, --masquerade           display masqueraded connections

        -v, --verbose              be verbose
        -n, --numeric              don't resolve names
        --numeric-hosts            don't resolve host names
        --numeric-ports            don't resolve port names
        --numeric-users            don't resolve user names
        -N, --symbolic             resolve hardware names
        -e, --extend               display other/more information
        -p, --programs             display PID/Program name for sockets
        -c, --continuous           continuous listing

        -l, --listening            display listening server sockets
        -a, --all, --listening     display all sockets (default: connected)
        -o, --timers               display timers
        -F, --fib                  display Forwarding Information Base (default)
        -C, --cache                display routing cache instead of FIB
        -T, --notrim               stop trimming long addresses
        -Z, --context              display SELinux security context for sockets

  <Iface>: Name of interface to monitor/list.
  <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
  <AF>=Use '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) 
    x25 (CCITT X.25)
查看链接状态 ESTABLISHED CLOSE_WAIT TIME_WAIT ,其中服务端不应出现过多CLOSE_WAIT
netstat -an