2012年6月29日 星期五

Ubuntu server 12.04 手動設定DNS server的正確方式


很多網路文章....都寫要手動更改/etc/resolv.conf
這在12.04 server 是錯的
resolv.conf開頭就有兩行:


# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

手動改完 reslov.conf 之後,下次重開機系統會把手動加入的部份清空。

正確方式請man resolvconf或參考
http://manpages.ubuntu.com/manpages/precise/man8/resolvconf.8.html

手動設定12.04 server  的IP位址時,修改  /etc/network/interface 加入

dns-nameservers  IP1 IP2 ...

系統在執行/etc/init.d/networking 時會讀取這行設定,自動更新 /etc/resolv.conf

底下是我的 /etc/network/interface 檔案,供參考



# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.240
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
dns-nameservers 168.95.1.1 8.8.8.8

沒有留言: