Configure static IP addresses and DNS for centos 7
Configure static IP addresses and DNS for centos 7
cd /etc/sysconfig/network-scripts/
Find the corresponding Nic configuration and edit it
vim ifcfg-eno16777736
Configure eno-16777736
TYPE = EthernetBOOTPROTO = static # configure static IP addresses, gateways, subnet Mask IPADDR = subnet mask = 255.255.255.0GATEWAY = 192.168.86.2 cancel networkmanager management NM_CONTROLLED = noDEFROUTE = yesPEERDNS = yesPEERROUTES = route = now.6init = route = bandwidth = noNAME = ed246b2b-cc49-4785-a675-feebf70440e7DEVICE = eno16777736ONBOOT = yes
NM_CONTROLLED = no indicates that the interface is managed through the configuration file instead of the Network Manager. "ONBOOT = yes" indicates that the system will enable this interface at startup.
I configured it in a virtual machine and used a bridge to connect to the network. The IP configuration and gateway can be found in the Virtual Machine editor.
Restart the network service after configuring the static IP address.
systemctl restart network.service
If you ping Baidu, the host cannot be found. If you ping Baidu IP (180.149.132.47), the host can be pinged, indicating that DNS is not configured. Next, configure DNS.
Switch to the networkmanager directory
cd /etc/NetworkManager/
Add a configuration file for modifying NetworkManager. conf
dns=none
Not managed through network manager
Modify resolv. conf and add dns Configuration
# Primary DNSnameserver 8.8.8.8 # standby DNSnameserver 8.8.4.4
Now ping baidu.com can be pinged.