To print epoch - The seconds that has passed since 1970-01-01 00:00:00 UTC, run the following command,
date +"%s" 1480572641Here %s tells date to print the epoch.
Tested on: CentOS 7, Debian 8, Ubuntu 16.04
To print epoch - The seconds that has passed since 1970-01-01 00:00:00 UTC, run the following command,
date +"%s" 1480572641Here %s tells date to print the epoch.
Tested on: CentOS 7, Debian 8, Ubuntu 16.04
In your system administration life time, suppose you're looking forward to edit a configuration file and it turns out that the file is not available. You forgot what package to install to have that file or what package contains that file. What would you do then? To get the answer, read this post.
To find out which package in the repository contains a specific file, you can use the repoquery command. The syntax to do that is,
repoquery -qf file_pathHere file_path is the file that you're looking for.
To check what package provides the file /etc/my.cnf, run the following command.
repoquery -qf /etc/my.cnfmariadb-libs-1:5.5.44-2.el7.centos.x86_64 mariadb-libs-1:5.5.44-2.el7.centos.i686
From the output, we can see that the packages that provides the specific file /etc/my.cnf is mariadb-libs.
Tested on: CentOS 7
To check what configuration files are associated with a specific package that is already installed on your system using rpm command, use the syntax as written below.
rpm -qc package_nameHere package_name is any package that is already installed on your system.
To check the configuration files that are associated with the package httpd, the Apache HTTP server, run the following command.
rpm -qc httpd/etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/userdir.conf /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.modules.d/00-base.conf /etc/httpd/conf.modules.d/00-dav.conf /etc/httpd/conf.modules.d/00-lua.conf /etc/httpd/conf.modules.d/00-mpm.conf /etc/httpd/conf.modules.d/00-proxy.conf /etc/httpd/conf.modules.d/00-systemd.conf /etc/httpd/conf.modules.d/01-cgi.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf/magic /etc/logrotate.d/httpd /etc/sysconfig/htcacheclean /etc/sysconfig/httpd
Tested on: CentOS 7
At times you need to know which package contains a specific file on rpm based Linux distros such as Fedora, RedHat(RHEL), CentOS, openSUSE, SLE etc. Read below to learn how.
Let's say you want to know what package provides the ip command. It's a two step process.
To find the ip binary location, run the following command.
which ip /sbin/ipThe location is /sbin/ip as it's seen from the output of 'which'.
To find the package that contains the binary /sbin/ip, run the following command.
rpm -qf /sbin/ip iproute-3.10.0-54.el7.x86_64From the output of 'rpm' command, you can see that the package is "iproute-3.10.0-54.el7.x86_64". So this is the package that we were looking for.
You can use any file path with 'rpm -qf' command. As long as the rpm database knows about the file. You will get a result.
Tested on: CentOS 7
Today I was looking at the /etc/sysconfig/network-scripts/ifcfg-enp0s3 file and I came across the line that says UUID. I was thinking what is UUID of a network interface? Then I started thinking about how to find UUIDs of network interfcaes. I looked on the internet but I got no solution. Then I thought of trying to find it myself using network management commands. I did find a solution.
To find the UUIDs of your network connection, run the following command.
nmcli connection showNAME UUID TYPE DEVICE virbr0 4e02750f-13d9-4662-bfc2-10f9ae1a71bd bridge virbr0 Wired connection 1 09066de3-7eb7-4ee1-9059-c651b6dff7a6 802-3-ethernet -- enp0s3 5144084b-0537-4e4b-9f15-065431bc6d38 802-3-ethernet --
From the output of this command, you can find the UUID of a connection on CentOS, Fedora, RedHat(RHEL), Ubuntu, Debian operating systems.
Tested on: CentOS 7, Ubuntu 16.04 LTS
If you're trying to mount network devices automatically at boot on Linux and your system is not booting correctly. This post is for you.
Today I was working with iscsi. I created portals, acls, luns, targets with targetcli. But when I tried to mount it automatically through fstab file on boot, my system wasn't booting. I looked online and I found that I had to change the mount option. I did and it worked. I am going to write what mount option I used in this post.
When my system wasn't booting, my /etc/fstab configuration file looked like this,
# # /etc/fstab # Created by anaconda on Thu Nov 24 03:07:55 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=0d83fc00-ee94-4741-8163-717418187f59 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=f246ba49-5772-4efc-bec2-28ff76f46f79 /root/mounts/sdb xfs defaults 0 0
Here UUID=f246ba49-5772-4efc-bec2-28ff76f46f79, this is the iscsi drive I was trying to mount. The mount option was "defaults". But to get it to work, I had to change the mount option to "_netdev". What this option does it, it attempts to mount this device after all the network connection is initialized.
So my working configuration looked like this,
# # /etc/fstab # Created by anaconda on Thu Nov 24 03:07:55 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=0d83fc00-ee94-4741-8163-717418187f59 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=f246ba49-5772-4efc-bec2-28ff76f46f79 /root/mounts/sdb xfs _netdev 0 0
Tested on: CentOS 7
This post is about how to open specific tcp and udp ports using the command firewall-cmd. So without further due, let's get started.
Let's say, I want to open the tcp ports 80 and 443 which are used by http and https protocol respectively.
To do that, run the following commands,
firewall-cmd --permanent --add-port=80/tcp firewall-cmd --permanent --add-port=443/tcp
Let's say, I want to open the udp port 53, which is used by bind dns service.
To do that, run the following command,
firewall-cmd --permanent --add-port=53/udpNow we have to reload firewall-cmd configurations. To do that, run the following command,
firewall-cmd --reloadTo verify that the commands worked, let's view the current opened port list,
firewall-cmd --list-ports 443/tcp 80/tcp 53/udpTested on: CentOS 7