Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to get dynamic and static IP addresses in CentOS 7

Shulou Source: shulou.com Published: 2022-06-01 18:34:06 11月06日 Update

What this article shares with you is about how to obtain dynamic and static IP addresses in CentOS 7. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

Automatic acquisition of dynamic IP addresses

1. Enter "ip addr" and press enter to confirm that you cannot get IP (CentOS 7 does not have the ifconfig command by default), and record the name of the network card (ens33 in this case).

two。 Enter "cd / etc/sysconfig/network-scripts/" press enter to confirm, continue to enter "ls" press enter to view the file.

3. Enter "vi ifcfg-ens33" and press enter to determine (the name of the network card may be different). You can also type "cd / etc/sysconfig/network-scripts/ifcfg-ens33" to edit the file directly in the second step.

4. Look at the last item (in the blue box) and find it is "ONBOOT=no".

5. Press the "I" key to enter the editing state, change the last line "no" to "yes", then press the "ESC" key to exit the editing state, and enter ": X" to save the exit.

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

7. Type "ip addr" again, and you can now get the IP address automatically.

Set static IP address

8. Enter "cd / etc/sysconfig/network-scripts/" press enter key to confirm, continue to enter "ls" press enter key to view the file to determine the name of the network card.

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

10. Press "I" to enter the editing state, set it to "BOOTPROTO='static'" (if set to none, disable DHCP,static to enable static IP address, set to dhcp to enable DHCP service), and modify the other parts to your settings, in this case, 192.168.1.1, you can configure IPV6 part according to your needs. Note: NM_CONTROLLED=no and ONBOOT=yes can be set up according to your needs.

11. After confirming that it is correct, press "ESC" to exit the editing state, and enter ": X" to save the exit, enter "service network restart" to restart the service, and enter "ifconfig" to view the network configuration.

twelve。 If you need to set up DNS (you need to set NM_CONTROLLED=no in step 9), enter "vi / etc/resolv.conf" and press enter to execute the command (this step can be omitted if DNS has been configured in step 9).

13. Enter the DNS server address in this file (in this case Guangdong Telecom as an example, you can also enter the router DNS address) and save the exit.

The above is how to obtain dynamic and static IP addresses in CentOS 7. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Input address enter key name file static status network card service dynamic configuration different command more knowledge article part practical one line again Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Huawei macOS Linux