28 เมษายน 2566

Mikrotik container + adguard home v0.107.29 (latest)

Mikrotik v7.8
AdGuard Home v0.107.29 (latest)

image from https://registry-1.docker.io "error response getting manifests: 404"

import image form PC instead (both PC and CHR using amd64)

$ docker pull adguard/adguardhome:latest
$ docker save adguard/adguardhome:latest -o adguard_home_0_107_29.tar

upload adguard_home_0_107_29.tar to your CHR


Create mount volune to keep config and data for upgrade image version
/container mounts
add dst=/opt/adguardhome/work name=adguard-work src=/adguard/work
add dst=/opt/adguardhome/conf name=adguard-conf src=/adguard/conf

/container
add file=adguard_home_0_107_29.tar interface=veth-adguard mounts=adguard-conf,adguard-work start-on-boot=yes logging=yes

04 เมษายน 2566

proxmox anywhere with mikrotik chr

Scenario
- mini pc with 1 NIC
- proxmox CE
- mikrotik CHR
- cloudflare tunnel

1. Install proxmox with static ip for existing network (192.168.80.20/24)

Network Device :  enp1s0
Linux Bridge : vmbr0

/etc/network/interfaces
iface enp1s0 inet manual

auto vmbr0
iface vmbr0 inet static
        address 192.168.80.20/24
        gateway 192.168.80.1
        bridge-ports enp1s0
        bridge-stp off
        bridge-fd 0

2. Add vmbr1 as LAN (10.80.0.20/24) and set vmbr0 as WAN

/etc/network/interfaces
iface enp1s0 inet manual

auto vmbr0
iface vmbr0 inet static
        address 192.168.80.20/24
        gateway 192.168.80.1
        bridge-ports enp1s0
        bridge-stp off
        bridge-fd 0
#WAN

auto vmbr1
iface vmbr1 inet static
        address 10.80.0.20/24
        bridge-ports none
        bridge-stp off
        bridge-fd 0
#LAN

3. Install Mikrotik CHR

ether1 : vmbr0 (dhcp client)
ehter2 : vmbr1 (10.80.0.1/24)
masquerade out-interface ether1

4. Install cloudflare tunnel via proxmox node shell

Add public hostname with service https://10.80.0.20:8006 for proxmox
Add public hostname with service http://10.80.0.1 for mikrotik CHR

5. change promox default gateway to vmbr1

/etc/network/interfaces
iface enp1s0 inet manual

auto vmbr0
iface vmbr0 inet static
        address 192.168.80.20/24
        bridge-ports enp1s0
        bridge-stp off
        bridge-fd 0
#WAN

auto vmbr1
iface vmbr1 inet static
        address 10.80.0.20/24
        gateway 10.80.0.1
        bridge-ports none
        bridge-stp off
        bridge-fd 0
#LAN

6. Access proxmox with public hostname

7. Install other proxmox guest with vmbr1 and access with public hostname

24 มีนาคม 2566

Mikrotik CHR on ReadyIDC cloud

ACTIONS -> OPTIONS -> Rebuild virtual server
select CentOS

ACTIONS -> POWER -> Reboot in Recovery

sudo yum install unzip

mount -t tmpfs tmpfs /tmp/

cd /tmp

wget https://download.mikrotik.com/routeros/7.8/chr-7.8.img.zip

unzip chr-7.8.img.zip

dd if=chr-7.8.img of=/dev/vda bs=4M oflag=sync

mkdir /media/vda1

mount /dev/vda1 /media/vda1

mkdir -p /media/vda1/boot/grub2/

vi /media/vda1/boot/grub2/grub.cfg

setparams 'Grub 2'
set root=(hd0,msdos1)
chainloader +1

sync

umount /dev/vda1

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

ACTIONS -> POWER -> Reboot Virtual Server

----- restore rsc and enable container ------

ip address add address=192.168.80.99/24 interface=ether1 

ip route add  gateway=192.168.80.1

system reset-configuration no-default=no skip-backup=yes keep-user=no

systec backup load name=chr-back-20230323.backup

system device-mode update container=yes

ACTIONS -> POWER -> Shut Down Virtual Server
select Power OFF

17 กุมภาพันธ์ 2566

Mikrotik container + adguard + uptime kuma

Mikrotik  v7.7

adguardhome after this version have an error
 
 
/system/device-mode/update container=yes

/container config
set registry-url=https://registry-1.docker.io

/interface bridge
add name=Docker

/ip address
add address=10.0.0.1/24 interface=Docker

/ip firewall nat
add chain=srcnat src-address=10.0.0.0/24 action=masquerade

/interface veth
add address=10.0.0.10/24 gateway=10.0.0.1 name=veth-adguard

/interface bridge port
add bridge=Docker interface=veth-adguard

/container
add interface=veth-adguard remote-image=adguard/adguardhome:v0.107.23 start-on-boot=yes logging=yes

/interface veth
add address=10.0.0.11/24 gateway=10.0.0.1 name=veth-uptimekuma

/interface bridge port
add bridge=Docker interface=veth-uptimekuma

/container mounts
add dst=/app/data name=uptimekuma src=/kuma_data

/container
add interface=veth-uptimekuma mounts=uptimekuma remote-image=louislam/uptime-kuma start-on-boot=yes logging=yes

sftp to remove kuma_data/.type after first start

13 กุมภาพันธ์ 2566

docker-composer :: php mysql phpmyadmin

 ubuntu 22.04

file structure
docker-composer.yaml
www/Dockerfile
www/html/index.php
mysql/dbdata/


