Post

OpenClash in OpenWrt

Setup OpenClash in OpenWrt x86 under VMWare ESXi

  1. Download latest image from https://mirror-03.infra.openwrt.org/releases/
  2. Convert to vmdk in ubuntu qemu-img convert -f raw -O vmdk <imput.img> <output.vmdk>
  3. Create a new VM in ESXi and upload the vmdk
  4. Ssh to ESXi and execute in default folder vmkfstools -i /vmfs/volumes/datastore1/openwrt2/input.vmdk /vmfs/volumes/datastore1/openwrt2/output.vmdk

  5. Launch VM and vim /etc/config/network, change ip to 172.16.68.9, reboot
  6. Change network interface config in web portal, set gateway and DNS server to 172.16.68.1, disable DHCP
  7. Copy settings from the old openwrt
  8. Change to aliyun source lists, sed -i 's_downloads.openwrt.org_mirrors.aliyun.com/openwrt_' /etc/opkg/distfeeds.conf
  9. Remove the option check_signature in /etc/opkg.conf
  10. opkg update and opkg install open-vm-tools nano

  11. Expand the disk size to 16GB in ESXi
  12. Follow https://openwrt.org/docs/guide-user/advanced/expand_root
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    # Install packages
    opkg update
    opkg install parted losetup resize2fs blkid
        
    # Download expand-root.sh
    wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0"
        
    # Source the script (creates /etc/uci-defaults/70-rootpt-resize and /etc/uci-defaults/80-rootpt-resize, and adds them to /etc/sysupgrade.conf so they will be re-run after a sysupgrade)
    . ./expand-root.sh
        
    # Resize root partition and filesystem (will resize partiton, reboot resize filesystem, and reboot again)
    sh /etc/uci-defaults/70-rootpt-resize
    
  13. opkg remove dnsmasq
  14. Follow https://github.com/vernesong/OpenClash/releases/tag/v0.47.024, use nftables
    1
    2
    3
    4
    
    #nftables
    opkg update
    opkg install bash dnsmasq-full curl ca-bundle ip-full ruby ruby-yaml kmod-tun kmod-inet-diag unzip kmod-nft-tproxy luci-compat luci luci-base
    opkg install /tmp/openclash.ipk
    
  15. Download the ipk and install it in web portal

  16. Setup VRRP via https://zhuanlan.zhihu.com/p/675745631, don’t forget to add option alt_config_file "/etc/keepalived/keepalived.conf in /etc/config/keepalived
    1
    2
    
    opkg update
    opkg install keepalived
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    ! Configuration File for keepalived
    
    global_defs {
    router_id LVS_DEVEL
    }
    
    vrrp_instance VI_1 {
        state MASTER
        interface br-lan
        virtual_router_id 51
        priority 110
        advert_int 1
        virtual_ipaddress {
            172.16.68.10
        }
    }
    
  17. /etc/init.d/keepalived enable
This post is licensed under CC BY 4.0 by the author.