How To Set Static IP and Manage Services in RHEL

Configuring Network Static IP Address and Manage Services

In this article we are going to learn how to Configure Network Static IP Address and manage services on Red Hat Enterprise Linux.

Requirements:

  • It is necessary that you have already installed RHEL/CentOS 7.0
  • Active RHEL 7.0 Subscriptions and Functional Repositories

To Set Hostname and Configure Static IP

Enter the following command to open the path /etc/sysconfig/network-scripts/ and assign static IP.

[root@linuxhelp ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736

To edit file, before that check BOOTPROTO is set to static, ONBOOT statement is set as YES and not to change HWADDR and UUID default values. After making changes save and close the file.

TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=d097dd2f-de95-43e9-a039-777feb318ff5
ONBOOT=yes
HWADDR=00:0C:29:FF:72:DE
IPADDR0=192.168.5.198
PREFIX0=24
GATEWAY0=192.168.5.1
DNS1=8.8.8.8
DOMAIN=8.8.4.4
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

To Enable DNS servers, just edit the resolv.conf file.

[root@linuxhelp ~]# vim /etc/resolv.conf
nameserver statement, add your DNS servers.
nameserver 8.8.8.8
nameserver 8.8.4.4

To alter the system hostname, just edit the /etc/hostname file and Hosts file.

[root@linuxhelp ~]#  vim /etc/hostname
linuxhelp.com
[root@linuxhelp ~]# vim /etc/hosts

After the hostname is set you can check whether it is fully qualified domain name by running hostname -f command.

[root@linuxhelp ~]# hostname -s
linuxhelp
[root@linuxhelp ~]# hostname -f
Linuxhelp1.com

Usage of Network Manager Text User Interface (nmtui)

The ‘ nmtui’ is a tool which gives a GUI interface to configure networking by controlling Network Manager, which aids editing advanced network settings such as activate or disable a connection, edit WI-FI connections, assign static IP addresses to Network Interfaces, create advanced Network interfaces like InfiniteBand, bridge, VLAN, bond.

To install nmtui use yum command.

[root@linuxhelp ~]#  yum install NetworkManager-tui

To start nmtui, execute nmtui command and use arrow keys to navigate and click Enter to select an option.

[root@linuxhelp ~]#  nmtui


You can directly edit the connection by mentioning the device name.

[root@linuxhelp ~]#  nmtui edit eno16777736
[root@linuxhelp ~]#  nmtui connect eno16777736

‘ eno16777736’ is my network interface name. You have to use your systems n/w interface name.

Network Interface is configured with a static IP address, so now restart your network and use ifconfig or ip command to view IP and finally test configuration using ping.

[root@linuxhelp ~]# systemctl restart network

After reboot use the new static IP configured to execute remote login with SSH.

[root@linuxhelp ~]# service network status
Configured devices:
lo Auto_Ethernet eno16777736
Currently active devices:
lo eno16777736
[root@linuxhelp ~]# ifconfig
eno16777736: flags=4163< UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 192.168.5.198 netmask 255.255.255.0 broadcast 192.168.5.255
inet6 fe80::20c:29ff:feff:72de prefixlen 64 scopeid 0x20 ether 00:0c:29:ff:72:de txqueuelen 1000 (Ethernet)
RX packets 540871 bytes 808783217 (771.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 295078 bytes 20100183 (19.1 MiB)
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
loop txqueuelen 0 (Local Loopback)
RX packets 154 bytes 12440 (12.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 154 bytes 12440 (12.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@linuxhelp ~]# ip addr show
1: lo: < LOOPBACK,UP,LOWER_UP>  mtu 65536 qdisc noqueue state UNKNOWN
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: eno16777736: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ff:72:de brd ff:ff:ff:ff:ff:ff
inet 192.168.5.198/24 brd 192.168.5.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feff:72de/64 scope link
valid_lft forever preferred_lft forever

To disable Unwanted System Services

To check the unwanted services we need to install net-tools and lsof tools.

[root@linuxhelp ~]# yum install net-tools
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* extras: centos.webwerks.com
* updates: centos.webwerks.com
Resolving Dependencies
-->  Running transaction check
--->  Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed
.
.
.
Installed:
net-tools.x86_64 0:2.0-0.17.20131004git.el7
Complete!
[root@linuxhelp ~]# yum install lsof
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* extras: centos.webwerks.com
* updates: centos.webwerks.com
Resolving Dependencies
-->  Running transaction check
--->  Package lsof.x86_64 0:4.87-4.el7 will be installed
.
.
.
Installed:
lsof.x86_64 0:4.87-4.el7
Complete!

To show list of sockets

After installation, execute “ netstat” or “ lsof” command to check what services are running on server.

[root@linuxhelp ~]# lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
avahi-dae 774 avahi 12u IPv4 18732 0t0 UDP *:mdns
avahi-dae 774 avahi 13u IPv4 18733 0t0 UDP *:49742
chronyd 817 chrony 1u IPv4 17905 0t0 UDP *:ntp
chronyd 817 chrony 2u IPv6 17906 0t0 UDP *:ntp
chronyd 817 chrony 3u IPv4 17907 0t0 UDP localhost:323
chronyd 817 chrony 5u IPv6 17908 0t0 UDP localhost:323
sshd 1637 root 3u IPv4 21843 0t0 TCP *:ssh (LISTEN)
sshd 1637 root 4u IPv6 21845 0t0 TCP *:ssh (LISTEN)
.
.
.
master 2249 root 14u IPv6 22540 0t0 TCP localhost:smtp (LISTEN)
cupsd 3025 root 10u IPv6 26370 0t0 TCP localhost:ipp (LISTEN)
cupsd 3025 root 11u IPv4 26371 0t0 TCP localhost:ipp (LISTEN)
yum 3678 root 6u IPv4 28945 0t0 UDP 192.168.5.196:59039-> google-public-dns-a.google.com:domain
urlgrabbe 4260 root 6u IPv4 31443 0t0 TCP 192.168.5.196:56556-> 14.139.62.20:http (ESTABLISHED)

To show list of sockets with their program name, use netstat command.

[root@linuxhelp ~]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2249/master
tcp 0 0 0.0.0.0:38925 0.0.0.0:* LISTEN 1799/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1639/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1637/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3025/cupsd
.
.
.
udp 0 0 0.0.0.0:47457 0.0.0.0:* 1799/rpc.statd
udp6 0 0 :::111 :::* 1639/rpcbind
udp6 0 0 :::123 :::* 817/chronyd
udp6 0 0 :::784 :::* 1639/rpcbind
udp6 0 0 ::1:323 :::* 817/chronyd
udp6 0 0 :::46476 :::* 1799/rpc.statd

To disable service

To check the status of the service use systemctl command.

[root@linuxhelp ~]# systemctl status sshd
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service  enabled)
Active: active (running) since Fri 2016-04-15 10:48:43 IST  4h 39min ago
Main PID: 1637 (sshd)
CGroup: /system.slice/sshd.service
??1637 /usr/sbin/sshd -D
Apr 15 10:48:43 linuxhelp systemd[1]: Started OpenSSH server daemon.
Apr 15 10:48:43 linuxhelp sshd[1637]: Server listening on 0.0.0.0 port 22.
Apr 15 10:48:43 linuxhelp sshd[1637]: Server listening on :: port 22.
[root@linuxhelp ~]# systemctl stop sshd
[root@linuxhelp ~]# systemctl disable sshd
rm ' /etc/systemd/system/multi-user.target.wants/sshd.service' 
[root@linuxhelp ~]# systemctl status sshd
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service  enabled)
Active: active (dead)

If you need to get a list of all started services run service &ndash status-all command.

[root@linuxhelp ~]# service --status-all
iprdump.service - LSB: Start the ipr dump daemon
Loaded: loaded (/etc/rc.d/init.d/iprdump)
Active: active (running) since Fri 2016-04-15 10:48:31 IST  4h 48min ago
Main PID: 853 (iprdump)
CGroup: /system.slice/iprdump.service
??853 /sbin/iprdump --daemon

Apr 15 10:48:31 linuxhelp iprdump[847]: Starting iprdump: [ OK ]
Apr 15 10:48:31 linuxhelp systemd[1]: Started LSB: Start the ipr dump daemon.
iprinit.service - LSB: Start the ipr init daemon
Loaded: loaded (/etc/rc.d/init.d/iprinit)
Active: active (running) since Fri 2016-04-15 10:48:31 IST  4h 48min ago
Main PID: 844 (iprinit)
CGroup: /system.slice/iprinit.service
??844 /sbin/iprinit --daemon

Apr 15 10:48:30 linuxhelp systemd[1]: Starting LSB: Start the ipr init daemon...
Apr 15 10:48:31 linuxhelp iprinit[802]: Starting iprinit: [ OK ]
Apr 15 10:48:31 linuxhelp systemd[1]: Started LSB: Start the ipr init daemon.
Hint: Some lines were ellipsized, use -l to show in full.
iprupdate.service - LSB: Start the iprupdate utility
Loaded: loaded (/etc/rc.d/init.d/iprupdate)
Active: active (running) since Fri 2016-04-15 10:48:31 IST  4h 48min ago
Main PID: 839 (iprupdate)
CGroup: /system.slice/iprupdate.service
??839 /sbin/iprupdate --daemon

Apr 15 10:48:30 linuxhelp systemd[1]: Starting LSB: Start the iprupdate uti.....
Apr 15 10:48:31 linuxhelp iprupdate[766]: Starting iprupdate: [ OK ]
Apr 15 10:48:31 linuxhelp systemd[1]: Started LSB: Start the iprupdate utility.
Hint: Some lines were ellipsized, use -l to show in full.
netconsole module not loaded
Configured devices:
lo Auto_Ethernet eno16777736
Currently active devices:
lo eno16777736

To list all the enabled and disabled services use list-unit-files option.

[root@linuxhelp ~]# systemctl list-unit-files
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.mount static
proc-fs-nfsd.mount static
proc-sys-fs-binfmt_misc.mount static
tmp.mount disabled
var-lib-nfs-rpc_pipefs.mount static
brandbot.path disabled
cups.path enabled
systemd-ask-password-console.path static
session-2.scope static
abrt-ccpp.service enabled
abrt-oops.service enabled
abrt-pstoreoops.service disabled
abrt-vmcore.service enabled
abrt-xorg.service enabled
abrtd.service enabled

To manage services, execute “ systemctl” command with -H option.

[root@linuxhelp ~]# systemctl -H linuxhelp.com status sshd

This command will check the status of sshd service in remote host “ linuxhelp.com

.

FAQ
Q
How can I monitor a Broadcast storm?
A
OpManager helps you monitor switch ports for traffic, utilization and errors. By presenting accurate information on port traffic and utilization, OpManager helps you identify top talkers on the LAN and detect potential ‘Broadcast Storms’ and pro–actively prevent the same.
Q
is there any simple command to delete ip address from a network interface?
A
Yes, use command ip addr flush dev eth0
Q
How to configure two ip address in same interface?
A
You can follow this link, https://www.linuxhelp.com/how-to-create-multiple-ip-address-to-single-network-interface/
Q
How to set IP in Ubuntu using cmd
A
you need to edit this file /etc/network/interfaces for setting IP address
Q
I want to install angry ip scanner in ubuntu
A
follow this link, https://www.linuxhelp.com/how-to-install-angry-ip-scanner-on-ubuntu-16-04/