Refer to the followingArticle:
Https://gist.github.com/fernandoaleman/2172388
Http://www.lifelinux.com/how-to-configure-static-ip-address-on-centos/
Http://www.ehowstuff.com/how-to-configure-static-ip-address-on-centos-6-2-linux-server/
Http://www.liurongxing.com/centos-dns-ifcfg-resolv.html
Http://bbs.csdn.net/topics/390162805
Http://www.cnblogs.com/shawnloong/archive/2011/11/23/2260757.html
1) At first, the system automatically obtains the IP address through DHCP. view the IP address of the system, which is similar to the following: (this step is critical. Find the corresponding network device and configuration file)
Root @ centos_aaa ~] # Ifconfig
Eth6Link encap: Ethernet hwaddr 08: 00: 27: C1: e4: 3D
Inet ADDR: 192.168.0.103 bcast: 192.168.0.255 mask: 255.255.255.0
Inet6 ADDR: fe80: a00: 27ff: fec1: e43d/64 scope: Link
Up broadcast running Multicast MTU: 1500 Metric: 1
RX packets: 108 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 32 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX Bytes: 12689 (12.3 kib) TX Bytes: 5908 (5.7 kib)
Lo link encap: local loopback
Inet ADDR: 127.0.0.1 mask: 255.0.0.0
Inet6 ADDR: 1/128 scope: Host
Up loopback running MTU: 16436 Metric: 1
RX packets: 8 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 8 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX Bytes: 480 (480.0 B) TX Bytes: 480 (480.0 B)
2) modify the corresponding/etc/sysconfig/network-scripts/Ifcfg-eth6But the file below does not exist, so you can directly create this file. The file content is modified as follows:
Device = eth6
Hwaddr = "08: 00: 27: C1: e4: 3D"
Nm_controlled = Yes
Onboot = Yes
Type = Ethernet
Ipaddr = 192.168.0.120
Bootpro = static
Netmask = 255.255.255.0
Dns1 = 192.168.0.1
Networking_ipv6 = No
Ipv6init = No
Ipv6_autoconf = No
Gateway = 192.168.0.1
3) modify the/etc/sysconfig/network file as follows:
Networking = Yes
Networking_ipv6 = No
Ipv6init = No
Hostname = centos_aaa
Gatway = 192.168.0.1
4) restart the service network restart
5) restart the system shutdown-R now
6) view the new IP Address: ipconfig
7) However, if this problem occurs, you can access the Intranet, but not the internet.
It seems that DNS configuration in/etc/resolv. conf does not work. The prompt is as follows:
# Generated by NetworkManager
# No nameservers found; try putting DNS servers into your
# Ifcfg files in/etc/sysconfig/network-Scripts like so:
#
# Dns1 = XXX. XXX
# Dns2 = XXX. XXX
# Domain = lab.foo.com bar.foo.com
Add the DNS configuration to/etc/sysconfig/network-scripts/ifcfg-eth6 and add dns1 = 192.168.0.1.
But this time still does not work, the last query information is the lack of default routing settings, you need to add the following file/etc/sysconfig/network-scripts/route-eth6, the content is: via 192.168.0.1.
Then restart the network.
8) the/etc/hosts file is set as follows: but it should be unrelated to the IP address and DNS configuration problems.
27.0.0.1 localhost. localdomain localhost
192.168.0.120 centos_aaa
: 1 localhost6.localdomain6 localhost6
9) but it is found that the static IP does not work after the shutdown and restart, because the network service is not set as an automatic random device to start. The modification is as follows:
You need to start the network service:
[Root @ centos_aaa ~] # Chkconfig network on
[Root @ centos_aaa ~] # Chkconfig -- list | less
Network 0: off 1: off 2: On 3: On 4: On 5: on 6: Off
10) after the machine is restarted, only IPv6 and IPv4 are available. You need to manually execute service network start to enter the fixed ip4 status. How can this problem be solved ??? (The reason is network andNetworkManager conflicts with services)
Stop IPv6 and add the following content at the end of/etc/sysctl. conf:
Net. ipv6.conf. All. disable_ipv6 = 1
Net. ipv6.conf. Default. disable_ipv6 = 1
Then stop the NetworkManager service:
Chkconfig -- level123456 NetworkManager off
I personally think that in order to avoid functional conflicts between the two services, NetworkManager should not be a service, but should be encapsulated on an upper layer of the network service.