2015年4月20日 星期一

[Linux 文章收集] How to configure static DNS on CentOS or Fedora

Source From Here 
Preface 
If you want to hard-code DNS servers to use on CentOS or Fedora, the method can differ, depending on whether you use Network Manager or network service. On RHEL based systems, Network Manager is used to manage network interfaces by default, while you can switch to network service. 

Configure static DNS with Network Manager 
If you are using Network Manager, you can configure static DNS as follows. 

In case of DHCP, choose "Automatic (DHCP) addresses only" method, so that your DHCP server cannot override your DNS setting. Then in the "DNS servers" field, enter a comma separate list of DNS servers to use (e.g., 8.8.8.8 and 8.8.4.4). 
 

If you use a static IP address, simply enter your DNS servers in the "DNS servers" field: 
 

Configure static DNS in /etc/sysconfig/network-scripts/ifcfg-ethX 
If you disabled Network Manager, but use network service instead, you can use interface configuration files (e.g., /etc/sysconfig/network-scripts/ifcfg-eth0) to specify static DNS. In this case, there are actually two ways to do it. 

Method One 
Use "PEERDNS=no". This option will prevent /etc/resolv.conf from being modified by a DHCP server. So instead of using DHCP-provided DNS, you can specify any arbitrary DNS servers you want to use in /etc/resolv.conf

The configuration file for your network interface (e.g., eth0) looks like the following. 
$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
  1. DEVICE=eth0  
  2. BOOTPROTO=dhcp  
  3. ONBOOT=yes  
  4. PEERDNS=no  
  5. ...  

Then, add static DNS to /etc/resolv.conf 
$ sudo vi /etc/resolv.conf
  1. nameserver 8.8.8.8  
  2. nameserver 8.8.4.4  

Method Two 
Alternatively, you can specify DNS servers directly in the interface configuration file, instead of modifying /etc/resolv.conf yourself. That is: 
$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
  1. DEVICE=eth0  
  2. BOOTPROTO=dhcp  
  3. ONBOOT=yes  
  4. DNS1=8.8.8.8  
  5. DNS2=8.8.4.4  

The DNS servers specified with "DNS1/DNS2" directives will then automatically be added to /etc/resolv.conf when the interface is activated. So there is no need to modify /etc/resolv.conf yourself. 

The above two methods can be applied similarly to a static IP address case. That is: 
  1. DEVICE=eth0  
  2. BOOTPROTO=manual  
  3. ONBOOT=yes  
  4. IPADDR=10.0.1.27  
  5. NETWORK=10.0.1.0  
  6. NETMASK=255.255.255.0  
  7. PEERDNS=no   
then add DNS to /etc/resolv.conf 

Or: 
  1. DEVICE=eth0  
  2. BOOTPROTO=manual  
  3. ONBOOT=yes  
  4. IPADDR=10.0.1.27  
  5. NETWORK=10.0.1.0  
  6. NETMASK=255.255.255.0  
  7. DNS1=8.8.8.8  
  8. DNS2=8.8.4.4  
Supplement 
CentOS : Manual IP network configuration

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...