How to set the static IP address for CentOS 7/Fedora 22+ is introduced in this post. Here, we assume the Linux is using NetworkManager to manage the network. All steps are done as root.
Find the interface you want to set the address ∞
lists all interfaces.
Find the interface name to set, such as
Edit the interface’s configuration file ∞
NAME, the configuration file is stored in
/etc/sysconfig/network-scripts/ifcfg-NAME. For the above example of
enp2s0, the configuration file is
As an example, to set its IP to 188.8.131.52 with netmask 255.255.255.0, gateway 184.108.40.206, DNS 220.127.116.11, the content will be like
NM_CONTROLLED="yes" DEVICE="enp2s0" BOOTPROTO=static ONBOOT="yes" IPADDR=18.104.22.168 NETMASK=255.255.255.0 GATEWAY=22.214.171.124 DNS1=126.96.36.199
Restart network/NetworkManager services ∞
You will need to restart the network/Networkmanager services to make the new configuration take effect
# systemctl restart network.service # systemctl restart NeworkManager.service
Then you can use
ifconfig -a again to verify whether the IP is set successfully.