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.
To configure an IP address in CentOS 7, follow these steps:
<code class="shell">vi /etc/sysconfig/network-scripts/ifcfg-eth0</code>
<code>IPADDR=192.168.0.20 NETMASK=255.255.255.0</code>
If you need to access through the gateway For other networks, please set up the gateway:
<code>GATEWAY=192.168.0.1</code>
<code>systemctl start network</code>
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!