Home >Operation and Maintenance >CentOS >How to set ip in centos7

How to set ip in centos7

下次还敢
下次还敢Original
2024-04-07 21:06:241044browse

How to configure the IP address in CentOS 7: 1. Edit the network configuration file; 2. Set the IP address and network mask; 3. Set the gateway (optional); 4. Enable network services; 5. Verify IP address.

How to set ip in centos7

How to configure an IP address in CentOS 7

To configure an IP address in CentOS 7, follow these steps:

1. Edit the network configuration file

<code class="shell">vi /etc/sysconfig/network-scripts/ifcfg-eth0</code>

2. Set the IP address and network mask

<code>IPADDR=192.168.0.20
NETMASK=255.255.255.0</code>

3. Set the gateway (optional)

If you need to access through the gateway For other networks, please set up the gateway:

<code>GATEWAY=192.168.0.1</code>

4. Enable network services

<code>systemctl start network</code>

5. Verify IP address

To verify that the IP address has been configured correctly, run the following command :

<code class="shell">ifconfig eth0</code>

You should see the following output:

<code>eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.20  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe4f:f2b2  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4f:f2:b2  txqueuelen 1000  (Ethernet)
        RX packets 321  bytes 31134 (30.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 292  bytes 31329 (30.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0</code>

where inet 192.168.0.20 represents the assigned IP address.

The above is the detailed content of How to set ip in centos7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn