Monday, August 24, 2020

Using yum through socks5 proxy

This is useful when you have a server that is not allowed to go to the internet, but have an ssh connection to another server that is able to go to the internet (we can call it jumphost).


1. Setup a socks proxy on port 8888 (any port will do, 8888 is just my preference) via the jumphost

# ssh -D 8888 -fN user@jumphost


2. Append below line into yum.conf

# cat  >> /etc/yum.conf <<EOF

proxy=socks5h://localhost:8888

EOF


3. Yum away (or run the yum command). All yum command will now tunneled through jumphost

# yum update


4. Once done, kill the socks proxy connection

# kill -9 $(ps -ef | grep fN | grep -v grep | awk '{print $2}')


5. And remove the proxy setting in /etc/yum.conf

# sed -i '$d' /etc/yum.conf

Sunday, August 23, 2020

Using mkchromecast in Linux Mint 20

 I used to use mkchromecast in my linux mint 19 without any issue, The installation is pretty straight forward, easy to use, and the best of all, is that mkchromecast is able to cast video with subtitle. 


After I have upgraded my machine to Mint 20, I installed it, and encountered one issue whereby mkchromecast does not pair properly with chromecast due to an issue in the pychromecast version used in ubuntu 20.04 (or linux mint 20 in my case). 


The bug is being reported in here, and was from this page that I found by googling the error.


So to install mkchromecast in linux mint 20 (or ubuntu 20.04), here are the steps:

1. Install the application

$ sudo apt install mkchromecast -y


2. Update pychromecast package to version 4.1.1

$ pip3 install pychromecast==4.1.1


That's all. To use it, just follow below steps:

1. Open a new terminal, and cast a video

$ mkchromecast --video -i myvideo.mp4


2. If you want to cast a video with a subtitle file

$ mkchromecast --video -i myvideo.mp4 --subtitle mysubtitle.srt


3. If you have multiple chromecast device, please use -s, and choose the index of the chromecast device you would like to use

$ mkchromecast --video -i myvideo.mp4 --subtitle mysubtitle.srt -s


4. Casting with basic control like pause (keyboard p), resume (keyboard r), volume up (keyboard u) and volume down (keyboard d)

$ mkchromecast --video -i myvideo.mp4 --subtitle mysubtitle.srt --control


mkchromecast is an excellent tool to cast your video to the big screen, but if you are not comfortable with casting with commands, vlc and google chrome browser are better tools but without the subtitle.


Monday, August 17, 2020

Monitoring coreutils basic operation progress, with progress app

While copying or moving stuff across locations in my computer, using terminal, most of the time I want to have a progress reporting of how much has been copied or moved. This can be easily achieved using a neat little tool called progress. To use it, you have to install it first.

To install progress

$ sudo apt install progress -y


Start you coreutils basic operation (cp, mv, dd, tar, gzip/gunzip, cat, etc.)

$ cp CentOS-8.1.1911-x86_64-dvd1.iso /data/


Monitor the progress using progress. Just run progress:

$ progress


To continuously see the progress, just use the -m option. It will update regularly, and speed and estimated remaining time will be shown 

$ progress -m




Friday, August 14, 2020

Quick DNS Server on Centos 8 using dnsmasq

To setup a quick and easy DNS server for CentOS 8, I choose dnsmasq. Bind is powerful, but too complicated for a simple DNS in a small LAN environment. So let's get started.


Install dnsmasq

# yum install dnsmasq -y


Backup original dnsmasq.conf configuration file

# cp /etc/dnsmasq.conf /etc/dnsmasq.conf.ori


Insert some settings into dnsmasq.conf. This is assuming our CentOS box IP address is 192.168.0.120, and it's interface is enp0s3. The "server" settings are for upstream DNS addresses.

# cat > /etc/dnsmasq.conf <<EOF

listen-address=::1,127.0.0.1,192.168.0.120

interface=enp0s3

expand-hosts

domain=local.lan

server=192.168.0.1

server=8.8.8.8

server=8.8.4.4

address=/local.lan/127.0.0.1

address=/local.lan/192.168.0.120

EOF


Test your configuration for any syntax error
# dnsmasq --test

Now to put in some dns records. Dnsmasq will read all records from /etc/hosts of the dnsmasq server (how easy & convenient is that?!)
# cat >> /etc/hosts <<EOF
dns 192.168.0.120
web 192.168.0.120
EOF

Start your dnsmasq service
# systemctl start dnsmasq

Allow DNS in firewall
# firewall-cmd --add-service dns
# firewall-cmd --add-service dns --permanent

Now to put your DNS to test. The best is to use other machine. My other machine is using DHCP, so I need to configure the DNS setting to point to my brand new dnsmasq server, and ignore the dns given by my DHCP
# nmcli connection modify enp0s3 ipv4.ignore-auto-dns yes
# nmcli connection modify enp0s3 ipv4.dns 192.168.0.120
# nmcli connection down enp0s3
# nmcli connection up enp0s3

Ping test
# ping web
PING web (192.168.0.120) 56(84) bytes of data.
64 bytes from web.local.lan (192.168.0.120): icmp_seq=1 ttl=64 time=0.134 ms
64 bytes from web.local.lan (192.168.0.120): icmp_seq=2 ttl=64 time=0.129 ms

You have got yourself a brand new DNS server, congratulations!


Monday, August 10, 2020

Monitor the progress of copy operation with pv

 Sometimes, when we need to copy a big file, let's say from our linux box, to a flash drive, and we just used the "cp" command. After a while, we are anxious to know what is the progress, and unfortunately we have forgotten to turn on verbose for the command. 


What to do? Cancellation is not an option, since we would be wasting time restarting the command again if we want to put the verbose option.


Worry not, there is a solution. And this solution is pv. Most of the time it is not installed by default, so we have to install it first.


What is pv? According to its man page, pv will monitor the progress of data through a pipe. Nice!


How do we install it?

$ sudo apt install pv -y


How do we use it? We can track the progress of any command, just by providing the PID of that running command. Let's say we are copying an iso. 

Firstly, get the PID of the cp command., and then run pv against it. 

$ ps -ef | grep iso | grep -v grep | awk '{print $2}'

12345

$ pv -d 12345

and pv will provide you with a nice progress bar, with E.T.A. like below