How to configure static IP addresses in CentOS 7
When I was a beginner in Linux, I encountered a problem, that is, configuring the IP address of the NIC. The collection of relevant information was successfully configured. This is now recorded for convenience of memory.
Use the CD command to jump to the corresponding configuration file. The configuration command is cd/etc/sysconfig/network-scripts/
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
If you do not know the file, use the ls command to view it.
[root@localhost network-scripts]# ls ifcfg-eno16777736 ifdown-ib ifdown-ppp ifdown-tunnel ifup-ib ifup-plusb ifup-Team network-functionsifcfg-lo ifdown-ippp ifdown-routes ifup ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6ifdown ifdown-ipv6 ifdown-sit ifup-aliases ifup-ipv6 ifup-ppp ifup-tunnelifdown-bnep ifdown-isdn ifdown-Team ifup-bnep ifup-isdn ifup-routes ifup-wirelessifdown-eth ifdown-post ifdown-TeamPort ifup-eth ifup-plip ifup-sit init.ipv6-global
The first ifcfg-enoxxxxxxxx (here x indicates a number) is the configuration file, which can be used in the vi editor. Press I to enter the editing mode and modify the file.
[root@localhost network-scripts]# vi ifcfg-eno16777736 TYPE="Ethernet"BOOTPROTO="static"DEFROUTE="yes"PEERDNS="yes"PEERROUTES="yes"IPV4_FAILURE_FATAL="no"IPV6INIT="yes"IPV6_AUTOCONF="yes"IPV6_DEFROUTE="yes"IPV6_PEERDNS="yes"IPV6_PEERROUTES="yes"IPV6_FAILURE_FATAL="no"NAME="eno16777736"UUID="718afcbf-931e-4c0c-a23f-bfc3c13023c2"DEVICE="eno16777736"ONBOOT="yes"IPADDR0="xxx.xxx.xxx.xxx"NETMASK="xxx.xxx.xxx.xxx"GATEWAY="xxx.xxx.xxx.xxx"
After editing, enter: wq! Save and exit, and then enter
/etc/init.d/network restart
The static IP Address Configuration is successfully saved and takes effect.