Centos6.5-dnsmasq安裝,

來源:互聯網
上載者:User

Centos6.5-dnsmasq安裝,

1、使用yum install dnsmasq -y 安裝dns(含dns server和dns代理功能)

2、查詢dnsmasq已經安裝成功

[root@localhost ~]# rpm -q dnsmasq

dnsmasq-2.48-18.el6_9.x86_64

[root@localhost ~]#

3、配置/etc/dnsmasq.conf檔案

對於/etc/dnsmasq.conf檔案的行太多的話,我們只需要添加我們需要的行,先把所有行都注釋掉,然後echo追加進去我們所需要的行。

  3.1、修改/etc/dnsmasq.conf的快速方法:在每行的頭添加字元,比如"#",注釋掉檔案的所有行,命令如下:
sed -i 's/^/#&/g' /etc/dnsmasq.conf    //注釋掉/etc/dnsmasq.conf檔案中的所有的行
cat /etc/dnsmasq.conf |grep -v "#"  //查看注釋是否OK

  3.2、然後把需要的行echo追加進去

echo resolv-file=/etc/resolv.dnsmasq.conf >>/etc/dnsmasq.conf    #此/etc/resolv.dnsmasq.conf檔案還需後續編輯
echo strict-order >>/etc/dnsmasq.conf
echo interface=eth0  >>/etc/dnsmasq.conf               #對特定介面提供dns服務
echo addn-hosts=/etc/dnsmasq.hosts >>/etc/dnsmasq.conf  #此/etc/dnsmasq.hosts檔案還需後續編輯

[root@localhost ~]# cat /etc/dnsmasq.conf |grep -v "#"            //查看echo是否追加ok
resolv-file=/etc/resolv.dnsmasq.conf
strict-order
interface=eth0  #對特定介面提供dns服務
addn-hosts=/etc/dnsmasq.hosts
[root@localhost ~]#

////////sed -i 's/^#//' 123.txt      //刪除檔案的行首字元#  注意 要加-i才能修改檔案生效

////////sed -i 's/^/#&/g' 123.txt    //每行添加行首字元# 注意 要加-i才能修改檔案生效

4、編輯設定檔

  4.1編輯/etc/resolv.dnsmasq.conf設定檔

cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
[root@localhost ~]# vim /etc/resolv.dnsmasq.conf
nameserver 8.8.8.8 
[root@localhost ~]#

  4.2編輯 /etc/dnsmasq.hosts設定檔

cp /etc/hosts /etc/dnsmasq.hosts               
[root@localhost ~]# vim /etc/dnsmasq.hosts
127.0.0.1  localhost.localdomain localhost
::1  localhost6.localdomain6 localhost6
135.251.214.2 RMS.chinamobile.com *.chinamobile.com   #劫持網域名稱映射到135.251.214.2

5、service dnsmasq restart  啟動服務

[root@Apache zfp]# service dnsmasq start
Starting dnsmasq:                                          [確定]
[root@Apache zfp]#

[root@Apache zfp]# service dnsmasq status
dnsmasq (pid  1139) 正在運行...
[root@Apache zfp]#

6、查看53連接埠監聽狀態

[root@localhost ~]# netstat -tunlp |grep 53
tcp        0      0 0.0.0.0:53                  0.0.0.0:*                   LISTEN      2465/dnsmasq       
tcp        0      0 :::53                       :::*                        LISTEN      2465/dnsmasq       
udp        0      0 0.0.0.0:53                  0.0.0.0:*                               2465/dnsmasq       
udp        0      0 :::53                       :::*                                    2465/dnsmasq       
[root@localhost ~]#

7、設定隨系統啟動dnsmasq服務

[root@localhost ~]#chkconfig dnsmasq on   //隨linux系統啟動dnsmasq服務

[root@localhost ~]# chkconfig --list |grep dnsmasq    //查看是否設定成功
dnsmasq         0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
[root@localhost ~]#

--------End Of Text-------

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.