Skip to content

Instantly share code, notes, and snippets.

@ahbanavi
Last active November 5, 2024 16:31
Show Gist options
  • Save ahbanavi/ef39d70aef6a1778a9c83c5f0fb86dfc to your computer and use it in GitHub Desktop.
Save ahbanavi/ef39d70aef6a1778a9c83c5f0fb86dfc to your computer and use it in GitHub Desktop.
My OpenWrt Initial Setup (Passwall2 + extroot + vnstat)

My OpenWrt Initial Setup

My Router Info

  • Model: Linksys EA8100
  • Memory: 256MB
  • Storage: Using 16GB thumb drive as extroot
  • OpenWrt Version: OpenWrt 23.05.3 r23809-234f1a2efa / LuCI openwrt-23.05 branch git-24.073.29889-cd7e519

Extroot

opkg update
opkg install block-mount kmod-fs-ext4 e2fsprogs parted kmod-usb-storage

# identify name of USB disk
ls -l /sys/block # or opkg install lsblk && lsblk

# Partitioning and formatting
DISK="/dev/sda"
parted -s ${DISK} -- mklabel gpt mkpart extroot 2048s -2048s
DEVICE="${DISK}1"
mkfs.ext4 -L extroot ${DEVICE}

# Configuring extroot
eval $(block info ${DEVICE} | grep -o -e 'UUID="\S*"')
eval $(block info | grep -o -e 'MOUNT="\S*/overlay"')
uci -q delete fstab.extroot
uci set fstab.extroot="mount"
uci set fstab.extroot.uuid="${UUID}"
uci set fstab.extroot.target="${MOUNT}"
uci commit fstab

# Configuring rootfs_data / ubifs
# Configure a mount entry for the the original overlay.
ORIG="$(block info | sed -n -e '/MOUNT="\S*\/overlay"/s/:\s.*$//p')"
uci -q delete fstab.rwm
uci set fstab.rwm="mount"
uci set fstab.rwm.device="${ORIG}"
uci set fstab.rwm.target="/rwm"
uci commit fstab

# Transferring data
mount ${DEVICE} /mnt
tar -C ${MOUNT} -cvf - . | tar -C /mnt -xf -

reboot

Sources:

Pass Wall 2

wget -O passwall.pub https://master.dl.sourceforge.net/project/openwrt-passwall-build/passwall.pub  
opkg-key add passwall.pub  

# https://github.com/moetayuko/openwrt-passwall-build
read release arch << EOF
$(. /etc/openwrt_release ; echo ${DISTRIB_RELEASE%.*} $DISTRIB_ARCH)
EOF
for feed in passwall_luci passwall_packages passwall2; do
  echo "src/gz $feed https://master.dl.sourceforge.net/project/openwrt-passwall-build/releases/packages-$release/$arch/$feed" >> /etc/opkg/customfeeds.conf
done
 
opkg update
opkg remove dnsmasq
opkg install dnsmasq-full
opkg install kmod-nft-socket
opkg install kmod-nft-tproxy
opkg install kmod-nft-nat
opkg install luci-app-passwall2

Bypass Iran

first we need to write a script to use another geosite and geoip and auto update it with cron.
cron:

0 9 * * 2 /root/scripts/update_dat_files.sh

auto update script (path: /root/scripts/update_dat_files.sh) is available in this gist. you can download it directly to your openwrt with following command:

mkdir /root/scripts && cd /root/scripts
wget https://gist.githubusercontent.com/ahbanavi/cccf067de8586311f63dadd63aded507/raw/update_dat_files.sh
chmod +x ./update_dat_files.sh

then run the script for first time to change geosite and geoip to Chocolate4U repo:

/root/scripts/update_dat_files.sh

then follow these steps in shunt rules to configure bypass and block list. here's mine:

Block Domains:
geosite:category-ads-all
geosite:malware
geosite:phishing
geosite:cryptominers
domain:analytics.google.com
domain:notify.bugsnag.com
domain:sessions.bugsnag.com
domain:api.bugsnag.com
domain:app.bugsnag.com
domain:browser.sentry-cdn.com
domain:app.getsentry.com

Block IPs:
geoip:malware  
geoip:phishing

Direct Domains:
geosite:ir  
domain:time.samsungcloudsolution.net  
domain:time.samsungcloudsolution.com  
domain:uploadboy.com  
domain:anime-planet.com  
domain:divyacamilla.info  
domain:meet.google.com

Direct IPs:
geoip:private  
geoip:ir

also, I use AdGuard Public DNS server to block more ads and trackers.

Sources:

vnstat

I primary use vnstat to automatically switch between my two wan based on net usage, check here to see more info.

opkg update
opkg install vnstat

opkg install vnstati luci-app-vnstat

vim /etc/vnstat.conf
# Interface "wan"
# MaxBandwidth 1000

vim /etc/config/vnstat
# config vnstat  
#	    list interface 'br-lan'  
#	    list interface 'lan4'  
#	    list interface 'wan'

vnstat -u -i wan  
vnstat -u -i lan4  
vnstat -u -i br-lan

# vim /etc/vnstat.conf
# change db file to a persist location, as we are in extroot by now, lib directory is persistant
# DatabaseDir "/lib/vnstat"

/etc/init.d/vnstat enable
/etc/init.d/vnstat start

Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment