Daily tip

How do I troublshoot the CIFS client in Linux?

Please activate tracing and debugging of the module cifs.ko by running these commands as root

#echo 1 > /proc/fs/cifs/traceSMB
#echo 7 > /proc/fs/cifs/cifsFYI

Then run dmesg to check for info

Daily tip

How to add a VLAN ID to a network interface?

First check if the the kernel module 8021q is loaded with

$lsmod | grep 8021q

if it is not loaded, load the relative module with

#modprobe 8021q

Then either

vconfig add IF VLAN_ID

or

ip add link IF name IF.VLAN_ID type vlan id VLAN_ID

Where IF is the network card interface: eth0, eth1, ens33, etc.

And VLAN_ID is the ID of your VLAN

For example if the VLAN ID is 5 and the ethernet interface is eth1, you can either run

#vconfig add eth1 50

or

#ip add link eth1 name eth1.5 type vlan id 5

You must be root or have the appropriate root permissions.

Daily tip

How to display all hosts in the localnet using ARP protocol?


For example by using the tool arp-scan and the following manner:


#arp-scan –interface=eth0 –localnet

Daily tip

How do I change a line in a file without opening it?

By using sed, the stream editor. For example like below

#sed -i.bak ‘/^search/s/esample.com/example.com’ /etc/resolv.conf

You also create a backup copy with the .bak suffix

Daily tip

How to check if Linux booted in (U)EFI mode?

The directory /sys/firmware/efi is created. Also as usual you can get some info via the dmesg command.

Daily tip

Is it possible to access a service running in a docker container from Internet?

By default services running on a container are not accessible from outside, what you need to do, provided everything is configured correctly in terms of DNS, public IP and domain registration, is to publish a container port to the host as below.

#docker container run -d -p 80:80 apache

With the -d switch we run the container in background and
 -p container_port:host_port instructs the host to create a NAT rule to forward any request to the host port 80 to the internal container port 80.


Daily tip

How can I trace a full TCP segment for diagnosis purposes?

By installing tcpdump and using it with the below command syntax (you must be root or have sudo permissions).

#tcpdump -vvv [-i ] [port|host] -nnXSs 0

For instance, if you want to see in details what happens with any connection to and from the local web server (port 80) you type

#tcpdump -vvv -i any port 80 -nnXSs 0

Note that -i any means that tcpdump is listening on any network interface.

Daily tip

Today we will start our daily – hopefully – post with a trick or solution to common and uncommon Linux tasks and problems. So stay tuned! Note that all command lines prefixed with a # must be run as root, with a $ can be run by a normal user.

How to remove older kernel in linux?

Sometimes is necessary to free up some space, especially when the /boot directory is on a different partition with space constraints.

#yum install yum-utils

#package-cleanup –oldkernels –count=2

It will keep only two kernels and not remove the current running kernel; so make sure you are running the latest Kernel.

Dragora

Dragora is another distribution so called Libre, because all packages, drivers and kernels must be provided with their full source code and must be free of patents; also firmware binaries are not allowed if not coming with the relative source code.

The current stable version is the 2.2 and it has the following distinctive features.

  • Init system runit
  • Qi source and package system, exposed through the command pkg

Unfortunately it appears the project is not yet mature, for example we don’t have an online repo, installed packages can be inferred by looking at the /var/db/pkg folder, and last but not least, I don’t see any Enterprise package like a web Server.



Foremost – tool to recover deleted data

To recover data in Linux a well known software is for instance TestDisk, however this time I will mention an alternative maybe not well known: Foremost: it is a utility released to public domain which was developed by the USA Air Force Office of Special Investigations and The Center for Information Systems Security Studies and Research. It is basically a data scavenger and forensic tool which – regardless of the relative file system – it will scan for specific file types, based on known headers, data structures and footers.

For instance you can scan for XLSX file types with the command below:

foremost -t zip -i /dev/sdb1 -o /restore

Here not only zip files will be scanned to but also jar ones and common Open Office and MS Office files ending in x, which basically are compressed zip files; here with /restore we mean the output directory for restored files. As always we must restore data in different partition.

If we want just a report without recovering any data the command will be

foremost -w -t zip -i /dev/sdb1 -o /restore

Important: the output directory must be empty, otherwise we must specify the -T; this switch will create a folder starting with the specified name and appending to it the current date and time.

foremost -w -T -t zip -i /dev/sdb1 -o /restore/

Unfortunately this software doesn’t allow to look for specific files or folders, but it can be tried when other tools have failed and because is quite fast. For instance it has been useful to scan for deleted files in a Novell file system (in a old Linux OES).

Even if it should be quite obvious it has to be mentioned that this tool doesn’t work with encrypted partitions.