Set IP address under Centos/linux
1: Temporary modification:
1.1: Modify 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
This time will be able to surf the internet, the IP address of the Internet is 192.168.100.100, the gateway address is 192.168.100.1. However, such a setting is temporary, once the network card restart or restart the server, in addition to 1.3 of other operations will be restored, such a way only suitable for temporary IP modification, want to permanently modify the network card configuration file, you need to modify the corresponding file
2: Permanent modification:
2.1: Modify the IP address
Modify the/etc/sysconfig/network-scripts/ifcfg-eth0 file, if more than one network card, then modify the appropriate network card
# vi/etc/ Sysconfig/network-scripts/ifcfg-eth0
device=eth0 #网卡对应的设备别名
bootproto=static & nbsp #网卡获得ip地址的方式 (default is DHCP, means auto get)
hwaddr=00:07:e9:05:e8:b4 #网卡MAC地址 (Physical address)
Ipaddr= 192.168.100.100 #IP地址
netmask=255.255.255.0 #子网掩码 &NBSP
onboot=yes &NBS P #系统启动时是否激活此设备
2.2: Modify the gateway address
Modify the/etc/sysconfig/network file
# vi/etc/sysconfig/network
Networking=yes #表示系统是否使用网络, no means network is not available
Hostname=doiido #设置本机的主机名 to be the same as the host name set in/etc/hosts
gateway=192.168.100.1 #设置网关的IP地址
You can ping the IP address at this time, but you cannot ping the domain name, so 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域名服务器
NameServer 114.144.114.114 #国内域名服务器
2.4: Restart the NIC
# Service Network Restart
Shutting down interface eth0: [OK]
Close Loopback interface: [OK]
Eject loopback interface: [OK]
Popup interface eth0: [OK]
This time, the system will be able to surf the internet properly.
#注: In fact, the gateway address and DNS can also be written in Ifcfg-eth0, but for the sake of specification, write them apart
Set IP address under Centos/linux