Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to set static IP address for CentOs

Shulou Source: shulou.com Published: 2022-05-31 11:41:24 09月23日 Update

This article mainly introduces CentOs how to set static IP address related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this CentOs how to set static IP address article, let's take a look.

1. Modify the configuration of the network card

Edit: vi / etc/sysconfig/network-scripts/ifcfg-eth0

Device=eth0 # describes the device alias corresponding to the Nic, for example, it is eth0 in the file of ifcfg-eth0

Bootproto=static # sets the way the network card obtains the ip address. The possible options are static,dhcp or bootp, corresponding to the statically specified ip address, the ip address obtained through the dhcp protocol, and the ip address obtained through the bootp protocol.

Subnet broadcast address corresponding to broadcast=192.168.0.255 #

Physical address of the network card corresponding to hwaddr=00:07:e9:05:e8:b4 #

Ipaddr=12.168.0.33 # if you set the way for the Nic to obtain the ip address statically, this field specifies the ip address corresponding to the Nic

The network mask for the netmask=255.255.255.0 # Nic

Network=192.168.0.0 # Network address corresponding to the Nic

two。 Modify gateway configuration

Edit: vi / etc/sysconfig/network modified as follows:

Networking=yes (indicates whether the system uses a network, which is generally set to yes. If set to no, the network cannot be used, and many system services will not start)

Hostname=centos (set the hostname of this machine, which corresponds to the hostname set in / etc/hosts)

Gateway=192.168.0.1 (sets the ip address of the gateway connected locally.)

When I modify it here and open it for editing, I already have the first three items by default, so only gateway has been added.

3. Modify dns configuration

Edit: vi / etc/resolv.conf modified as follows:

Nameserver is the ip address of the dns server, the first is the preferred, and the second is the backup.

4. Restart network services

Execute the command:

Service network restart

Or

/ etc/init.d/network restart, this is the end of the article on "how to set a static IP address for CentOs". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to set static IP address in CentOs". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Address network card static network host knowledge service configuration content method article system gateway native value alias command field simple operation file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Shulou Tech Info Docker MariaDB