How to configure a static IP address on CentOS 7 / RHEL 7
I am a new sysadmin and CentOS user. My system is configured to use DHCP. How can I switch from DHCP to static IP address on CentOS 7 desktop system? How do I setup a static TCP/IP address on my CentOS Linux 7 or Red Hat Enterprise Linux 7 server using command line option?
On CentOS 7 or RHEL 7 one need to use the NetworkManager daemon. It attempts to make networking configuration and operation as painless and automatic as possible by managing the primary network connection and other network interfaces, like Ethernet, WiFi, and Mobile Broadband devices. In this quick tutorial you will learn about configuring a network interface using ifcfg files located in /etc/sysconfig/network-scripts/ directory in a CentOS 7 and RHEL 7:
Create a file named /etc/sysconfig/network-scripts/ifcfg-eth0 as follows:
How do I configure an eth0 interface with static network settings (method # 1)?
To configure an eth0 interface with static network settings using ifcfg files, edit or create a file with name ifcfg-eth0 in the /etc/sysconfig/network-scripts/ directory as follows: # vi /etc/sysconfig/network-scripts/ifcfg-eth0 Update/edit as follows for static IP configuration:
# Server IP #
# Subnet #
# Set default gateway IP #
# Set dns servers #
# Disable ipv6 #
# This is system specific and can be created using 'uuidgen eth0' command #
Save and close the file. You do not need to specify the network or broadcast address as this is calculated automatically by the system. To restart networking service, enter: # systemctl restart network
Verify new IP settings: # ip a s eth0 Verify new routing settings: # ip r Verify DNS servers settings: # cat /etc/resolv.conf Verify the internet connectivity: # ping -c 3 sxi.io # ping -c 4 google.com Sample session:
How do I configure an eth0 interface with static network settings using Network Manager (method # 2)?
You need to use the nmtui command. It is a curses?based TUI application for interacting with NetworkManager. To show a connection editor that supports adding, modifying, viewing and deleting connections. To view or setup a static IP using this tool for eth0, enter: # nmtui edit eth0 Sample outputs:
The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.