OpenTollGate / TollGateNostrToolKit

5 stars 1 forks source link

Pick random IP address to avoid conflict with WAN #27

Closed chGoodchild closed 4 weeks ago

chGoodchild commented 1 month ago

To achieve what you're describing, you'll need to modify your router's configuration. This typically involves editing the DHCP server settings and possibly the network interface configuration. Here's a general approach to accomplish this:

  1. Create a script to generate a random IP address:

    First, you'll need a script that generates a random IP address of the form x.x.x.1. Here's a simple bash script that does this:

    #!/bin/sh
    echo $((RANDOM%254+1)).$((RANDOM%254+1)).$((RANDOM%254+1)).1

    Save this script as /usr/bin/random_ip.sh and make it executable:

    chmod +x /usr/bin/random_ip.sh
  2. Modify the network configuration:

    You'll need to edit the network configuration file, which is typically located at /etc/config/network. Modify the LAN interface section to use the random IP:

    config interface 'lan'
        option type 'bridge'
        option ifname 'eth0.1'
        option proto 'static'
        option ipaddr '`/usr/bin/random_ip.sh`'
        option netmask '255.255.255.0'
  3. Update DHCP server configuration:

    Edit the DHCP server configuration file, usually located at /etc/config/dhcp. Modify the LAN section to use the new random IP range:

    config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv6 'server'
        option ra 'server'
  4. Create a boot script:

    To ensure this happens at every boot, create a boot script:

    #!/bin/sh /etc/rc.common
    
    START=99
    
    start() {
       NEW_IP=$(/usr/bin/random_ip.sh)
       uci set network.lan.ipaddr="$NEW_IP"
       uci commit network
       /etc/init.d/network restart
       /etc/init.d/dnsmasq restart
    }

    Save this as /etc/init.d/random_lan_ip and make it executable:

    chmod +x /etc/init.d/random_lan_ip

    Enable it to run at boot:

    /etc/init.d/random_lan_ip enable
  5. Reboot your router:

    After making these changes, reboot your router for the changes to take effect.

Please note:

Always back up your current configuration before making these changes, and be prepared to reset your router if something goes wrong.