How To Change your DNS on Linux

If you want to hard-code DNS Servers to use on CentOS or Debian, it has 2 methods.

  1. Configure static DNS with GUI Network manager ( Ubuntu Desktop )
  2. Configure static DNS in /etc/sysconfig/network-scripts/ifcfg-eth0 (Default is eth0)
    1. By the way, just edit the config file by following cmd
      $ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
      DEVICE=eth0
      BOOTPROTO=dhcp
      ONBOOT=yes
      PEERDNS=no

      Then, add static DNS to /etc/resolv.conf

      $ sudo vi /etc/resolv.conf
      nameserver 8.8.8.8
      nameserver 8.8.4.4
    2. Method 2 (DHCP) 
      $ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
      DEVICE=eth0
      BOOTPROTO=dhcp
      ONBOOT=yes
      DNS1=8.8.8.8
      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.

    3. Fixed IP
      DEVICE=eth0
      BOOTPROTO=manual
      ONBOOT=yes
      IPADDR=10.0.1.27
      NETWORK=10.0.1.0
      NETMASK=255.255.255.0
      DNS1=8.8.8.8
      DNS2=8.8.4.4