Most Common Linux Commands

netcat — a utility that is able to write and read data across TCP and UDP network connections.

  • -v: produce more verbose(冗余的) output
  • -w timeout: connections which cannot be established or are idle timeout after timeout second.
  • -z: only scan for listening daemon, without sending any data to them.
  • -n: do not do any DNS or service lookups on any address, hostname or ports.
  • -l: listen for an incoming connection rather than initiating a connection to a remote host.
  • -k: when a connection is completed, listen for another one.
  • -p source_port: specify the source port nc should use.
  • -u: use UDP instead of TCP.

(1) nc -v -w 2 -z target 22-23: try connecting to every port in [22, 23] at the target

ports scanning

(2) nc -v -n target 443: grab port banners at target:443
grab port banners

(3) nc -l -p 10001: listen for an incoming connection on port 10001.
(4) Transferring files using netcat:

// server
nc -l -p 1234 > filename.txt

// client
nc destination 1234 < filename.txt

wc — print new line, word and byte counts for each file

  • -l: print the new line counts.
  • -w: print the word counts.
  • -m: print the character counts.
  • -c: print the byte counts.

(1) wc file: print number of lines, number of words, number of bytes, filename for file

wc co_routine.cpp

(2) ls -l | wc -l: count the number of files in current directory
count file number

tcpdump — dump traffic on a network

  • -A: print each packet (minus its link level header) in ASCII.
  • -X: print each packet (minus its link level header) in hex and ASCII.
  • -i interface: select interface that the capture is to take place on.
  • -n: don’t convert host addresses to names.
  • -nn: don’t convert protocol and port numbers etc. to names either.
  • -s snaplen: snarf snaplen bytes of data from each packet rather than the default of 65535 bytes.
  • -S: Print absolute, rather than relative, TCP sequence numbers.
  • -v, -vv, -vvv: show more protocol specific information.

pcap-filter — packet filter syntax

  • port port: either the source or destination port of the packet is port.
  • host host: either the source or destination of the packet is host.
  • src host host/src port port: the source of the packet is host/port.
  • dst host host/dst port port: the destination of the packet is host/port.

(1) tcpdump -nn -vv port 80: capture traffic on port 80

Flags are some combination of S(SYN), F(FIN), P(PUSH), R(RST), W(ECN CWR) or E (ECN-Echo), or a single ‘.’ (no flags).

capture port 80

(2) tcpdump -A port 8080:
tcpdump ASCII

(3) tcpdump -A dst port 1234: capture on destination port
capture on destination port

ss -- used to dump socket statistics

  • no option: displays a list of open non-listening sockets(e.g. TCP/UNIX/UDP) that have established connection.
  • -t: Display TCP sockets.
  • -u: Display UDP sockets.
  • -x: Display Unix domain sockets.
  • -a: Display both listening and non-listening (for TCP this means established connections) sockets.
  • -n: Do not try to resolve service names.
  • -l: Display only listening sockets (these are omitted by default).
  • -p: Show the process name/pid which owns the connection.
  • -s: Print summary statistics.
  • -4: Display only IP version 4 sockets
  • -6: Display only IP version 6 sockets
  • [ state TCP-STATE ] [ EXPRESSION ]: Filtering connections by tcp state or EXPRESSION

STATE-FILTER allows to construct arbitrary set of states to match. Its syntax is sequence of keywords state and exclude followed by identifier of state.
Available identifiers are:

  • all standard TCP states: established, syn-sent, syn-recv, fin-wait-1, fin-wait-2, time-wait, closed, close-wait, last-ack, listening and closing.
  • all - for all the states
  • connected - all the states except for listening and closed
  • synchronized - all the connected states except for syn-sent
  • bucket - states, which are maintained as minisockets, i.e. time-wait and syn-recv
  • big - opposite to bucket

(1) ss -tu: filter out tcp and udp connections

ubuntu@VM-100-62-ubuntu:~$ ss -tu
Netid     State       Recv-Q       Send-Q              Local Address:Port                Peer Address:Port       
tcp       ESTAB       0            0                   10.xxx.100.xx:ssh                61.xxx.169.xx:30199      
tcp       ESTAB       0            0                   10.xxx.100.xx:42710             10.xxx.231.xxx:5574       
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末洛二,一起剝皮案震驚了整個濱河市辆床,隨后出現(xiàn)的幾起案子抖格,更是在濱河造成了極大的恐慌,老刑警劉巖钳榨,帶你破解...
    沈念sama閱讀 210,978評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機憨愉,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,954評論 2 384
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來卿捎,“玉大人配紫,你說我怎么就攤上這事〗颗欤” “怎么了笨蚁?”我有些...
    開封第一講書人閱讀 156,623評論 0 345
  • 文/不壞的土叔 我叫張陵睹晒,是天一觀的道長趟庄。 經(jīng)常有香客問我括细,道長,這世上最難降的妖魔是什么戚啥? 我笑而不...
    開封第一講書人閱讀 56,324評論 1 282
  • 正文 為了忘掉前任奋单,我火速辦了婚禮,結(jié)果婚禮上猫十,老公的妹妹穿的比我還像新娘览濒。我一直安慰自己,他們只是感情好拖云,可當我...
    茶點故事閱讀 65,390評論 5 384
  • 文/花漫 我一把揭開白布贷笛。 她就那樣靜靜地躺著,像睡著了一般宙项。 火紅的嫁衣襯著肌膚如雪乏苦。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,741評論 1 289
  • 那天尤筐,我揣著相機與錄音汇荐,去河邊找鬼。 笑死盆繁,一個胖子當著我的面吹牛掀淘,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播油昂,決...
    沈念sama閱讀 38,892評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼革娄,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了冕碟?” 一聲冷哼從身側(cè)響起稠腊,我...
    開封第一講書人閱讀 37,655評論 0 266
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎鸣哀,沒想到半個月后架忌,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,104評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡我衬,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,451評論 2 325
  • 正文 我和宋清朗相戀三年叹放,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片挠羔。...
    茶點故事閱讀 38,569評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡井仰,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出破加,到底是詐尸還是另有隱情俱恶,我是刑警寧澤,帶...
    沈念sama閱讀 34,254評論 4 328
  • 正文 年R本政府宣布,位于F島的核電站合是,受9級特大地震影響了罪,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜聪全,卻給世界環(huán)境...
    茶點故事閱讀 39,834評論 3 312
  • 文/蒙蒙 一泊藕、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧难礼,春花似錦娃圆、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,725評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至谦炬,卻和暖如春吝岭,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背吧寺。 一陣腳步聲響...
    開封第一講書人閱讀 31,950評論 1 264
  • 我被黑心中介騙來泰國打工窜管, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人稚机。 一個月前我還...
    沈念sama閱讀 46,260評論 2 360
  • 正文 我出身青樓幕帆,卻偏偏與公主長得像,于是被迫代替她去往敵國和親赖条。 傳聞我的和親對象是個殘疾皇子失乾,可洞房花燭夜當晚...
    茶點故事閱讀 43,446評論 2 348

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,306評論 0 10
  • =========================================================...
    lavor閱讀 3,484評論 0 5
  • =========================================================...
    _燈火闌珊處閱讀 2,399評論 0 3
  • 僅以此文記念我們一起浪過的歲月 憧憬即將更浪的明天 寢室有四口人?? 首先是天天早起給我們做飯的龔媽媽 我天天賴床...
    Helewise閱讀 644評論 0 0
  • 今天,上午復習了下昨天的單詞纬乍。 然后背誦了list 3的單詞碱茁。 沒有背list 4 被拉去上班了。 然后吃了自助餐...
    伊家閱讀 388評論 0 0