$ sudo apt update && sudo apt -y upgrade
$ sudo apt install docker-compose docker.io -y

$ vi docker-compose.yaml
version: "3.8"
services:

  www:
    build:
      context: ./www
      dockerfile: Dockerfile
    depends_on:
      - db
    volumes:
      - ./www/html:/var/www/html/
    ports:
      - "8080:80"
    networks:
      - my-network

  db:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: xxxxxxxxx
    volumes:
      - ./mysql/dbdata:/var/lib/mysql/
    ports:
      - "3306:3306"
    networks:
      - my-network

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    depends_on:
      - db
    environment:
      PMA_HOST: db
    ports:
      - "8081:80"
    networks:
      - my-network

networks:
  my-network:


$ vi www/Dockerfile
FROM php:8.2-apache

ENV TZ=Asia/Bangkok
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN printf '[PHP]\ndate.timezone = "Asia/Bangkok"\n' > /usr/local/etc/php/conf.d/tzone.ini

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update && apt-get upgrade -y

$ sudo docker-compose up -d

03 กุมภาพันธ์ 2566

PHP Cloudflare Turnstile

Turnstile is Cloudflare’s smart CAPTCHA alternative.

https://www.cloudflare.com/products/turnstile/

<?php
if (isset($_POST["cf-turnstile-response"])) {

    $captcha = $_POST['cf-turnstile-response'];
    $secretKey = "__Secret_Key__";
    $ip = $_SERVER['REMOTE_ADDR'];
    $url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
    $data = array('secret' => $secretKey, 'response' => $captcha, 'remoteip' => $ip);

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $curlData = curl_exec($curl);
    curl_close($curl);
    
    $result = json_decode($curlData, true);
    
    if (intval($result["success"]) == 1) {
        echo "success";
        exit();
    } else {
        echo "error";
        exit();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Test Turnstile</title>
        <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
    </head>
    <body>
        <form method="POST" action="">
            <div>
                <!-- The following line controls and configures the Turnstile widget. -->
                <div class="cf-turnstile" data-sitekey="__Site_Key__" data-theme="light"></div>
                <!-- end. -->
            </div>
            <button  type="submit">Sign in</button>
        </form>
    </body>
</html>

26 มกราคม 2566

Mikrotik load balance with recursive route

RouterOS7

ehter1 : 192.168.1.x/24
ether2 : 192.168.2.x/24
LAN : 192.168.25.1/24

ether1 ping check : 1.0.0.1
ether2 ping check : 8.8.4.4

/ip firewall mangle
add action=accept chain=prerouting dst-address=192.168.1.0/24
add action=accept chain=prerouting dst-address=192.168.2.0/24
add action=accept chain=prerouting dst-address=192.168.25.0/24
add action=mark-connection chain=input in-interface=ether1 new-connection-mark=wan1_input passthrough=yes
add action=mark-connection chain=input in-interface=ether2 new-connection-mark=wan2_input passthrough=yes
add action=mark-routing chain=output comment="WAN1 Input" connection-mark=wan1_input new-routing-mark=WAN1 passthrough=no
add action=mark-routing chain=output comment="WAN2 Input" connection-mark=wan2_input new-routing-mark=WAN2 passthrough=no
add action=mark-connection chain=prerouting in-interface=ether1 new-connection-mark=wan1_conn passthrough=yes
add action=mark-connection chain=prerouting in-interface=ether2 new-connection-mark=wan2_conn passthrough=yes
add action=mark-routing chain=prerouting connection-mark=wan1_conn in-interface=br-lan new-routing-mark=WAN1 passthrough=no
add action=mark-routing chain=prerouting connection-mark=wan2_conn in-interface=br-lan new-routing-mark=WAN2 passthrough=no
add action=mark-connection chain=prerouting comment=4/0 dst-address-type=!local in-interface=br-lan new-connection-mark=wan1_lb passthrough=yes per-connection-classifier=both-addresses:4/0
add action=mark-connection chain=prerouting comment=4/1 dst-address-type=!local in-interface=br-lan new-connection-mark=wan2_lb passthrough=yes per-connection-classifier=both-addresses:4/1
add action=mark-connection chain=prerouting comment=4/2 dst-address-type=!local in-interface=br-lan new-connection-mark=wan1_lb passthrough=yes per-connection-classifier=both-addresses:4/2
add action=mark-connection chain=prerouting comment=4/3 dst-address-type=!local in-interface=br-lan new-connection-mark=wan2_lb passthrough=yes per-connection-classifier=both-addresses:4/3
add action=mark-routing chain=prerouting connection-mark=wan1_lb in-interface=br-lan new-routing-mark=WAN1 passthrough=no
add action=mark-routing chain=prerouting connection-mark=wan2_lb in-interface=br-lan new-routing-mark=WAN2 passthrough=no

/queue simple
add dst=ether1 limit-at=1M/1M max-limit=10M/10M name=wan1 queue=pcq-upload-default/pcq-download-default target=192.168.25.0/24
add dst=ether2 limit-at=1M/1M max-limit=10M/10M name=wan2 queue=pcq-upload-default/pcq-download-default target=192.168.25.0/24

/ip route
add distance=1 dst-address=1.0.0.1/32 gateway=192.168.1.1 routing-table=main scope=10
add distance=1 dst-address=8.8.4.4/32 gateway=192.168.2.1 routing-table=main scope=10
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=1.0.0.1 routing-table=main target-scope=30
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=8.8.4.4 routing-table=main target-scope=30
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=1.0.0.1 routing-table=WAN1 target-scope=30
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=8.8.4.4 routing-table=WAN2 target-scope=30