Daily tip

How to transparently redirect HTTP requests on port 80 to a http proxy on port 8080?

By using the iptable nat

First pre-requisite is enabling IP forwarding on the system

#echo “net.ipv4.conf.all.forwarding =1”>>/etc/sysctl.conf && sysctl -p

Then issue the below iptable command

#iptables -t nat -A PREROUTING -p tcp –dport 80 -j REDIRECT –to-port 8080


Daily tip

I have installed CentOS minimal and the commands, ifconfig, netstat and traceroute are not recognized: how come?

These are considered now deprecated or legacy commands/utilities, please get more info on their equivalent (in the order):

ip
ss
tracepath

Daily tip.

How do I display a substring of a variable in bash?

For example, you want to display the first seven characters from a string passed from the command line

echo ${$1:0:7}

Of course you can also save the value somewhere

substr=${$1:0:7}

Daily tip

How do I revoke a certificate in Openssl?

#openssl -ca revoke openssl ca -revoke /etc/ssl/certs/cert.pem

Of course replace path and filename to reflect your configuration.

Daily tips

How to prevent changing SELinux policy?

#setsebool secure_mode_policyload on

After that the SELinux policy (enforced or permissive) can be changed only after rebooting


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.