Set IP address 1 under CentOS/Linux
: Temporary modification:
1.1: Modify IP address
# ifconfig eth0 192.168.100.100
1.2: Modify 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 of the Internet 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 modification. If you want to permanently modify the network card configuration file, you need to modify the corresponding file.
2: Permanent modification:
2.1: Modify IP address
Modify the /etc/sysconfig/network-scripts/ifcfg-eth0 file, if there are multiple network cards, modify the corresponding network card
# vi /etc/sysconfig/network-scripts/ifcfg- eth0
DEVICE=eth0 #The device alias corresponding to the network card
BOOTPROTO=static #The way the network card obtains the ip address (the default is dhcp, which means automatic acquisition)
HWADDR=00:07:E9:05:E8:B4 #Network card MAC address (physical address)
IPADDR=192.168.100.100 #IP address
NETMASK=255.255.255.0 #Subnet mask
ONBOOT=yes #Whether this 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, no indicates that the network cannot be used At this time, the IP address can be pinged, but the domain name cannot be pinged, so you need to modify DNS 2.3: modify DNS to 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: restarting the network card # service network restart is shutting down interface eth0: [OK]
Close the loopback interface: [OK]
Pop up the loopback interface: [OK]
Pop up the interface eth0: [OK]
At this time, the system can access the Internet normally
#Note: In fact, the gateway address and DNS can also be written in ifcfg-eth0, But for the sake of specification, they are written separately
from : http://www.linuxidc.com/Linux/2015-02/112964.htm
Set IP address under CentOS/Linux
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326885624&siteId=291194637
Recommended
Ranking