How to Set static IP addresses in centos

Source: Internet
Author: User

During the project, the IP address of the host is changed every time the server is restarted because the company's LAN uses the automatic IP address acquisition method. To solve this problem, I have consulted http://blog.sina.com.cn/s/blog_536677e50100qhb5.htmlArticleThen, the static IP address is set as needed to solve the problem. The solution is as follows:

1. Modify Nic configuration EDIT: VI/etc/sysconfig/network-scripts/ifcfg-eth0

Device = eth0 # describe the device alias for the NIC, for example, it is eth0 in the ifcfg-eth0 File
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
Hwaddr = 00: 07: E9: 05: E8: B4 # physical address of the corresponding Nic

Ipaddr = 12.168.0.33 # If you set the method for obtaining the IP address from the network adapter to static, this field specifies the IP address of the network adapter.
Netmask = 255.255.255.0 # network mask corresponding to the network adapter
Network = 192.168.0.0 # network address of the NIC

2. Modify the gateway Configuration

Edit: VI/etc/sysconfig/network:

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 servicesProgramCannot be started)
Hostname = centos (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 (set the IP address of the gateway connected to the local machine .)

The first three items are available by default when I open the editing here, so only gateway is added.

3. Modify DNS Configuration

Edit: VI/etc/resolv. conf:

Nameserver is the IP address of the DNS server. The first is the first choice, and the second is the backup.

4. Restart the network service.

Run the following command:

Service Network restart or/etc/init. d/network restart

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.