Friday, June 13, 2025

ALPINE LINUX share internet 2 nic

#!/bin/sh


# Enable IP forwarding

echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

sysctl -p


# Install required packages

apk add iptables iptables-openrc dnsmasq


# Configure iptables for NAT

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

iptables -A FORWARD -i eth1 -j ACCEPT


# Save iptables rules

mkdir -p /etc/iptables

iptables-save > /etc/iptables/rules-save


# Enable iptables service at boot

rc-update add iptables default


# Assign static IP to eth1

cat <<EOF > /etc/network/interfaces

auto lo

iface lo inet loopback


auto eth0

iface eth0 inet dhcp


auto eth1

iface eth1 inet static

    address 192.168.100.1

    netmask 255.255.255.0

EOF


# Enable networking service at boot

rc-update add networking default


# Configure dnsmasq

cat <<EOF > /etc/dnsmasq.conf

interface=eth1

dhcp-range=192.168.100.50,192.168.100.150,12h

dhcp-option=3,192.168.100.1

dhcp-option=6,8.8.8.8

EOF


# Enable and start dnsmasq

rc-update add dnsmasq default

rc-service dnsmasq restart


echo "Internet sharing setup complete and persistent across reboots."


Monday, June 9, 2025

MikroTik

Check Network card

 /interface print

set ip for nat card

/ip dhcp-client add interface=ether3 disabled=no
show status
/ip dhcp-client print

set ip for exit card
/ip address add address=192.168.137.1/24 interface=ether4

/ip pool add name=dhcp_pool_ether4 ranges=192.168.137.10-192.168.137.100
/ip dhcp-server network add address=192.168.137.0/24 gateway=192.168.137.1 dns-server=8.8.8.8
/ip dhcp-server add name=dhcp_ether4 interface=ether4 address-pool=dhcp_pool_ether4 disabled=no
show lease
/ip dhcp-server lease print

share
/ip firewall nat add chain=srcnat out-interface=ether3 action=masquerade

/system package update check-for-updates

/system package update download

Saturday, June 7, 2025

Debian 12 to share internet

1. Download The Debian Bookworm network installation CD

2. install follow steps and on set software unselect all

note command to see network

   ip a

3 sudo nano /etc/network/interfaces


3.1 sudo systemctl restart networking
3.2 echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
3.3 sudo nano /etc/sysctl.conf
    uncomment #
    net.ipv4.ip_forward=1
3.4 sudo sysctl -p
3.5 
sudo iptables -t nat -A POSTROUTING -o enx000ec6c29c18-j MASQUERADE
sudo iptables -A FORWARD -i ens33 -o enx000ec6c29c18 -j ACCEPT
sudo iptables -A FORWARD -i enx000ec6c29c18 -o ens33 -m state --state RELATED,ESTABLISHED -j ACCEPT
3.6 sudo apt install iptables-persistent


sudo nano /etc/apt/sources.list


sudo apt update && sudo apt upgrade
sudo apt install open-vm-tools isc-dhcp-server
sudo nano /etc/dhcp/dhcpd.conf

sudo nano /etc/default/isc-dhcp-server

sudo systemctl restart isc-dhcp-server

  sudo systemctl enable isc-dhcp-server

8 sudo nano /etc/systemd/system/nightly-reboot.service

[Unit]
Description=Scheduled Nightly Reboot

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl --force reboot

sudo nano /etc/systemd/system/nightly-reboot.timer

[Unit]
Description=Nightly Reboot Scheduling

[Timer]
OnCalendar=*-*-* 2:01:00
RandomizedDelaySec=300

[Install]
WantedBy=multi-user.target

10 sudo systemctl daemon-reload

   sudo systemctl enable nightly-reboot.timer

   sudo systemctl start nightly-reboot.timer

Friday, May 23, 2025

excel forward backward seq

B2=INPUT
B3 =INDEX(A1:G1, MOD(MATCH(B2, A1:G1, 0), COLUMNS(A1:G1)) + 1)

B4=INDEX(A1:G1, IF(MATCH(B2, A1:G1, 0)=1, COLUMNS(A1:G1), MATCH(B2, A1:G1, 0)-1))

Tuesday, May 13, 2025

mysql move data over year

 CREATE TABLE record_packing_ok_2024 LIKE record_packing_ok;


INSERT INTO record_packing_ok_2024

SELECT *

FROM record_packing_ok

WHERE YEAR(date_time) < 2025;


DELETE FROM `record_packing_ok` WHERE year(`date_time`)<2025;

Thursday, March 13, 2025

