Skip to main content

OS - How to change the hostname


In this post I'm sharing how to address of the most repetitive tasks after fresh build or clone a VM. Eg. for database  pre install tasks .

First of all , I will how to change the hostname.
Next, I will setup the local naming resolution.
At end, how to play with the firewall.





Change hostname
- the hostname is key including for server provisioning and orchestration, the server name can be changed using the hostnamectl command. Lets see bellow some examples.





root@Unknown-08-00-27-26-48-7d # hostnamectl status
Static hostname: localhost.localdomain
Transient hostname: Unknown-08-00-27-26-48-7d
Icon name: computer-vm
Chassis: vm
Machine ID: d5a9e3e4d118804089e345228a189582
Boot ID: f76e3fc1c76f49028a1583b90eb01511
Virtualization: kvm
Operating System: Oracle Linux Server 7.7
CPE OS Name: cpe:/o:oracle:linux:7:7:server
Kernel: Linux 4.14.35-1902.3.2.el7uek.x86_64
Architecture: x86-64




root@Unknown-08-00-27-26-48-7d # hostnamectl set-hostname wls.example.com




root@Unknown-08-00-27-26-48-7d # hostnamectl status
Static hostname: wls.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: d5a9e3e4d118804089e345228a189582
Boot ID: f76e3fc1c76f49028a1583b90eb01511
Virtualization: kvm
Operating System: Oracle Linux Server 7.7
CPE OS Name: cpe:/o:oracle:linux:7:7:server
Kernel: Linux 4.14.35-1902.3.2.el7uek.x86_64
Architecture: x86-64




Setup local name resolution

TIP - I'm getting the IP (192.168.1.118) from the router ( who acts as DHCP). If the VM was cloned, is recommended to generate a new MAC address. With a different MAC the server will receive other available IP.









Humans call each-other by name not by mobile number neither ID number. Is good idea to do the same with server, for that we need a mechanism called "naming resolution". I will leave the details for that topic out this post. For the immediate propose, let's say it could be like a mobile contact list ( name / number).

As mentioned above, i'm getting the IP (192.168.1.118), that information is listed is in a file called "hosts":

Linux : /etc/hosts
Windows : %Systemroot%\System32\drivers\etc\hosts

Backing to Linux command line.





