When we use the CentOS system, we may feel that some settings are not suitable for ourselves. Although they do not cause great errors, they do cause us a lot of trouble, next I will give you some suggestions to modify your DNS, gateway, and IP address. Let's explain how to modify it!
1. Modify DNS in CentOS
Modify the DNS configuration file of the corresponding Nic
1 # vi/etc/resolv. conf
Modify the following content
12 nameserver 8.8.8.8 # google Domain Name Server nameserver 8.8.4.4 # google Domain Name Server
2. CentOS System gateway Modification
Modify the gateway configuration file of the corresponding Nic
1 [root @ centos] # vi/etc/sysconfig/network
Modify the following content
123 NETWORKING = yes (indicates whether the system uses the network, which is generally set to yes. If it is set to no, the network cannot be used, and many system service programs cannot start) HOSTNAME = centos (set the Host Name of the local machine, the host name set here corresponds to the host name set in/etc/hosts) GATEWAY = 192.168.1.1 (set the IP address of the GATEWAY connected to the local machine. For example, the gateway is 10.0.0.2)
3. Modify the IP address of the CentOS System
Modify the configuration file of the corresponding Nic IP Address
1 # vi/etc/sysconfig/network-scripts/ifcfg-eth0
Modify the following content
12345678910 DEVICE = eth0 # describe the DEVICE alias corresponding to the NIC, for example, In the ifcfg-eth0 file it is eth0BOOTPROTO = static # Set the way the NIC gets the IP address, possible options are static, dhcp or bootp, corresponding to static IP addresses, IP addresses obtained through dhcp, IP addresses obtained through the bootp protocol BROADCAST = 192.168.0.255 # corresponding subnet BROADCAST address HWADDR = 00: 07: E9: 05: e8: B4 # The physical IP address of the corresponding network adapter IPADDR = 12.168.1.2 # If you set the network adapter's IP address to be statically specified, this field specifies the IP address IPV6INIT = no00006_autoconf = noNETMASK = 255.255.255.0 # NETWORK mask NETWORK = 192.168.1.0 # NETWORK address of the NETWORK adapter ONBOOT = yes # whether to set the IP address when the system starts. this network interface, when set to yes, the device is activated when the system starts.
4. Restart the network configuration.
1 service network restart
Or
1/etc/init. d/network restart
Modify IP Address
Effective immediately:
1 ifconfig eth0 192.168.0.2 netmask 255.255.255.0
Start effective:
Modify
1/etc/sysconfig/network-scripts/ifcfg-eth0
Modify Gateway Default Gateway
Effective immediately:
1 route add default gw 192.168.0.1 dev eth0
Start effective:
Modify
1/etc/sysconfig/network
Modify DNS
Modify
1/etc/resolv. conf
The modification takes effect immediately and starts as well.
Modify host name
Effective immediately:
1 hostname centos1
Start effective:
Modify
1/etc/sysconfig/network
In the CentOS system, we have modified the DNS, gateway, and IP address. After restarting the network configuration, we can see the effect.