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 configure an IP address in CentOS 7
To configure an IP address in CentOS 7, follow these steps:
1. Edit the network configuration file
1 | <code class = "shell" >vi /etc/sysconfig/network-scripts/ifcfg-eth0</code>
|
Copy after login
2. Set the IP address and network mask
1 2 | <code>IPADDR=192.168.0.20
NETMASK=255.255.255.0</code>
|
Copy after login
3. Set the gateway (optional)
If you need to access through the gateway For other networks, please set up the gateway:
1 | <code>GATEWAY=192.168.0.1</code>
|
Copy after login
4. Enable network services
1 | <code>systemctl start network</code>
|
Copy after login
5. Verify IP address
To verify that the IP address has been configured correctly, run the following command :
1 | <code class = "shell" >ifconfig eth0</code>
|
Copy after login
You should see the following output:
1 2 3 4 5 6 7 8 | <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>
|
Copy after login
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!