Skip to content

Commit 516173e

Browse files
author
JerryZhang
committed
Merge branch 'master' of https://github.com/linuxwiki/SourceWiki
2 parents 00d5e01 + b87d7ff commit 516173e

File tree

4 files changed

+299
-10
lines changed

4 files changed

+299
-10
lines changed

NetTools/dig.md

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,178 @@
1-
COMING SOON ......
1+
# DNS 查询工具 -- dig|host|nslookup
2+
3+
`nslookup``host``dig` 是三个DNS查询工具,以下会分别介绍它们的使用方法。
4+
5+
## 一、nslookup
6+
7+
>nslookup is a tried and true program that has weathered the ages. nslookup has been deprecated and may be removed from future releases. There is not even a man page for this program.
8+
9+
因此,这里不过多介绍。
10+
11+
## 二、host
12+
13+
`host`命令和`dig`命令很相像,但是`host`命令的输出要更简洁,如下示例
14+
15+
``` bash
16+
# host www.google.com
17+
www.google.com has address 74.125.135.106
18+
```
19+
20+
`host`命令只输出给我们`dig`命令的ANSWER section,相对`dig`提供的一些不必要的信息来说更简洁快速。也可指定DNS Server来查询,例如我想使用Google DNS`8.8.8.8`,named可以如下指定
21+
22+
``` bash
23+
# host www.google.com 8.8.8.8
24+
Using domain server:
25+
Name: 8.8.8.8
26+
Address: 8.8.8.8#53
27+
Aliases:
28+
29+
www.google.com has address 173.194.72.147
30+
```
31+
32+
`host`当然也支持反解析
33+
34+
``` bash
35+
# host 173.194.72.147
36+
147.72.194.173.in-addr.arpa domain name pointer tf-in-f147.1e100.net.
37+
```
38+
39+
指定查询类型可以使用`-t`选项
40+
41+
``` bash
42+
# host -t SOA google.com #查询SOA记录信息
43+
google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300
44+
```
45+
46+
查询`MX`记录
47+
48+
```
49+
$ host -t MX google.com
50+
google.com mail is handled by 10 aspmx.l.google.com.
51+
google.com mail is handled by 40 alt3.aspmx.l.google.com.
52+
google.com mail is handled by 20 alt1.aspmx.l.google.com.
53+
google.com mail is handled by 50 alt4.aspmx.l.google.com.
54+
google.com mail is handled by 30 alt2.aspmx.l.google.com.
55+
```
56+
57+
`-C`对比认证DNS SOA信息
58+
59+
```
60+
# host -C google.com
61+
Nameserver 216.239.34.10:
62+
google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300
63+
Nameserver 216.239.36.10:
64+
google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300
65+
Nameserver 216.239.32.10:
66+
... ...
67+
```
68+
69+
查询DNS Server软件版本信息,10.10.10.2为DNS Server
70+
71+
``` bash
72+
# host -c CH -t txt version.bind 10.10.10.2
73+
Using domain server:
74+
Name: 10.10.10.2
75+
Address: 10.10.10.2#53
76+
Aliases:
77+
78+
version.bind descriptive text "9.8.1-P2"
79+
```
80+
81+
__host帮助__
82+
83+
``` bash
84+
# host
85+
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
86+
[-R number] [-m flag] hostname [server]
87+
-a is equivalent to -v -t ANY
88+
-c specifies query class for non-IN data 搜索非网络数据时要指定要查找的类
89+
-C compares SOA records on authoritative nameservers
90+
-d is equivalent to -v
91+
-l lists all hosts in a domain, using AXFR
92+
-i IP6.INT reverse lookups
93+
-N changes the number of dots allowed before root lookup is done
94+
-r disables recursive processing
95+
-R specifies number of retries for UDP packets
96+
-s a SERVFAIL response should stop query
97+
-t specifies the query type 指定要查询的记录类型
98+
-T enables TCP/IP mode
99+
-v enables verbose output 输出更详细的信息
100+
-w specifies to wait forever for a reply
101+
-W specifies how long to wait for a reply
102+
-4 use IPv4 query transport only
103+
-6 use IPv6 query transport only
104+
-m set memory debugging flag (trace|record|usage)
105+
```
106+
107+
## 三、dig
108+
109+
dig也是一个很强大的命令,相对host来说输出较为繁杂,如下:
110+
111+
``` bash
112+
$ dig www.google.com
113+
... ...
114+
115+
;; ANSWER SECTION:
116+
www.google.com. 297 IN A 74.125.135.106
117+
www.google.com. 297 IN A 74.125.135.104
118+
... ...
119+
120+
;; AUTHORITY SECTION:
121+
google.com. 172796 IN NS ns3.google.com.
122+
google.com. 172796 IN NS ns1.google.com.
123+
google.com. 172796 IN NS ns4.google.com.
124+
google.com. 172796 IN NS ns2.google.com.
125+
126+
... ...
127+
```
128+
129+
查询`MX`记录
130+
131+
``` bash
132+
$ dig google.com MX | grep '^;; ANSWER SECTION:' -A 5
133+
;; ANSWER SECTION:
134+
google.com. 368 IN MX 50 alt4.aspmx.l.google.com.
135+
google.com. 368 IN MX 40 alt3.aspmx.l.google.com.
136+
google.com. 368 IN MX 10 aspmx.l.google.com.
137+
google.com. 368 IN MX 30 alt2.aspmx.l.google.com.
138+
google.com. 368 IN MX 20 alt1.aspmx.l.google.com.
139+
```
140+
141+
查询`SOA`记录
142+
143+
``` bash
144+
$ dig google.com SOA | grep '^;; ANSWER SECTION:' -A 1
145+
;; ANSWER SECTION:
146+
google.com. 85539 IN SOA ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300
147+
```
148+
149+
指定DNS Server查询
150+
151+
``` bash
152+
$ dig www.baidu.com @8.8.8.8
153+
... ...
154+
;; ANSWER SECTION:
155+
www.baidu.com. 1024 IN CNAME www.a.shifen.com.
156+
www.a.shifen.com. 166 IN A 119.75.217.56
157+
www.a.shifen.com. 166 IN A 119.75.218.77
158+
... ...
159+
```
160+
161+
`dig`查询版本号
162+
163+
``` bash
164+
$ dig chaos txt version.bind 10.10.10.2 | grep '^;; ANSWER SECTION:' -A 1
165+
;; ANSWER SECTION:
166+
version.bind. 0 CH TXT "9.8.1-P2"
167+
```
168+
169+
`dig`反解析`-x`
170+
171+
``` bash
172+
$ dig -x 74.125.135.105
173+
;; QUESTION SECTION:
174+
;105.135.125.74.in-addr.arpa. IN PTR
175+
176+
;; ANSWER SECTION:
177+
105.135.125.74.in-addr.arpa. 83205 IN PTR ni-in-f105.1e100.net.
178+
```

