When using the CentOS system, we may feel that some settings are not suitable for us. Although it will not cause major mistakes, it does bring us a lot of small troubles. Now I will give you some suggestions and modify them. Your DNS, gateway and IP address. So let's explain how to modify it!
1. The CentOS system modifies the DNS
to modify the DNS configuration file of the corresponding network card
# vi /etc/resolv.conf
to modify the following content
nameserver 8.8.8.8 #google domain name server
nameserver 8.8.4.4 #google domain name server
2. CentOS system to modify the gateway
to modify the corresponding network card The configuration file of the gateway [root@centos]# vi /etc/sysconfig/network
Modify the following content
NETWORKING=yes (indicates whether the system uses the network, generally set to yes. If it is set to no, the network cannot be used, and many system services The program will not be able to start)
HOSTNAME=centos (set the host name of the machine, the host name set here should correspond to the host name set in /etc/hosts)
GATEWAY=192.168.1.1 (set the IP address of the gateway connected to the machine. For example, the gateway is 10.0.0.2)
3. Modify the IP address of the CentOS system Modify
the configuration file corresponding to the IP address of the network card
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Modify the following content
DEVICE=eth0 #Describe the device alias corresponding to the network card. For example, in the ifcfg-eth0 file, it is eth0
BOOTPROTO=static #Set the way the network card obtains the ip address. The possible options are static, dhcp or bootp, corresponding to the statically specified ip address respectively. , the ip address obtained through the dhcp protocol, and the ip address obtained through
the
bootp
protocol .1.2 #If the method of setting the network card to obtain the ip address is statically specified, this field specifies the ip address corresponding to the network card
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0 #The network mask corresponding to the network card
NETWORK=192.168.1.0 #Network card Corresponding network address
ONBOOT=yes #Whether this network interface is set when the system starts, when it is set to yes, the device is activated when the system starts
4. Restart the network configuration
service network restart or /etc/init.d/network restart
to modify the IP address
Immediately effective:
ifconfig eth0 192.168.0.2 netmask 255.255.255.0
Start effective:
Modify /etc/sysconfig/network-scripts/ifcfg-eth0
Modify the gateway Default Gateway
takes effect immediately:
route add default gw 192.168.0.1 dev eth0
starts to take effect:
modify /etc/sysconfig/network
Modify DNS
Modify /etc/resolv.conf
After modification It can take effect immediately, and it is also effective to start.
Modify the host name to
take effect immediately:
hostname centos1
Start to take effect:
modify /etc/sysconfig/network
In CentOS system, we have completed the modification of DNS, gateway, and IP address. After restarting the network configuration, we will You can see the effect.
1. The CentOS system modifies the DNS
to modify the DNS configuration file of the corresponding network card
# vi /etc/resolv.conf
to modify the following content
nameserver 8.8.8.8 #google domain name server
nameserver 8.8.4.4 #google domain name server
2. CentOS system to modify the gateway
to modify the corresponding network card The configuration file of the gateway [root@centos]# vi /etc/sysconfig/network
Modify the following content
NETWORKING=yes (indicates whether the system uses the network, generally set to yes. If it is set to no, the network cannot be used, and many system services The program will not be able to start)
HOSTNAME=centos (set the host name of the machine, the host name set here should correspond to the host name set in /etc/hosts)
GATEWAY=192.168.1.1 (set the IP address of the gateway connected to the machine. For example, the gateway is 10.0.0.2)
3. Modify the IP address of the CentOS system Modify
the configuration file corresponding to the IP address of the network card
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Modify the following content
DEVICE=eth0 #Describe the device alias corresponding to the network card. For example, in the ifcfg-eth0 file, it is eth0
BOOTPROTO=static #Set the way the network card obtains the ip address. The possible options are static, dhcp or bootp, corresponding to the statically specified ip address respectively. , the ip address obtained through the dhcp protocol, and the ip address obtained through
the
bootp
protocol .1.2 #If the method of setting the network card to obtain the ip address is statically specified, this field specifies the ip address corresponding to the network card
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0 #The network mask corresponding to the network card
NETWORK=192.168.1.0 #Network card Corresponding network address
ONBOOT=yes #Whether this network interface is set when the system starts, when it is set to yes, the device is activated when the system starts
4. Restart the network configuration
service network restart or /etc/init.d/network restart
to modify the IP address
Immediately effective:
ifconfig eth0 192.168.0.2 netmask 255.255.255.0
Start effective:
Modify /etc/sysconfig/network-scripts/ifcfg-eth0
Modify the gateway Default Gateway
takes effect immediately:
route add default gw 192.168.0.1 dev eth0
starts to take effect:
modify /etc/sysconfig/network
Modify DNS
Modify /etc/resolv.conf
After modification It can take effect immediately, and it is also effective to start.
Modify the host name to
take effect immediately:
hostname centos1
Start to take effect:
modify /etc/sysconfig/network
In CentOS system, we have completed the modification of DNS, gateway, and IP address. After restarting the network configuration, we will You can see the effect.
Reprinted in: https://my.oschina.net/cjkall/blog/195878