# 確保網絡接口配置使用dhcp方式

[root@localhost] cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE="eth1"

BOOTPROTO=dhcp

IPV6INIT=no

NM_CONTROLLED=no

ONBOOT="yes"

TYPE="Ethernet"

# 重啟網絡服務

[root@localhost] service network restart

Shutting down interface eth0: [OK]

Shutting down loopback interface: [OK]

Bringing up loopback interface: [OK]

Bringing up interface eth0:

Determining IP information for eth1… done. [OK]

# 檢查IP地址

[root@os03] ifconfig

eth1Link encap:EthernetHWaddr 00:0C:29:15:63:D9

inet addr:192.168.1.202Bcast:192.168.1.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe15:63d9/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:251 errors:0 dropped:0 overruns:0 frame:0

TX packets:43 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:36077 (35.2 KiB)TX bytes:4598 (4.4 KiB)

……

# 檢查默認路由

[root@os03] route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric RefUse Iface

192.168.1.0 0.0.0.0 255.255.255.0 U 000 eth1

169.254.0.0 0.0.0.0 255.255.0.0 U 1002 00 eth1

 

配置DNS服務

DNSmasq能夠緩存外部DNS記錄,同時提供本地DNS解析或者作為外部DNS的代理,即DNSmasq會首先查找/etc/hosts等本地解析文件,然后再查找/etc/resolv.conf等外部nameserver配置文件中定義的外部DNS。所以說dnsmasq是一個很不錯的DNS中繼。DNS配置同樣寫入dnsmasq.conf配置文件里。

# 本地解析文件

#no-hosts

#addn-hosts=/etc/banner_add_hosts

 

# Set this (and domain: see below) if you want to have a domain

# automatically added to simple names in a hosts-file.

# 例如,/etc/hosts中的os01將擴展成os01.debugo.com

expand-hosts

local=/debugo.com/

 

# 強制使用完整的解析名

domain-needed

 

# 添加額外的上級DNS主機(nameserver)配置文件

#resolv-file=

 

# 不使用上級DNS主機配置文件(/etc/resolv.conf和resolv-file)

no-resolv

# 相應的,可以為特定的域名指定解析它的nameserver。一般是其他的內部DNS name server

# server=/myserver.com/192.168.0.1

 

# 設置DNS緩存大小(單位:DNS解析條數)

cache-size=500

 

# 關于log的幾個選項

log-queries

 

#log-dhcp

 

log-facility=/var/log/dnsmasq.log

 

# 異步log,緩解阻塞,提高性能。

log-async=20

 

# 指定domain的IP地址

address=/doubleclick.net/127.0.0.1

address=/.phobos.apple.com/202.175.5.114

 

配置完成后重啟dnsmasq,然后在客戶端測試:

[root@os03] nslookup os01.debugo.com

Server:192.168.1.132

Address:192.168.1.132#53

Name:os01.debugo.com

Address: 192.168.1.132

[root@os03] nslookup os02.debugo.com

Server:192.168.1.132

Address:192.168.1.132#53

Name:os02.debugo.com

Address: 192.168.1.201

[root@os03] nslookup doubleclick.net

Server:192.168.1.132

Address:192.168.1.132#53

Name:doubleclick.net

Address: 127.0.0.1

#注意,由于address選項解析為127.0.0.1,而非server的192.168.1.132地址。

[root@os03] nslookup a1.phobos.apple.com

Server:192.168.1.132

Address:192.168.1.132#53

Name:a1.phobos.apple.com

Address: 202.175.5.114

 

好了,說到這里應該都會使用DNSmasq這個小工具了,簡單快捷,下一期,我們再講講如何搭建智能dns。更多精彩》》

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:www.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » linux基本服務系列之DNSmasq的使用

登錄

找回密碼

注冊