Services/NTP.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
## 一、简介
3+
4+
Network Time Protocol(NTP)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可使用加密确认的方式来防止恶毒的协议攻击。默认使用`UDP 123端口`
5+
6+
NTP提供准确时间,首先需要一个准确的UTC时间来源,NTP获得UTC的时间来源可以从原子钟、天文台、卫星,也可从Internet上获取。时间服务器按照NTP服务器的等级传播,根据离外部UTC源的远近将所有服务器归入不用的层(Stratum)中。Stratum-1在顶层由外部UTC接入,stratum-1的时间服务器为整个系统的基础,Stratum的总数限制在15以内。下图为NTP层次图:
7+
8+
<center><img src="/images/Network_Time_Protocol_servers_and_clients.png" alt="ntp" title="ntp" width="400" /></center>
9+
10+
## 二、NTP Server安装配置
11+
12+
关于NTP服务器的安装,根据不同版本安装方法也不同。REDHAT系统则可以使用yum安装,Ubuntu系列可以使用apt-get安装,这里不做具体的介绍,主要详细介绍配置文件的信息。
13+
14+
对于Centos过滤注释和空行后,ntp配置文件内容如下
15+
16+
``` bash
17+
# grep -vE '^#|^$' /etc/ntp.conf
18+
driftfile /var/lib/ntp/drift
19+
restrict default kod nomodify notrap nopeer noquery
20+
restrict -6 default kod nomodify notrap nopeer noquery
21+
restrict 127.0.0.1
22+
restrict -6 ::1
23+
server 0.centos.pool.ntp.org
24+
server 1.centos.pool.ntp.org
25+
server 2.centos.pool.ntp.org
26+
includefile /etc/ntp/crypto/pw
27+
keys /etc/ntp/keys
28+
```
29+
30+
### 2.1 配置选项说明
31+
32+
* `driftfile`选项, 则指定了用来保存系统时钟频率偏差的文件。 ntpd程序使用它来自动地补偿时钟的自然漂移, 从而使时钟即使在切断了外来时源的情况下, 仍能保持相当的准确度。另外,driftfile 选项也保存上一次响应所使用的 NTP 服务器的信息。 这个文件包含了 NTP 的内部信息, 它不应被任何其他进程修改。`无需更改`
33+
* `restrict default kod nomodify notrap nopeer noquery` 默认拒绝所有NTP客户端的操作【restrict <IP 地址> <子网掩码>|<网段> [ignore|nomodiy|notrap|notrust|nknod]】 指定可以通信的IP地址和网段。如果没有指定选项,表示客户端访问NTP服务器没有任何限制
34+
* `ignore`: 关闭所有NTP服务
35+
* `nomodiy`: 表示客户端不能更改NTP服务器的时间参数,但可以通过NTP服务器进行时间同步
36+
* `notrust`: 拒绝没有通过认证的客户端
37+
* `knod`: kod技术科阻止"Kiss of Death"包(一种DOS攻击)对服务器的破坏,使用knod开启功能
38+
* `nopeer`: 不与其它同一层的NTP服务器进行同步
39+
* `server [IP|FQDN|prefer]`指该服务器上层NTP Server,使用prefer的优先级最高,没有使用prefer则按照配置文件顺序由高到低,默认情况下至少15min和上层NTP服务器进行时间校对
40+
* `fudge`: 可以指定本地NTP Server层,如`fudge 127.0.0.1 stratum 9`
41+
* `broadcast 网段 子网掩码`: 指定NTP进行时间广播的网段,如`broadcast 192.168.1.255`
42+
* `logfile`: 可以指定NTP Server日志文件
43+
44+
几个与NTP相关的配置文件:`/usr/share/zoneinfo/``/etc/sysconfig/clock``/etc/localtime`
45+
46+
* `/usr/share/zoneinfo/`: 存放时区文件目录
47+
* `/etc/sysconfig/clock`: 指定当前系统时区信息
48+
* `/etc/localtime`: 相应的时区文件
49+
50+
如果需要修改当前时区,则可以从/usr/share/zoneinfo/目录拷贝相应时区文件覆盖/etc/localtime并修改/etc/sysconfig/clock 即可
51+
52+
``` bash
53+
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
54+
sed -i 's:ZONE=.*:ZONE="Asia/Shanghai":g' /etc/sysconfig/clock
55+
```
56+
57+
## 三、相关命令
58+
59+
`ntpstat`查看同步状态
60+
61+
``` bash
62+
# ntpstat
63+
synchronised to NTP server (192.168.0.18) at stratum 4
64+
time correct to within 88 ms #表面时间校正88ms
65+
polling server every 1024 s #每隔1024s更新一次
66+
```
67+
68+
`ntpq`列出上层状态
69+
70+
``` bash
71+
# ntpq -np
72+
remote refid st t when poll reach delay offset jitter
73+
==============================================================================
74+
*192.168.0.18 202.112.31.197 3 u 101 1024 377 14.268 0.998 0.143
75+
```
76+
77+
输出说明:
78+
79+
* `remote`: NTP Server
80+
* `refid` : 参考的上层ntp地址
81+
* `st` : 层次
82+
* `when` : 上次更新时间距离现在时常
83+
* `poll` : 下次更新时间
84+
* `reach` : 更新次数
85+
* `delay` : 延迟
86+
* `offset`: 时间补偿结果
87+
* `jitter`: 与BIOS硬件时间差异
88+
89+
`ntpdate` 同步当前时间: `ntpdate NTP服务器地址`
90+
91+
## 四、参考文档
92+
93+
* [NTP百度百科](http://baike.baidu.com/view/60648.htm)
94+
* [NTP维基百科](http://en.wikipedia.org/wiki/Network_Time_Protocol)
95+
* 鸟哥Linux私房菜

Services/cron.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@
44

55
> **cron** is the general name for the service that runs scheduled actions. **crond** is the name of the daemon that runs in the background and reads **crontab** files.
66
7-
简单理解:cron 是服务,crond 是收据进程, crontab 的 crond 的配置文件。
7+
简单理解:cron 是服务,crond 是守护进程, crontab 的 crond 的配置文件。
88

99
### 1.2 crontab 选项
1010

11-
+ `crontab -e` : Edit your crontab file, or create one if it doesn't already exist.
11+
+ `crontab -e` : Edit your crontab file, or create one if it doesn't already exist. # 推荐使用命令新增计划任务--语法检查
1212
+ `crontab -l` : Display your crontab file.
13-
+ `crontab -r` : Remove your crontab file.
13+
+ `crontab -r` : Remove your crontab file. # 慎用
1414
+ `crontab -u user` : Used in conjunction with other options, this option allows you to modify or view the crontab file of user. When available, only administrators can use this option.
1515

1616
### 1.3 crontab 格式
1717

1818
minute(s) hour(s) day(s) month(s) weekday(s) command(s)
1919

20-
+ minute: 0-59
21-
+ hour: 0-23
22-
+ day: 1-31
23-
+ month: 1-12
24-
+ weekday: 0-6, 周日:0, 周一:1, 以此类推
25-
+ command: 执行命令(注意要写绝对路径)
20+
```
21+
# Use the hash sign to prefix a comment
22+
# +—————- minute (0 – 59)
23+
# | +————- hour (0 – 23)
24+
# | | +———- day of month (1 – 31)
25+
# | | | +——- month (1 – 12)
26+
# | | | | +—- day of week (0 – 7) (Sunday=0 or 7)
27+
# | | | | |
28+
# * * * * * command to be executed
29+
```
2630

2731
## 二、使用举例
2832

@@ -41,6 +45,19 @@
4145

4246
0 10 * * * 5 /home/jerryzhang/update_weekly.py
4347

48+
(4) 每天 6, 12, 18 点执行一次命令
49+
50+
0 6,12,18 * * * /bin/echo hello
51+
52+
(5) 每天 13, 14, 15, 16, 17 点执行一次命令
53+
54+
0 13-17 * * * /bin/echo hello
55+
56+
__注:__
57+
58+
* 程序执行完毕,系统会给对应用户发送邮件,显示该程序执行内容,如果不想收到,可以重定向内容 `> /dev/null 2>&1`
59+
* 如果执行语句中有 `%` 号,需要使用反斜杠 '\' 转义
60+
4461
## 三、参考资料
4562

4663
+ [维基百科: Cron](http://zh.wikipedia.org/wiki/Cron)
Loading

0 commit comments

Comments
 (0)