how to force using custom dns server when obtained ip from dhcp in ifcfg config file
To force the use of a custom DNS server when obtaining an IP address from DHCP in the ifcfg config file, you can follow these steps:
-
Open the ifcfg config file for the specific network interface you want to configure. The file is usually located in the
/etc/sysconfig/network-scripts/directory and has a name likeifcfg-eth0orifcfg-ens33. -
Edit the file using a text editor such as
viornano. -
Look for the line starting with
BOOTPROTOand change its value toBOOTPROTO=dhcp. This ensures that the IP address is still obtained from DHCP. -
Add the following lines to the file to specify the custom DNS server(s):
DNS1=custom_dns_server_1 DNS2=custom_dns_server_2Replace
custom_dns_server_1andcustom_dns_server_2with the IP addresses of your desired DNS servers. You can add additional lines (DNS3,DNS4, etc.) if needed. -
Save and exit the file.
-
To apply the changes, restart the network service by running the following command:
sudo systemctl restart networkAlternatively, you can also restart the specific network interface by running:
sudo ifdown <interface_name> sudo ifup <interface_name>Replace
<interface_name>with the name of the network interface you modified (e.g.,eth0orens33).
After restarting the network service or the specific network interface, the custom DNS servers should be used instead of the ones provided by DHCP
原文地址: http://www.cveoy.top/t/topic/iU3X 著作权归作者所有。请勿转载和采集!