configuring static ip address in centos 7
By default CentOS interface is configured to receive IP from DHCP server.generally centos used for server purpose. If you want to use it as a server and would like to access it remotely then you must be configured static ip. Here I will show you how to configure static IP address in CentOS system.
This tutorial describes on how to configure static ip address on centos 7 system
First we will check available network interfaces on system.we can chek it through following command
[root@localhost ~]# ip a
or
[root@localhost ~]# ifconfig -a
Also Read -> How to Install and Configure Redis Server on Centos 7
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:08:d7:55 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.12/24 brd 192.168.0.255 scope global noprefixroute dynamic enp0s3
valid_lft 6581sec preferred_lft 6581sec
inet6 fe80::ac6b:3c74:553a:fb40/64 scope link noprefixroute
valid_lft forever preferred_lft forever
now go to network interface which is located under /etc/sysconfig/network-scripts directory.you can check default dhcp settings using below command.
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
now you can add below settings to above file
IPADDR=192.168.30.100
NETMASK=255.255.255.0
GATEWAY=192.168.30.1
DNS1=192.168.30.1
DNS2=8.8.8.8
Also change below settings
BOOTPROTO=dhcp
TO
BOOTPROTO=static
change below setting to Activate on boot
ONBOOT=no
TO
ONBOOT=yes
Then restart network service with following command.
[root@localhost ~]# systemctl restart network
Also Read -> How to Install and Configure Redmine on Centos 7
using nmtui
you can also use nmtui, its an text-based user interface to configure network interfaces.
open terminal and type nmtui
select network interface and then Edit
and then set ip address
now restart network service using systemctl
systemctl restart network
now check static ip using ifconfig command
[root@localhost ~]# ifconfig -a
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.30.100 netmask 255.255.255.0 broadcast 192.168.30.255
inet6 fe80::ac6b:3c74:553a:fb40 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:08:d7:55 txqueuelen 1000 (Ethernet)
RX packets 1320 bytes 153677 (150.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 600 bytes 85969 (83.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 4 bytes 344 (344.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 344 (344.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
also check dns entries in resolv.conf file
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.30.1
nameserver 8.8.8.8
Finally you can ping with google or any other site to verify static ip and dns settings are perfect.
[root@localhost ~]# ping google.com
That's it. Now you have successfully configured static ip address on centos 7 system.
Also Read -> How to Configure NIC bonding on Centos 7