VBA select area to export to picture and set name same sheet name

 Sub ExportAllSheets()

    Dim oWs As Worksheet

    Dim oRng As Range

    Dim oChrtO As ChartObject

    Dim lWidth As Long, lHeight As Long

    Dim sFilePath As String

    

    sFilePath = "d:\"

    

    For Each oWs In ActiveWorkbook.Worksheets

        ActiveWindow.Zoom = 100

        Set oRng = oWs.Range("B2:n30")

        

        oRng.CopyPicture xlScreen, xlPicture

        lWidth = oRng.Width

        lHeight = oRng.Height

        

        Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)

        

        oChrtO.Activate

        With oChrtO.chart

            .Paste

            .Export Filename:=sFilePath & oWs.Name & ".jpg", Filtername:="JPG"

        End With

        

        oChrtO.Delete

    Next oWs

End Sub


Monday, February 10, 2025

openssh use public-key to connect (both server and client was windows)

first install openssh server, and openssh client both side

 server side:

    1 edit sshd_config

        1.1 remove # at line

        PubkeyAuthentication yes

        PasswordAuthentication no   (change yes -->no)

        1.2 add # at two lines of end file

        #Match Group administrators

           #AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

    restart openssh service

    3 create file authorized_keys   (c:\user\prapop\.ssh\authorized_keys)

    may be need

    4 remove inherite permission and remove adminostator of file authorized_keys  

client side

    1 ssh-keygen

    2 copy id_rsa.pub (client side) --> authorized_keys (server side)

ssh -N -R 12345:localhost:21118 -o ServerAliveInterval=60 -o ServerAliveCountMax=3 192.168.0.86


Friday, February 7, 2025

openssh server windows and revese tunnel

  • Download the latest OpenSSH for Windows binaries (package OpenSSH-Win64.zip or OpenSSH-Win32.zip)
  • As the Administrator, extract the package to C:\Program Files\OpenSSH
  • As the Administrator, install sshd and ssh-agent services:
    powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

Configuring SSH server

  • Allow incoming connections to SSH server in Windows Firewall:
    • When installed as an optional feature, the firewall rule “OpenSSH SSH Server (sshd)” should have been created automatically. If not, proceed to create and enable the rule as follows.
    • Either run the following PowerShell command as the Administrator:
      New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\Windows\System32\OpenSSH\sshd.exe"
      Replace C:\Windows\System32\OpenSSH\sshd.exe with the actual path to the sshd.exe (C:\Program Files\OpenSSH\ssh.exe, had you followed the manual installation instructions above).
    • or go to Windows Security > Firewall & network protection1 > Advanced Settings > Inbound Rules and add a new rule for port 22.
  • Start the service and/or configure automatic start:
    • Go to Control Panel > System and Security > Windows Tools (Administrative Tools on Windows 10 and older) and open Services. Locate OpenSSH SSH Server service.
    • If you want the server to start automatically when your machine is started: Go to Action > Properties (or just double-click the service). In the Properties dialog, change Startup type to Automatic and confirm.
    • Start the OpenSSH SSH Server service by clicking the Start the service link or Action > Start in the menu.

Setting up SSH public key authentication

Follow a generic guide for Setting up SSH public key authentication in *nix OpenSSH server, with the following difference:

  • Create the .ssh folder (for the authorized_keys file) in your Windows account profile folder (typically in C:\Users\username\.ssh).2
  • For permissions to the .ssh folder and the authorized_keys file, what matters are Windows ACL permissions, not simple *nix permissions. Set the ACL so that the respective Windows account is the owner of the folder and the file and is the only account that has a write access to them. The account that runs OpenSSH SSH Server service (typically SYSTEM or sshd) needs to have read access to the file.
  • Though, with the default Win32-OpenSSH configuration there is an exception set in sshd_config for accounts in Administrators group. For these, the server uses a different location for the authorized keys file: %ALLUSERSPROFILE%\ssh\administrators_authorized_keys (i.e. typically C:\ProgramData\ssh\administrators_authorized_keys).

C:\Program Files\OpenSSH\ssh-keygen.exe

(on windows10 will copy to user folder)


Client 

install openssh

cmd-->

ssh -N -R 12345:localhost:21118 -o ServerAliveInterval=60 -o ServerAliveCountMax=3 192.168.0.86


Cr: https://winscp.net/eng/docs/guide_windows_openssh_server

Thursday, January 23, 2025

Excel โชว์ข้อมูลจากการเลือก หลายเงื่อนไข

 

Input E1 find "AAA or BBB"

E2,E3

=IFERROR(INDEX($B$2:$B$11, SMALL(IF(INDEX($C$2:$D$11,,MATCH($E$1,$C$1:$D$1,0))>0, ROW($B$2:$B$11)-MIN(ROW($B$2:$B$11))+1), ROW(1:1))), "")

Code from Copliot help