home
readme
diff
tree
note
docs
0commit 96a73a9f781ed8610b819f9df0a4d3814e836adf
1Author: lakefox <mason@lakefox.net>
2Date: Mon Jan 5 14:28:09 2026 -0700
3
4 Fixed router temp ip assignment issue
5
6diff --git a/init.sh b/init.sh
7index c164ea0..d3c948a 100755
8--- a/init.sh
9+++ b/init.sh
10@@ -30,6 +30,10 @@ mkdir -p root/usr/share/udhcpc
11 cp modules/default.script root/usr/share/udhcpc
12 chmod +x root/usr/share/udhcpc/default.script
13
14+# cp modules/nftables.conf root/etc/
15+cp modules/ip_broadcast.sh root/
16+chmod +x root/ip_broadcast.sh
17+
18 # Load the firewall script
19 cp modules/network.sh root/lib
20 chmod +x root/lib/network.sh
21diff --git a/modules/.default.script.swp b/modules/.default.script.swp
22new file mode 100644
23index 0000000..483e2f8
24Binary files /dev/null and b/modules/.default.script.swp differ
25diff --git a/modules/.network.sh.swp b/modules/.network.sh.swp
26deleted file mode 100644
27index f42f9d2..0000000
28Binary files a/modules/.network.sh.swp and /dev/null differ
29diff --git a/modules/default.script b/modules/default.script
30index ecb2cbf..1410e32 100755
31--- a/modules/default.script
32+++ b/modules/default.script
33@@ -10,6 +10,17 @@ case "$1" in
34 ;;
35
36 renew|bound)
37+ # --- NEW MODEM CHECK ---
38+ # Check if the IP starts with 192.168.100
39+ case "$ip" in
40+ 192.168.100.*)
41+ echo "REJECTED: Modem internal IP detected ($ip). Waiting for bridge mode..." > /dev/console
42+ ip addr flush dev $interface
43+ exit 1
44+ ;;
45+ esac
46+ # -----------------------
47+
48 echo "Applying IP $ip to $interface..." > /dev/console
49
50 # 1. Use 'replace' to be safe, and add a broadcast address
51diff --git a/modules/dhcp.sh b/modules/dhcp.sh
52index 2d08da7..bf6c8cd 100755
53--- a/modules/dhcp.sh
54+++ b/modules/dhcp.sh
55@@ -20,6 +20,7 @@ opt lease 864000 # 10 days in seconds
56 # Static lease for the server
57 static_lease 14:98:77:86:e5:0d 192.168.0.11
58 static_lease 18:7c:0b:02:c4:50 192.168.0.2
59+static_lease d8:9e:f3:9f:ed:6f 192.168.0.12
60
61 # File to store active leases (ensure directory exists)
62 lease_file /var/lib/misc/udhcpd.leases
63diff --git a/modules/ip_broadcast.sh b/modules/ip_broadcast.sh
64new file mode 100644
65index 0000000..e4f94e4
66--- /dev/null
67+++ b/modules/ip_broadcast.sh
68@@ -0,0 +1,4 @@
69+#!/bin/sh
70+# Get the current IP of eth0 (adjust interface name as needed)
71+CURRENT_IP=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
72+echo "$CURRENT_IP"
73diff --git a/modules/network.sh b/modules/network.sh
74index 7b24ef7..705fc20 100755
75--- a/modules/network.sh
76+++ b/modules/network.sh
77@@ -11,9 +11,35 @@ ip addr add 192.168.0.1/24 dev eth1
78 touch /var/lib/misc/udhcpd.leases
79 udhcpd /etc/udhcpd.conf &
80
81-# Get IP from ISP - restoration of the default script is mandatory for routing!
82-# We use -n (now) to make the script wait until the IP is actually set.
83-udhcpc -i eth0 -s /usr/share/udhcpc/default.script -n -q -t 5
84+# --- WAN IP ACQUISITION LOOP ---
85+while true; do
86+ echo "Requesting WAN IP from modem..." > /dev/console
87+
88+ # -n: exit if no lease, -q: quit after lease, -t 5: try 5 times
89+ udhcpc -i eth0 -s /usr/share/udhcpc/default.script -n -q -t 5
90+
91+ # Extract the IP assigned to eth0
92+ WAN_IP=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
93+
94+ case "$WAN_IP" in
95+ 192.168.100.*)
96+ echo "Caught modem internal IP ($WAN_IP). Modem not ready. Retrying in 15s..." > /dev/console
97+ ip addr flush dev eth0
98+ sleep 15
99+ ;;
100+ "")
101+ echo "No IP received. Retrying in 5s..." > /dev/console
102+ sleep 5
103+ ;;
104+ *)
105+ echo "Valid WAN IP detected: $WAN_IP" > /dev/console
106+ break
107+ ;;
108+ esac
109+done
110+
111+# Restart udhcpc in the background to maintain the lease/handle ISP changes
112+udhcpc -i eth0 -s /usr/share/udhcpc/default.script &
113
114 # Give the kernel a second to settle the routing table
115 sleep 2
116diff --git a/modules/nftables.conf b/modules/nftables.conf
117new file mode 100644
118index 0000000..87f7366
119--- /dev/null
120+++ b/modules/nftables.conf
121@@ -0,0 +1,62 @@
122+#!/usr/sbin/nft -f
123+
124+flush ruleset
125+
126+define WAN_IF = eth0
127+define LAN_IF = eth1
128+define SERVER_IP = 192.168.0.11
129+define LAN_NET = 192.168.0.0/24
130+
131+table ip filter {
132+ chain input {
133+ type filter hook input priority 0; policy drop;
134+ iifname "lo" accept
135+ iifname $LAN_IF accept
136+ ct state established,related accept
137+ iifname $WAN_IF udp dport 67-68 accept
138+ ip protocol icmp icmp type echo-request limit rate 2/second accept
139+ ct state invalid drop
140+ }
141+
142+ chain forward {
143+ type filter hook forward priority 0; policy drop;
144+ tcp flags syn tcp option maxseg size set rt mtu
145+ ct state established,related accept
146+
147+ # Allow LAN to WAN and LAN to LAN
148+ iifname $LAN_IF oifname $WAN_IF accept
149+ iifname $LAN_IF oifname $LAN_IF accept
150+
151+ # Allow Port Forwarded traffic to Server
152+ ip daddr $SERVER_IP tcp dport { 80, 53 } limit rate 50/second accept
153+ ip daddr $SERVER_IP udp dport 53 limit rate 50/second accept
154+
155+ # Local SSH to Server
156+ iifname $LAN_IF ip daddr $SERVER_IP tcp dport 22 accept
157+ }
158+
159+ chain output {
160+ type filter hook output priority 0; policy accept;
161+ }
162+}
163+
164+table ip nat {
165+ chain prerouting {
166+ type nat hook prerouting priority -100;
167+
168+ # Match traffic coming into the interfaces that is NOT from loopback
169+ iifname != "lo" tcp dport 80 dnat to $SERVER_IP
170+ iifname != "lo" tcp dport 53 dnat to $SERVER_IP
171+ iifname != "lo" udp dport 53 dnat to $SERVER_IP
172+}
173+ chain postrouting {
174+ type nat hook postrouting priority 100;
175+
176+ # HAIRPIN: If traffic is coming FROM LAN and going TO Server, masquerade it
177+ # so the server replies through the router instead of directly to the client.
178+ ip saddr $LAN_NET ip daddr $SERVER_IP masquerade
179+
180+ # WAN: Standard masquerade for all internet-bound traffic
181+ oifname $WAN_IF masquerade
182+ }
183+}
184diff --git a/modules/script.sh b/modules/script.sh
185index aead671..ce57541 100755
186--- a/modules/script.sh
187+++ b/modules/script.sh
188@@ -45,8 +45,12 @@ sleep 1
189 # Start the firewall
190 /lib/network.sh
191
192+#/usr/sbin/nft -f /etc/nftables.conf
193+
194 sleep 2
195
196+while true; do /ip_broadcast.sh | nc -l -p 6785; done &
197+
198 echo "--- BusyBox Router Initialized ---"
199
200 # 4. Start the interactive root shell (PID 1 hands off to this)