In this CentOS Linux version 7 or Red Hat Enterprise Linux version 7 tutorial we will take a look at the network service using command line options. We for instance look how to stop/start/restart or get the status of the network service.
From version 7 of RHEL (CentOS, Fedora, Scientific linux) systemd is used. It replaces Upstart as the default init system and can be used to control services (service and system manager) of the Linux operating system.
Older version of RHEL/CentOS where using the system V method of controlling services (daemons). In these versions the init scripts where located in the /etc/rc.d/init.d directory. In CentOS/RHEL 7 these scripts have been replaced with service units.
Networking Service Name and Control
To control the networking service you need to make use of network.service or network (the system will place .service for you, but it is better to learn from the start to add .service yourself).
To control the systemd system you must use the new command systemctl. For instance to ask for the status of the network.service:
$ sudo systemctl status network.service network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d/init.d/network) Active: active (exited) since Fri 2014-10-24 19:19:23 CEST; 35min ago Process: 744 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS) Oct 24 19:19:22 web-server.example.com systemd: Starting LSB: Bring up/down networking... Oct 24 19:19:23 web-server.example.com network: [ OK ] Oct 24 19:19:23 web-server.example.com network: Bringing up interface eth0: [ OK ] Oct 24 19:19:23 web-server.example.com systemd: Started LSB: Bring up/down networking.
To stop, start or restart the network service on RHEL7 you can do the following:
$ sudo systemctl stop network.service $ sudo systemctl start network.service $ sudo systemctl restart network atorvastatin 20 mg tablet.service
Below you’ll find the output of the systemctl restart network.service command:
$ sudo systemctl restart network.service $
As you can see, as long as the command is successful nothing will be shown.
With the journalctl tool you can access the journal logs. The tool has also a live view option, so you can supervise the log messages in real time as new entries are continuously printed as they appear (just like tail -f for example). You can start journalctl in live view mode by typing the following in one session:
$ sudo journalctl -f
Repeat the previous systemctl command to restart the network service by typing the command in a separate session. Watch the journalctl live view session to see what happens.
The service and chkconfig Commands
You should note that the service and chkconfig commands are still available. They also still work as expected, but they are only included for backwards compatibility. For instance the iptables command is still available, but you should use firewalld and firwall-cmd.
You should learn the new commands and ways that are provided in RHEL7 and CentOS7, because it is possible that in future releases some of the old commands can be dropped.
That’s all for this tutorial.