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 18.104.22.168 with netmask 255.255.255.0, gateway 22.214.171.124, DNS 126.96.36.199, the content will be like
NM_CONTROLLED="yes" DEVICE="enp2s0" BOOTPROTO=static ONBOOT="yes" IPADDR=188.8.131.52 NETMASK=255.255.255.0 GATEWAY=184.108.40.206 DNS1=220.127.116.11
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.