iwlwifi: Your Wifi Is Working?

Sometimes, specially when you are using Arch, after using pacman -Syu, and updating linux-firmware, you will find that there is no wifi present after rebooting. Donot panic, there is a bug in firmware for iwlwifi which block your system to load latest firmware for iwlwifi. Just issue command journalctl -p 3 -xb, this will let you know that firmware file is not loading (I dont recall the exact error message).

sudo mv /usr/lib/firmware/faulty.ucode.xz /usr/lib/firmware/faulty.ucode.xz.back

Thats is all. your wifi will be up in no time!

Passing RealIp Address To Nginx Access Log

When you place Nginx behind Cloudflare, the http_remote_addr in Nginx access_log will contain the Cloudflare IP, which is not helpfull when banning users. To enable Nginx to resolve the real IP of visitors, we need to whitelist the Cloudflare IPs and map the header value.

set_real_ip_from [Cloudflare IP]

real_ip_header CF-Connecting-IP;

To automate this process, we can write a bash script /usr/bin/get_cloudflare_ips.sh that handles this repetitive task.

#!/usr/bin/env bash

generate_ip_file() {
    CMD="$1"

    printf "# https://www.cloudflare.com/ips\n"
    printf "# Generated at %s\n" "$(LC_ALL=C date)"

    for TYPE in v4 v6; do
        printf "\n# IP%s\n" "$TYPE"
        curl -sL "https://www.cloudflare.com/ips-$TYPE/" | sed "s!^!$CMD !g" | sed "s!\$!;!g"
        printf "\n"
    done
}

(generate_ip_file set_real_ip_from && printf "real_ip_header CF-Connecting-IP;\n") > /etc/nginx/conf.d/cloudflare.conf

Assuming this works well, it will produce /etc/nginx/conf.d/cloudflare.conf like

# https://www.cloudflare.com/ips
#

# IPv4
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;

# IPv6
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;
real_ip_header CF-Connecting-IP;

Since Cloudflare may update their IP addresses, it’s best practice to stay synced with them. To overcome this difficulty, a nice systemd timer at /etc/systemd/system/cloudflare.timer like


[Unit]
Description=Running cloudflare service

[Timer]
OnCalendar=Sat *-*-1..7 18:00:00
Persistent=true

[Install]
WantedBy=timers.target

This timer will run after 4 weeks and start a service /etc/systemd/system/cloudflare.service which in turn will execute bash script at /usr/bin/get_cloudflare_ips.sh


[Unit]
Description=Fetching cloudflare ips
 
[Service]
Type=simple
ExecStart=/usr/bin/get_cloudflare_ips.sh

Running Multiple Wordpress Instances In Docker

When running multiple instances of WordPress in docker, this will be very helpful.

docker run -e MYSQL_ROOT_PASSWORD='strongpassword' \
-e MYSQL_USER=wpuser -e MYSQL_PASSWORD='strongpassword' -e MYSQL_DATABASE=website_db \
-v /var/www/website/database:/var/lib/mysql --name website_db \
-d --restart always mariadb

You must make sure to run mysql or mariadb container first. Because it will in on the network created by docker before you create wordpress instance

docker run -e WORDPRESS_DB_HOST=website_db -e WORDPRESS_DB_USER=wpuser \
-e WORDPRESS_DB_PASSWORD='strongpassword' -e WORDPRESS_DB_NAME=website_db \
-p 8081:80 -v /var/www/website/html:/var/www/html --name website_wordpress \
--link [db container name]:mysql -d --restart always wordpress

you can certainly access volumes from /var/. And also use docker exec to add dbdump files.

Finding And Deleting Old Kernels

In Ubuntu, you will some time find fallback kernels in /boot. These are some time annoyning specially when you do not have something else to do. I’m using ubuntu server for my web projects, I updated it, to my my surprize there were about four versions of kernel were present. Yes you can certainly delete them by issuing command but why so easy. Why not use just one command and you will get only two, one for main use and other one for fallback. So any time you got more than two use this command

dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' \
| sed -n '/linux-image second last/q' | xargs sudo apt-get -y purge

But do not forgot to update your grub config after this.

Welcome to Jekyll!

You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.

Jekyll requires blog post files to be named according to the following format:

YEAR-MONTH-DAY-title.MARKUP

Where YEAR is a four-digit number, MONTH and DAY are both two-digit numbers, and MARKUP is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.

Jekyll also offers powerful support for code snippets:

def print_hi(name)
  puts "Hi, #{name}"
end
print_hi('Tom')
#=> prints 'Hi, Tom' to STDOUT.

Check out the Jekyll docs for more info on how to get the most out of Jekyll. File all bugs/feature requests at Jekyll’s GitHub repo. If you have questions, you can ask them on Jekyll Talk.