root@Unknown-08-00-27-26-48-7d # ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.118 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::144a:40e:d8a5:5e46 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:26:48:7d txqueuelen 1000 (Ethernet)
RX packets 2703552 bytes 3841742453 (3.5 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 165177 bytes 11675354 (11.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<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 48 bytes 4080 (3.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 4080 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:c1:d2:9c txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

root@Unknown-08-00-27-26-48-7d # cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6




root@Unknown-08-00-27-26-48-7d # echo "192.168.1.118 wls.example.com wls" >> /etc/hosts




root@Unknown-08-00-27-26-48-7d # cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.118 wls.example.com wls




Test the IP conectivity / name resoution





root@Unknown-08-00-27-26-48-7d # ping wls
PING wls.example.com (192.168.1.118) 56(84) bytes of data.
64 bytes from wls.example.com (192.168.1.118): icmp_seq=1 ttl=64 time=0.105 ms
64 bytes from wls.example.com (192.168.1.118): icmp_seq=2 ttl=64 time=0.071 ms
^C
--- wls.example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1054ms
rtt min/avg/max/mdev = 0.071/0.088/0.105/0.017 ms




Manage Firewall

To reduce / avoid time on troubleshooting mainly within weblogic ( it has lot of no well know ports used for internal communications) is also recommended to stop / disable the firewall.





root@wls #  systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-04-09 23:24:47 BST; 4s ago
Docs: man:firewalld(1)
Main PID: 5306 (firewalld)
Tasks: 2
CGroup: /system.slice/firewalld.service
└─5306 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Apr 09 23:24:46 wls.example.com systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 09 23:24:47 wls.example.com systemd[1]: Started firewalld - dynamic firewall daemon.




root@wls #  systemctl stop firewalld

root@wls # systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2020-04-09 23:26:10 BST; 4s ago
Docs: man:firewalld(1)
Process: 5306 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 5306 (code=exited, status=0/SUCCESS)

Apr 09 23:26:09 wls.example.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 09 23:26:10 wls.example.com systemd[1]: Stopped firewalld - dynamic firewall daemon.




root@wls #  systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

root@wls # systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)

Apr 09 23:26:09 wls.example.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 09 23:26:10 wls.example.com systemd[1]: Stopped firewalld - dynamic firewall daemon.




Conclusion, these three tasks simplify the system administrator's life, help to prevent issues and time wasting on troubleshooting in VM Lab environments.

Further reading ..

CONFIGURING HOST NAMES USING HOSTNAMECTL(RedHat)
MANAGING SYSTEM SERVICES (RedHat)





Thank you for reading, hope this post was helpful.
Rogerio






Comments

Popular posts from this blog

DB - How to monitor Oracle datapump jobs

These days there is lot of work around database migrations not only but mainly to cloud providers. One of the ways to migrate Oracle databases is using data pump (expdp/impdp). In general works fine, it allows an easy way to bring the database even different OS. It is always good to monitor the progress, to know where we are and estimate how long we are from the end. In this post, I am sharing some queries to help with database monitoring progress. The queries can be easily tailed to various scenarios. Starting with a simple one - the track the number of objects loaded during an import operation. When there is a massive amount of errors during the import. Drop and run the import again. The bellow query can be useful also to monitor the number of objects if we are dropping the users. Here, I’m making the assumption there were no other database activity in progress on the last 24 hours. select owner, count(0) from dba_objects where owner in ( select username from dba_users where created...

VM - Partilhar Pastas Windows - Linux

Neste post escrevo como partilhar pastas entre Windows (Host) e uma VM Guest, neste caso Linux. Ha algumas formas de fazer isto, esta parece me a mais facil. Seleccionar a Pasta Windows Na consola Virtual Box > Devices > Shared Folder Seleccionar a pasta windows para partilhar no Linux   O   Montar a pasta Windows na VM Ha duas opcoes : 1) Reiniciar a VM (Auto-mount) 2) Linha de comando [root@host ~]# mkdir -p /u01/stage/win_ebs_sw [root@host ~]# chmod 777 /u01/stage/win_ebs_sw [root@host ~]# mount -t vboxsf Oracle_EBS /u01/stage/win_ebs_sw/ [root@host ~]# ls /u01/stage/win_ebs_sw ebs_weblogic_webtier [root@host ~]# df -h /u01/stage/win_ebs_sw Filesystem Size Used Avail Use% Mounted on Oracle_EBS 895G 494G 401G 56% /u01/stage/win_ebs_sw Guardar a Configuracao no /etc/fstab para tornar as alteracoes permanentes. [root@host ~]# echo "Oracle_EBS /u01/stage/win_ebs_sw vboxsf defaults 0 0" >> /etc/fstab [root@host ~]# cat /etc/fstab # /etc/...

DB – How to monitor Oracle database long ops ?

As DBAs, some questions we are often asked and to be fair we ask ourselfs when we are doing massive operations, are : Is the database doing something? How long the database takes to complete the task? There a data dictionary view, GV$SESSION_LONGOPS whom is really usefull for monitoring and to provide estimated time to get the task done. Starting with a first example, a query for general propose . set lines 240 col message form a100 col opname form a50 select * from ( select round(l.sofar/l.totalwork*100,2) as complete, --l.* l.sid, --l.opname, l.message, l.start_time, l.time_remaining/60 "minuts remaining", l.elapsed_seconds from gv$session_longops l where totalwork !=0 ) where complete < 100; The view is also usefull on specific operations such as Oracle Recovery Manager (RMAN) jobs monitoring, this query returns information about backup,restore and recovery. select sid, serial#,opname, context, sofar, totalwork, round(sofar/totalwork*100,2) "%_complet...