CentOS 6.3 static IP settings tutorial
There is a computer installed with CentOS6.3 in the LAN. when the power is down or restarted, its IP address will be re-allocated by DHCP. If you want to remotely control the computer, you have to turn on the monitor to view its new IP address, this is too troublesome. So we need to set the IP address of this computer to static.
(1) Find the/etc/sysconfig/network-scripts/ifcfg-eth0 file, create one if not, the content is as follows
[Plain]View
Plaincopy
- Device = eth0
- Bootproto = static
- Broadcast = 192.168.0.255
- Onboot = Yes
- Ipaddr = 192.168.0.108
- Netmask = 255.255.255.0
- Gateway = 192.168.0.1
- Dns1 = 192.168.0.1
DEVICE = eth0 # describe the DEVICE alias corresponding to the NIC
BOOTPROTO = static # Set the way for the NIC to obtain the IP address. The possible options are static, dhcp, or bootp, which respectively correspond to the IP address specified by the static state and the IP address obtained through the dhcp protocol, IP addresses obtained through the bootp protocol
BROADCAST = 192.168.0.255 # corresponding subnet BROADCAST address
ONBOOT = yes
IPADDR = 192.168.0.108 # If you set the method for obtaining the IP address from the NIC to static, this field specifies the IP address of the NIC.
NETMASK = 255.255.255.0 # network mask corresponding to the network adapter
GATEWAY = 192.168.0.1 # the IP address of the default GATEWAY, which can be found in CMD using ipconfig
DNS1 = 192.168.0.1 # address of the DNS1 server, which can be found in CMD using nslookup
(2) Find the/etc/sysconfig/network file. The content is as follows:
[Plain]View
Plaincopy
- NETWORKING = yes
- NETWORKING_IPV6 = no
- HOSTNAME = localhost. localdomain
- GATEWAY = 192.168.0.1
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 be started.
Networking_ipv6 = No
Hostname = localhost. localdomain # Set the Host Name of the local machine. The host name set here must correspond to the host name set in/etc/hosts.
Gateway = 192.168.0.1 # IP address of the default gateway
(3) view the/etc/resolv. conf file
[Plain]View
Plaincopy
- # Generated by NetworkManager
- Nameserver 192.168.0.1
This file does not need to be modified, it is automatically generated according to the NIC configuration file/etc/sysconfig/network-scripts/ifcfg-eth0. Even if the modification is made, the content will be washed out after the network service is restarted.
(4) restart the network service
[Plain]View
Plaincopy
- Service network restart