#遇到一条很长的命令怎么办,想换行的时候在末尾增加\符号就可以换行继续输入命令了
#在ifconfig内容中找出ip
[root@bogon ~]# ifconfig ens33|grep "inet "\
> |awk '{print $2}' #awk默认分割符号为空格
192.168.1.107
[root@bogon ~]# ifconfig ens33|grep "inet "|awk '{print $2}'
192.168.1.107
[root@bogon ~]#
#ping都懂用,可是linux下,ping命令会一直ping,不会自动停止怎么办
[root@bogon ~]# ping www.baidu.com -c 4 #-c 次数
PING www.a.shifen.com (112.80.248.73) 56(84) bytes of data.
64 bytes from 112.80.248.73 (112.80.248.73): icmp_seq=1 ttl=54 time=29.0 ms
64 bytes from 112.80.248.73 (112.80.248.73): icmp_seq=2 ttl=54 time=29.2 ms
64 bytes from 112.80.248.73 (112.80.248.73): icmp_seq=3 ttl=54 time=29.0 ms
64 bytes from 112.80.248.73 (112.80.248.73): icmp_seq=4 ttl=54 time=29.3 ms
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 29.050/29.171/29.370/0.215 ms
[root@bogon ~]#
[root@bogon ~]# netstat -an|grep -v unix #显示网络连接信息,-a所有,-n实际地址 |grep -v 晓得吧,就是反向显示(不显示符合条件)的意思了
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.107:22 192.168.1.100:53436 ESTABLISHED
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:32571 0.0.0.0:*
udp 0 0 127.0.0.1:323 0.0.0.0:*
udp 0 0 0.0.0.0:48503 0.0.0.0:*
udp 0 0 192.168.122.1:53 0.0.0.0:*
udp 0 0 0.0.0.0:67 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:69 0.0.0.0:*
udp6 0 0 ::1:323 :::*
udp6 0 0 :::30378 :::*
raw6 0 0 :::58 :::* 7
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
[root@bogon ~]#
#查看网络连接状态,并汇总信息
[root@bogon ~]# netstat -an|grep tcp
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.107:22 192.168.1.100:53436 ESTABLISHED
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
[root@bogon ~]# netstat -an|grep tcp|awk '{++S[$NF]} END {for (a in S) print a,S[a]}'
LISTEN 9
ESTABLISHED 1
[root@bogon ~]# netstat -an|awk '/^tcp/{++S[$NF]} END {for (a in S) print a,S[a]}' #写法有很多种
LISTEN 9
ESTABLISHED 1
[root@bogon ~]#
#查看系统路由表,两种方法
[root@bogon ~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 ens33
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@bogon ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default bogon 0.0.0.0 UG 0 0 0 ens33
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@bogon ~]#
#追踪网络数据包的路径,经过的路由
[root@bogon ~]# traceroute www.12306.com
效果略
#根据域名查ip
[root@bogon ~]# nslookup www.baidu.com
Server: 58.20.127.238
Address: 58.20.127.238#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 112.80.248.74
Name: www.a.shifen.com
Address: 112.80.248.73
#可以使用dig命令,查看NS(域名服务器)记录
[root@bogon ~]# dig www.taobao.com
; <<>> DiG 9.9.4-RedHat-9.9.4-37.el7 <<>> www.taobao.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6829
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.taobao.com. IN A
;; ANSWER SECTION:
www.taobao.com. 392 IN CNAME www.taobao.com.danuoyi.tbcache.com.
www.taobao.com.danuoyi.tbcache.com. 48 IN A 113.57.228.95
;; Query time: 2 msec
;; SERVER: 58.20.127.238#53(58.20.127.238)
;; WHEN: Mon Jun 26 01:50:56 PDT 2017
;; MSG SIZE rcvd: 104
[root@bogon ~]#
#从根服务器开始追踪域名解析过程
[root@bogon ~]# dig www.yahoo.com + trace
;; Invalid option
; <<>> DiG 9.9.4-RedHat-9.9.4-37.el7 <<>> www.yahoo.com + trace
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10260
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.yahoo.com. IN A
;; ANSWER SECTION:
www.yahoo.com. 592 IN CNAME atsv2-fp.wg1.b.yahoo.com.
atsv2-fp.wg1.b.yahoo.com. 34 IN A 106.10.178.37
atsv2-fp.wg1.b.yahoo.com. 34 IN A 106.10.178.36
;; Query time: 1 msec
;; SERVER: 58.20.127.238#53(58.20.127.238)
;; WHEN: Mon Jun 26 01:55:09 PDT 2017
;; MSG SIZE rcvd: 103
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22596
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;trace. IN A
;; ANSWER SECTION:
trace. 3600 IN A 110.52.11.56
;; AUTHORITY SECTION:
. 48 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2017062600 1800 900 604800 86400
;; Query time: 1 msec
;; SERVER: 58.20.127.238#53(58.20.127.238)
;; WHEN: Mon Jun 26 01:55:09 PDT 2017
;; MSG SIZE rcvd: 125
[root@bogon ~]#
随后我会写上如何搭建简单的网络环境的教程