Comet Pro (GL-RM10): Share Wi-Fi uplink to the Ethernet port (NAT + DHCP) – working scripts
Hi all,
I wanted the target PC connected to the Comet Pro's Ethernet port to get internet through the Comet's Wi-Fi connection, e.g. on the road with no router or switch around. There is no built-in option for this (only Wi-Fi/Ethernet failover), but it works fine with the tools already on the device (iptables, dnsmasq) via SSH.
Tested on GL-RM10, firmware [FW-Version]. Unofficial, use at your own risk. Everything the scripts change is runtime-only; a reboot restores the original state.
How it works
- The Comet stays connected to Wi-Fi (
wlan0) as usual. eth0gets a private subnet (10.254.254.0/24by default, with automatic fallback to172.31.254.0/24/192.168.254.0/24if it collides with the Wi-Fi network).dnsmasqserves DHCP + DNS oneth0only; traffic is NATed out viawlan0.- Works in any network the Comet itself is online in (no assumptions about the foreign network, no free IP needed).
- KVM web UI, GL cloud and Tailscale on the Comet keep working.
Step 1 – Important: set Ethernet to Static in the web UI
With Ethernet in DHCP mode and a cable plugged into a PC (which runs no DHCP server), the firmware falls back to zeroconf (169.254.x.x) and installs a default route via eth0 that takes precedence over Wi-Fi. Result: after a reboot with the cable plugged in, the Comet is effectively offline.
Fix: Network settings → Ethernet Mode Static:
| Field | Value |
|---|---|
| IP Address | 10.254.254.1 |
| Netmask | 255.255.255.0 |
| Gateway | 10.254.254.254 (dummy, required by the UI) |
| DNS Server | 10.254.254.1 |
With this, Wi-Fi keeps priority and the Comet survives reboots with or without the cable. Verify:
ip route get 1.1.1.1
It must go dev wlan0.
Step 2 – Scripts
Store them in a persistent location, e.g. /root.
/root/share.sh
#!/bin/sh
# Internet sharing wlan0 -> eth0 (NAT + DHCP + DNS)
WAN=wlan0
LAN=eth0
NETS="10.254.254 172.31.254 192.168.254"
# stop running instance
[ -x /root/stopshare.sh ] && /root/stopshare.sh >/dev/null 2>&1
# stop firmware DHCP/zeroconf on eth0 and clean up eth0
for p in $(ps -ef | grep -E '[u]dhcpc|[z]cip|[a]utoip' | grep -w "$LAN" | awk '{print $2}'); do kill $p; done
ip addr flush dev $LAN
ip route flush dev $LAN 2>/dev/null
GW=$(ip -4 route show default dev $WAN | awk '{print $3}' | head -1)
[ -z "$GW" ] && { echo "ERROR: $WAN has no gateway"; exit 1; }
# pick a private subnet that does not collide with the Wi-Fi network
for N in $NETS; do
ip route get $N.1 | grep -q " via " && { NET=$N; break; }
done
[ -z "$NET" ] && { echo "ERROR: no collision-free subnet found"; exit 1; }
# upstream DNS: from resolv.conf, otherwise gateway
DNS=$(awk '/^nameserver/{print $2; exit}' /etc/resolv.conf 2>/dev/null)
case "$DNS" in ""|127.*|::1) DNS=$GW ;; esac
echo "WLAN-GW: $GW DNS: $DNS LAN: $NET.0/24"
echo 1 > /proc/sys/net/ipv4/ip_forward
ip link set $LAN up
ip addr add $NET.1/24 dev $LAN
# NAT + firewall
iptables -t nat -A POSTROUTING -s $NET.0/24 -o $WAN -j MASQUERADE
iptables -I FORWARD 1 -i $LAN -o $WAN -j ACCEPT
iptables -I FORWARD 1 -i $WAN -o $LAN -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# DHCP + DNS on eth0 only (lo excluded: port 53 on 127.0.0.1 is already in use)
dnsmasq -C /dev/null --user=root --group=root \
--interface=$LAN --except-interface=lo --bind-dynamic \
--no-resolv --server=$DNS \
--dhcp-range=$NET.100,$NET.200,255.255.255.0,12h \
--dhcp-option=3,$NET.1 --dhcp-option=6,$NET.1 \
--dhcp-authoritative \
--dhcp-leasefile=/tmp/share.leases \
--pid-file=/tmp/share-dnsmasq.pid \
--log-dhcp --log-facility=/tmp/share.log
sleep 1
pidof dnsmasq >/dev/null || { echo "ERROR: dnsmasq not running"; exit 1; }
# watchdog: keep the firmware from taking over eth0 again
(
while true; do
for p in $(ps -ef | grep -E '[u]dhcpc|[z]cip|[a]utoip' | grep -w "$LAN" | awk '{print $2}'); do kill $p; done
ip route del default dev $LAN 2>/dev/null
ip route del 0.0.0.0/32 dev $LAN 2>/dev/null
for a in $(ip -4 -o addr show dev $LAN | awk '{print $4}' | grep -v "^$NET.1/"); do
ip addr del $a dev $LAN
done
ip -4 addr show dev $LAN | grep -q "$NET.1/" || ip addr add $NET.1/24 dev $LAN
sleep 5
done
) >/dev/null 2>&1 &
echo $! > /tmp/share-watchdog.pid
ip route get 1.1.1.1 from $NET.100 iif $LAN
echo "OK"
/root/stopshare.sh
#!/bin/sh
# stop internet sharing
WAN=wlan0
LAN=eth0
NETS="10.254.254 172.31.254 192.168.254"
for f in /tmp/share-watchdog.pid /tmp/share-dnsmasq.pid; do
[ -f $f ] && kill $(cat $f) 2>/dev/null
rm -f $f
done
for N in $NETS; do
while iptables -t nat -D POSTROUTING -s $N.0/24 -o $WAN -j MASQUERADE 2>/dev/null; do :; done
done
while iptables -D FORWARD -i $LAN -o $WAN -j ACCEPT 2>/dev/null; do :; done
while iptables -D FORWARD -i $WAN -o $LAN -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 2>/dev/null; do :; done
ip addr flush dev $LAN
ip route flush dev $LAN 2>/dev/null
echo "Sharing stopped"
Usage
chmod +x /root/share.sh /root/stopshare.sh
/root/share.sh # start
/root/stopshare.sh # stop
Set the target PC to DHCP. It gets an address from 10.254.254.100 to .200, with gateway and DNS 10.254.254.1.
Notes
- Not started automatically on purpose. After a reboot, sharing is off until you run
share.shagain. - Firmware updates may change the behavior. Re-check
ip route get 1.1.1.1afterwards. - The target PC is not reachable from the Wi-Fi network (NAT). For remote access, install Tailscale on the target PC. Using the Comet's built-in Tailscale as a subnet router for
10.254.254.0/24should also work, but I haven't fully tested it yet. - Windows puts the network behind the Comet into the "Public" profile. Keep that in mind for firewall rules.
- I first tried a real L2 bridge / proxy-ARP + DHCP relay to put the PC into the same subnet as the Wi-Fi. That is not reliable: a Wi-Fi client can't bridge foreign MACs, and many networks (hotels, enterprise Wi-Fi) block relayed DHCP. NAT is the robust option.
Feature request for GL.iNet
Since the hardware and the needed tools are already on the device, a simple "Share Wi-Fi to Ethernet port" toggle in the web UI would be great, and it would also avoid the zeroconf default-route issue described in Step 1.