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.