To overwrite DNS server settings from DHCP under Linux, you can use the following steps:

  1. Open the terminal.

  2. Edit the Network Manager configuration file using a text editor (e.g., nano or vi). The file is usually located at /etc/NetworkManager/NetworkManager.conf.

    sudo nano /etc/NetworkManager/NetworkManager.conf
    
  3. Look for the [main] section in the file and add the line dns=none. This line tells Network Manager not to use the DNS servers provided by DHCP.

    [main]
    dns=none
    
  4. Save the file and exit the text editor.

  5. Restart the Network Manager service to apply the changes.

    sudo systemctl restart NetworkManager
    
  6. Configure the DNS servers manually by editing the network interface configuration file. The file is usually located at /etc/sysconfig/network-scripts/ifcfg-<interface_name>. Replace <interface_name> with the name of your network interface (e.g., eth0).

    sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
    
  7. Add the following lines to the file, replacing <DNS_server_IP> with the IP address of your desired DNS server(s).

    DNS1=<DNS_server_IP>
    DNS2=<DNS_server_IP>
    

    You can add multiple DNS servers by specifying additional DNS3, DNS4, and so on.

  8. Save the file and exit the text editor.

  9. Restart the network service to apply the changes.

    sudo systemctl restart network
    

After following these steps, your Linux system should now use the manually configured DNS servers and ignore the ones provided by DHCP


原文地址: http://www.cveoy.top/t/topic/iU4p 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录