Set IP addresses in CentOS
Set IP addresses in CentOS
1: temporary modification:
1.1: Modify the IP address
# Ifconfig eth0 192.168.100.100
1.2: Modify the gateway address
# Route add default gw 192.168.100.1 dev eth0
1.3: Modify DNS
# Echo "nameserver 8.8.8.8">/etc/resolv. conf
At this time, you can access the internet. The IP address is 192.168.100.100 and the gateway address is 192.168.100.1. However, this setting is temporary. Once the network card is restarted or the server is restarted, all operations except 1.3 will be restored. This method is only suitable for temporary IP address modification, to permanently modify the NIC configuration file, you must modify the corresponding file.
2: Permanent modification:
2.1: Modify the IP address
Modify the/etc/sysconfig/network-scripts/ifcfg-eth0 file. If there are multiple NICs, modify the corresponding Nic
# Vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE = eth0 # The DEVICE alias corresponding to the NIC
BOOTPROTO = static # How to obtain the IP address of the NIC (dhcp is used by default, indicating that the IP address is automatically obtained)
HWADDR = 00: 07: E9: 05: E8: B4 # Nic MAC address (physical address)
IPADDR = 192.168.100.100 # IP Address
NETMASK = 255.255.255.0 # Subnet Mask
ONBOOT = yes # whether the device is activated when the system starts
2.2: Modify the gateway address
Modify the/etc/sysconfig/network File
# Vi/etc/sysconfig/network
NETWORKING = yes # indicates whether the system uses the network, and no indicates that the network cannot be used.
HOSTNAME = doiido # Set the Host Name of the local machine. It must be the same as the host name set in/etc/hosts.
GATEWAY = 192.168.100.1 # Set the IP address of the GATEWAY
At this time, you can ping the IP address but cannot ping the domain name. Therefore, you need to modify the DNS
2.3: Modify DNS
Modify the/etc/resolv. conf file
# Vi/etc/resolv. conf
Nameserver 8.8.8.8 # google Domain Name Server
Nameserver 114.144.114.114 # domestic Domain Name Server
2.4: restart the NIC
# Service network restart
Closing interface eth0: [OK]
Disable the loop interface: [OK]
Pop-up loop interface: [OK]
Pop-up page eth0: [OK]
At this time, the system will be able to access the Internet normally.
# Note: in fact, the gateway address and DNS can also be written in the ifcfg-eth0, but for the sake of standardization, write them separately