How to Set CentOS 7 to automatically obtain the IP address upon startup

Source: Internet
Author: User

How to Set CentOS 7 to automatically obtain the IP address upon startup

In this example, CentOS 7 is used as an example to describe how to set the Linux system to automatically obtain IP addresses and set fixed IP addresses.

Automatically obtain Dynamic IP addresses

1. Enter "ip addr" and press the Enter key to confirm that the IP address cannot be obtained (CentOS 7 does not have the ifconfig command by default). Record the NIC name (in this example, ens33, In the yellow box ).

2. Enter "cd/etc/sysconfig/network-scripts/", press the Enter key, and continue to enter "ls" and press the Enter key to view the file.

3. Enter "vi ifcfg-ens33" and press the Enter key to confirm (NIC name may be different ). You can also enter "cd/etc/sysconfig/network-scripts/ifcfg-ens33" in step 2 to edit the file directly.

4. Check the last item (in the blue box) and find it as "ONBOOT = no ".

5. press "I" to enter the editing status, change "no" in the last line to "yes", Press "ESC" to exit the editing status, and enter ": x" to save and exit.

6. Enter "service network restart" to restart the service, or enter "systemctl restart netwrok ".

7. Enter "ip addr" again to view the ip address.

Set static IP addresses

8. Enter "cd/etc/sysconfig/network-scripts/", press the Enter key, continue to enter "ls", press the Enter key to view the file, and determine the network Card Name.

9. Enter "vi ifcfg-ens33" and press the Enter key to confirm (NIC name may be different ). If you know the NIC name, you can directly enter "cd/etc/sysconfig/network-scripts/ifcfg-ens33" to edit the file.

10. press "I" to enter the editing status and set it to "BOOTPROTO = 'static". (DHCP is prohibited if it is set to none, and static IP addresses are enabled, if it is set to dhcp, it is to enable the DHCP service), and modify the other part for your settings. In this example, It is 192.168.1.200/24, GW: 192.168.1.1. You can configure the IPV6 part as needed.

Note: NM_CONTROLLED = no and ONBOOT = yes can be set as needed.

11. Press "ESC" to exit the editing status, enter ": x" to save and exit, enter "service network restart" to restart the service, and enter "ifconfig" to view the network configuration.

12. if you need to set DNS (you need to set NM_CONTROLLED = no in step 1), enter "vi/etc/resolv. conf and press enter to execute the command (if DNS has been configured in step 1, skip this step ).

13. Enter the DNS server address in this file (in this example, Guangdong Telecom is used as an example, or enter the DNS address of the router) and save and exit.

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.