命令行学习笔记(网络相关)

  • ping host -- 测试目标主机是否连通

效果如下:

➜  anyang ping www.baidu.com
PING www.a.shifen.com (119.75.217.109) 56(84) bytes of data.
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=1 ttl=52 time=32.1 ms
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=2 ttl=52 time=31.1 ms
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=3 ttl=52 time=64.4 ms
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=4 ttl=52 time=45.0 ms
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=5 ttl=52 time=63.9 ms
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=6 ttl=52 time=25.4 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5001ms
rtt min/avg/max/mdev = 25.419/43.695/64.408/15.620 ms
  • whois domain -- 查看域名的详细信息

效果如下:

➜  anyang whois jianshu.com
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
   Domain Name: JIANSHU.COM
   Registrar: NAME.COM, INC.
   Sponsoring Registrar IANA ID: 625
   Whois Server: whois.name.com
   Referral URL: http://www.name.com
   Name Server: F1G1NS1.DNSPOD.NET
   Name Server: F1G1NS2.DNSPOD.NET
   Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
   Updated Date: 06-apr-2016
   Creation Date: 20-mar-2008
   Expiration Date: 20-mar-2020
  • dig domain -- 域名解析(将域名映射到地址)
  • dig -x host -- 逆向查询(将地址映射到域名)

效果如下:

➜  anyang dig jianshu.com
; <<>> DiG 9.10.3-P4-Ubuntu <<>> jianshu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64332
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;jianshu.com.           IN  A
;; ANSWER SECTION:
jianshu.com.        600 IN  A   106.75.2.241
;; Query time: 144 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Dec 07 17:50:26 CST 2016
;; MSG SIZE  rcvd: 56
➜  anyang dig -x 202.200.112.200
; <<>> DiG 9.10.3-P4-Ubuntu <<>> -x 202.200.112.200
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2080
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;200.112.200.202.in-addr.arpa.  IN  PTR
;; ANSWER SECTION:
200.112.200.202.in-addr.arpa. 3600 IN   PTR xfz.xaut.cn.
200.112.200.202.in-addr.arpa. 3600 IN   PTR xfz.xaut.edu.cn.
;; Query time: 115 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Dec 07 17:55:59 CST 2016
;; MSG SIZE  rcvd: 109
  • wget file -- 下载文件
  • wget -c file -- 断点续传
  • wget -r url -- 递归下载文件

效果如下:

➜  anyang wget http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
--2016-12-07 18:11:35--  http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
Resolving cn.wordpress.org (cn.wordpress.org)... 66.155.40.250, 66.155.40.249
Connecting to cn.wordpress.org (cn.wordpress.org)|66.155.40.250|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://cn.wordpress.org/wordpress-3.1-zh_CN.zip [following]
--2016-12-07 18:11:37--  https://cn.wordpress.org/wordpress-3.1-zh_CN.zip
Connecting to cn.wordpress.org (cn.wordpress.org)|66.155.40.250|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3448957 (3.3M) [application/zip]
Saving to: ‘wordpress-3.1-zh_CN.zip’
wordpress-3.1-zh_CN   7%[>                   ] 244.22K  31.1KB/s    eta 1m 45s ^C
➜  anyang wget -c http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
--2016-12-07 18:11:59--  http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
Resolving cn.wordpress.org (cn.wordpress.org)... 66.155.40.250, 66.155.40.249
Connecting to cn.wordpress.org (cn.wordpress.org)|66.155.40.250|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://cn.wordpress.org/wordpress-3.1-zh_CN.zip [following]
--2016-12-07 18:12:01--  https://cn.wordpress.org/wordpress-3.1-zh_CN.zip
Connecting to cn.wordpress.org (cn.wordpress.org)|66.155.40.250|:443... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 3448957 (3.3M), 3194644 (3.0M) remaining [application/zip]
Saving to: ‘wordpress-3.1-zh_CN.zip’
wordpress-3.1-zh_CN 100%[+==================>]   3.29M   198KB/s    in 12s     
2016-12-07 18:12:16 (268 KB/s) - ‘wordpress-3.1-zh_CN.zip’ saved [3448957/3448957]
➜  anyang ls
file1  learngit  test  wordpress-3.1-zh_CN.zip
  • telnet host -- 远程登录
  • curl url -- 通过 url 语法在命令行下上传或下载文件
  • netstat -- 显示各种网络相关的信息
  • netstat -a -- 显示所有端口
  • netstat -at -- 显示所有 tcp 端口
  • netstat -au -- 显示所有 udp 端口

效果如下:

➜  anyang 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:hostmon         0.0.0.0:*               LISTEN     
tcp        0      0 anyang:domain           0.0.0.0:*               LISTEN     
tcp        0      0 localhost:domain        0.0.0.0:*               LISTEN     
tcp        0      0 localhost:ipp           0.0.0.0:*               LISTEN     
tcp        0      0 anyang:50716            140.205.172.5:https     TIME_WAIT  
tcp        0      0 anyang:38262            119.167.151.130:http    TIME_WAIT  
tcp        0      0 anyang:59446            113.200.101.240:https   TIME_WAIT  
tcp        0      0 anyang:48646            106.75.2.241:http       ESTABLISHED
tcp        0      0 anyang:56038            123.138.46.49:https     TIME_WAIT  
tcp        0      0 anyang:53002            linux.cn:https          TIME_WAIT  
tcp        0      0 anyang:35568            123.138.46.32:https     TIME_WAIT  
tcp        0      0 anyang:37560            ec2-54-222-216-13:https ESTABLISHED
tcp        0      0 anyang:57712            hn.kd.ny.adsl:https     TIME_WAIT  
tcp        0      0 anyang:34666            123.138.46.33:https     TIME_WAIT  
tcp6       0      0 [::]:hostmon            [::]:*                  LISTEN     
tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN     
➜  anyang 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:51767           0.0.0.0:*                          
udp        0      0 0.0.0.0:ipp             0.0.0.0:*                          
udp        0      0 0.0.0.0:mdns            0.0.0.0:*                          
udp        0      0 0.0.0.0:hostmon         0.0.0.0:*                          
udp        0      0 anyang:domain           0.0.0.0:*                          
udp        0      0 localhost:domain        0.0.0.0:*                          
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                          
udp        0      0 0.0.0.0:59548           0.0.0.0:*                          
udp6       0      0 [::]:mdns               [::]:*                             
udp6       0      0 [::]:hostmon            [::]:*                             
udp6       0      0 [::]:40747              [::]:* 

相关资料:

  1. 29个你必须知道的Linux命令: http://www.imooc.com/article/1285
  2. 常用命令行介绍: https://github.com/iamcoach/console/blob/master/COMMANDS.md
  3. 常用命令行cheet sheet: https://bbs.excellence-girls.org/topic/167
  4. 书籍《鸟哥的Linux私房菜》: https://book.douban.com/subject/4889838/
  5. Ubuntu各种技巧:http://wiki.ubuntu.org.cn/UbuntuSkills
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335

推荐阅读更多精彩内容

  • 学习内容 网络相关:ping, telnet, curl, netstat,修改hosts 个人总结 ping简述...
    z嘉嘉嘉阅读 1,368评论 0 1
  • 本文整理了在实践过程中使用的Linux网络工具,这些工具提供的功能非常强大,我们平时使用的只是冰山一角,比如lso...
    老夫刘某阅读 3,470评论 0 7
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,497评论 18 139
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 12,112评论 2 34
  • 1. 概述 在网络环境中一般用户只需要在浏览器中输入url如www.sunny.com就可以到对应服务器获取相应的...
    ghbsunny阅读 2,826评论 0 7