In this post, we are continuing with the commands that are used for Linux system administration.
How to change the hostname
1) [For RedHat and Centos] Using a text editor open the file /etc/sysconfig/network and Modify the HOSTNAME= value to match your server’s new name
1 |
# sudo gedit /etc/sysconfig/network |
Sample entry after editing:
1 2 3 4 |
$ cat /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=ibmppc1.example.com |
2) Run the below command:
1 |
# hostname NEW_NAME_HERE |
This will change the hostname until next reboot. The change won’t be visible immediately in your current terminal. Start a new terminal to see the new hostname.
3) For internal networking, change the host that is associated with the main IP address for your server at /etc/hosts file
1 2 3 4 5 |
127.0.0.1 localhost localhost.localdomain 123.45.67.89 hostname.domain.com hostname ~ |
4) Also change the hostname at /etc/hostname
1 |
$ sudo vi /etc/hostname |
5) Finally, restart networking or your computer to apply the changes.
Example :
1 |
$ sudo /etc/init.d/network restart |
How to view network connections
The “netstat” command can be used for viewing the network connections. Using this command, it is possible to look for the ports your server is listening on and the programs behind those ports.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ netstat -ape | more (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name tcp 0 0 localhost:mysql *:* LISTEN mysql 11865 - tcp 0 0 *:netbios-ssn *:* LISTEN root 11620 - tcp 0 0 alban-ThinkPad-T:domain *:* LISTEN root 12080 - tcp 0 0 192.168.122.1:domain *:* LISTEN root 17841 - tcp 0 0 *:ssh *:* LISTEN root 11667 - tcp 0 0 localhost:ipp *:* LISTEN root 47289 - tcp 0 0 *:microsoft-ds *:* LISTEN root 11619 - tcp 0 0 192.168.0.196:38934 74-208-236-208.el:https ESTABLISHED alban 21856 2840/chrome tcp 1 0 192.168.0.196:37935 a184-25-67-247.de:https CLOSE_WAIT alban 42601 2840/chrome |
How to update local host aliases
In order to update the local host aliases, edit the file /etc/hosts. This has to be done by the user with root privilege. Also sudo can be used to update this file.
Format of each line :
IP_address <tab> your_domain <tab> alias
Example :
1 2 |
$ cat /etc/hosts 127.0.0.1 localhost.localdomain localhost |
How to shutdown
In order to properly shutdown a Linux machine, the command “shutdown” can be used. If many users are logged in, this command can be used with options as in the example given below :
1 |
# shutdown -h +2 "Going to shutdown for maintenance in 2 min" |
where +2 indicates that the system will shutdown in 2 minutes.
To shutdown immediately :
1 |
# shutdown -h now |
How to monitor user information
There are various Linux commands available for monitoring user information. Some of them are “who”, “w”, “users”, “groups”, “id” and “last”. The command “set” displays all the environment variables in the current user’s environment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
falcon@falcon-ThinkPad-T420 ~ $ who falcon tty8 2017-06-08 06:58 (:0) falcon pts/2 2017-06-08 07:05 (:0) falcon@falcon-ThinkPad-T420 ~ $ w 08:01:48 up 1:03, 2 users, load average: 0.30, 0.26, 0.19 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT falcon tty8 :0 06:58 1:03m 51.89s 0.17s cinnamon-session --session cinnamon falcon pts/2 :0 07:05 0.00s 0.06s 0.00s w falcon@falcon-ThinkPad-T420 ~ $ users falcon falcon falcon@falcon-ThinkPad-T420 ~ $ groups falcon adm cdrom sudo dip plugdev lpadmin sambashare libvirtd falcon@falcon-ThinkPad-T420 ~ $ id uid=1000(falcon) gid=1000(falcon) groups=1000(falcon),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),110(sambashare),125(libvirtd) falcon@falcon-ThinkPad-T420 ~ $ last falcon pts/2 :0 Thu Jun 8 07:05 still logged in falcon tty8 :0 Thu Jun 8 06:58 still logged in reboot system boot 3.19.0-32-generi Thu Jun 8 06:58 - 08:02 (01:03) falcon tty8 :0 Tue Jun 6 20:07 - down (02:05) reboot system boot 3.19.0-32-generi Tue Jun 6 20:06 - 22:13 (02:06) falcon pts/1 :0 Tue Jun 6 10:05 - 11:29 (01:24) falcon tty8 :0 Tue Jun 6 09:44 - down (01:45) reboot system boot 3.19.0-32-generi Tue Jun 6 09:44 - 11:29 (01:45) falcon tty8 :0 Mon Jun 5 20:54 - down (01:47) reboot system boot 3.19.0-32-generi Mon Jun 5 20:53 - 22:42 (01:48) wtmp begins Sun Jun 4 23:59:14 2017 falcon@falcon-ThinkPad-T420 ~ $ set BASH=/bin/bash BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:progcomp:promptvars:sourcepath BASH_ALIASES=() BASH_ARGC=() BASH_ARGV=() BASH_CMDS=() BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d BASH_LINENO=() BASH_SOURCE=() BASH_VERSINFO=([0]="4" [1]="3" [2]="11" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu") BASH_VERSION='4.3.11(1)-release' CINNAMON_VERSION=2.8.8 CLUTTER_BACKEND=x11 |