Force Custom DNS Server with DHCP on Linux
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_2'Replace 'custom_dns_server_1' and 'custom_dns_server_2' with 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.
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qA2P 著作权归作者所有。请勿转载和采集!