【Linux】Linux中的网络命令

dig命令:是常用的域名查询工具,可以用来测试域名系统工作是否正常。

语法:

dig(选项)(参数)
[root@localhost tmp]# dig http://oa.kingnet.com

; <<>> DiG 9.9.4-RedHat-9.9.4-18.el7 <<>> http://oa.kingnet.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46009
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;http://oa.kingnet.com.         IN      A

;; AUTHORITY SECTION:
kingnet.com.            600     IN      SOA     ns3.dnsv3.com. enterprise1dnsadmin.dnspod.com. 1524116107 3600 180 1209600 180

;; Query time: 5029 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: 日 4月 22 16:18:11 CST 2018
;; MSG SIZE  rcvd: 123

 

curl & wget

curl 的手册,加上 -d 参数后就是 POST 请求了,不是 GET。

 

wget -N 覆盖同名已经存在的文件

 

ping命令常用来测试主机之间网络的连通性。执行ping指令会使用ICMP传输协议,发出要求回应的信息,若远端主机的网络功能没有问题,就会回应该信息,因而得知该主机运作正常。

[root@localhost tmp]# ping www.baidu.com
PING www.a.shifen.com (119.75.213.61) 56(84) bytes of data.
64 bytes from 119.75.213.61: icmp_seq=1 ttl=51 time=41.8 ms
64 bytes from 119.75.213.61: icmp_seq=2 ttl=51 time=56.2 ms

 

host命令

host命令用来做DNS查询。用来测试域名系统工作是否正常.

[root@localhost tmp]# host www.baidu.com
www.baidu.com is an alias for www.a.shifen.com.
www.a.shifen.com has address 119.75.216.20
www.a.shifen.com has address 119.75.213.61

  nslookup命令是常用域名查询工具,就是查DNS信息用的命令。

[root@localhost tmp]# nslookup www.baidu.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 119.75.216.20
Name:   www.a.shifen.com
Address: 119.75.213.61

 

ifconfig  & ifdown & ifup

ifdown和ifup命令和运行ifconfig up,ifconfig down的功能一样。是用于启动或者禁用网卡。

其实这些命令是shell脚本。

[root@localhost ~]# which ifup
/usr/sbin/ifup
您在 /var/spool/mail/root 中有邮件
[root@localhost ~]# file /usr/sbin/ifup
/usr/sbin/ifup: Bourne-Again shell script, ASCII text executable

使用

[root@localhost ~]# ifdown ens33 

或者

[root@localhost ~]# ifconfig ens33  down

不过注意的是ifdown命令禁用网卡的话,是无法登陆虚拟机的,尽量少用。

 

ip命令

  ip命令可以网络配置,路由管理等。以后会替代ifconfig命令。

  如果没用该命令,可以先安装

yum -y install initscripts

   1.列出路由表

[root@e02d387b9271 /]# ip  route  show
default via 192.168.254.1 dev eth0
192.168.254.0/24 dev eth0 proto kernel scope link src 192.168.254.3

   2.显示网卡信息

[root@e02d387b9271 /]# ip addr show eth0
18: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:c0:a8:fe:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.254.3/24 brd 192.168.254.255 scope global eth0
       valid_lft forever preferred_lft forever

 

traceroute命令用于追踪数据包在网络上的传输时的全部路径

[root@localhost ~]# traceroute www.baidu.com
traceroute to www.baidu.com (119.75.213.61), 30 hops max, 60 byte packets
 1  gateway (192.168.1.1)  21.144 ms  20.886 ms  20.678 ms
 2  10.69.96.1 (10.69.96.1)  20.508 ms  20.375 ms  20.242 ms
 3  10.64.131.6 (10.64.131.6)  20.106 ms 10.64.131.14 (10.64.131.14)  19.994 ms                                                                   

 tracepath命令用来追踪并显示报文到达目的主机所经过的路由信息。

[root@localhost ~]# tracepath www.baidu.com
 1?: [LOCALHOST]                                         pmtu 1500
 1:  gateway                                              32.898ms
 1:  gateway                                               3.508ms

 

iftop可以用来监控网卡的实时流量。这个需要安装。

先下载所需依赖

[root@localhost ~]# yum install flex byacc  libpcap ncurses ncurses-devel libpcap-devel

 然后下载源码并安装,分别执行以下几条命令

[root@localhost iftop-0.17]# wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
[root@localhost iftop-0.17]# tar zxvf iftop-0.17.tar.gz
[root@localhost iftop-0.17]# cd iftop-0.17
[root@localhost iftop-0.17]# ./configure
[root@localhost iftop-0.17]# make && make install

查看

[root@localhost iftop-0.17]# which iftop
/usr/local/sbin/iftop

按下iftop命令

参数说明:

  TX:发送流量
  RX:接收流量
  TOTAL:总流量
  Cumm:运行iftop到目前时间的总流量
  peak:流量峰值
  rates:分别表示过去 2s 10s 40s 的平均流量

 

默认情况下,通过POST方式传递过去的数据中若有特殊字符,首先需要将特殊字符转义在传递给服务器端,如value值中包含有空格,则需要先将空格转换成%20,这时候需要 参数d (-d --data 使用POST方法, -d 后面的是post的数据) 如:

1 curl -d "value%201" http://hostname.com

curl -d "{\"cmd\":1,\"record\":{\"id\":\"test11\",\"score\":29.8,\"token\":\"aaa\"}}" http://localhost:3000/leaderboards

通过使用-C选项可对大文件使用断点续传功能 通过添加-C选项继续对该文件进行下载,已经下载过的文件不会被重新下载

-o:将文件保存为命令行中指定的文件名的文件中
-O:使用URL中默认的文件名保存文件到本地。

如果我们只想要显示 HTTP 头,而不显示文件内容,可以使用 -I 选项。

-L:如果直接使用 curl 打开某些被重定向后的链接,这种情况下就无法获取我们想要的网页内容,而当我们通过浏览器打开该链接时,会自动跳转到 http://www.codebelief.com。此时我们想要 curl 做的,就是像浏览器一样跟随链接的跳转,获取最终的网页内容。我们可以在命令中添加 -L 选项来跟随链接重定向。

posted @ 2018-04-22 16:55  songguojun  阅读(282)  评论(0编辑  收藏  举报