OpenWrt Forum Archive

Topic: [HELP] /etc/ppp/ip-up.d is not working.

The content of this topic has been archived on 30 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

1.i wrote a script and put under /etc/ppp/ip-up.d, but the system doesn't run the script when the ppp0 is up.
2.i did chmod a+x

3.the script:
var1=`ifconfig ppp0 | grep 'addr:' | sed 's/.*addr:\([^ ]\{2,3\}\).*/\1/'`
if [ "$var1" != 218 ]; then
    ifdown wan && ifup wan
else
    WANIP=$(ifconfig ppp0 | grep addr | awk '{print $2}' | sed 's/addr://')
        iptables -t nat -A prerouting_rule -d $WANIP -p tcp -j DNAT --to 192.168.1.100
        iptables -A forwarding_rule -p tcp -d 192.168.1.100 -j ACCEPT
        iptables -t nat -A postrouting_rule -s 192.168.0.0/12 -p tcp -d 192.168.1.100 -j MASQUERADE
fi

3.1.the purpose of the script: Keep reconnect until get a wan IP start with 218 (218.x.x.x), if the IP is start with 218 then it'll create a loopback firewall rule.

use /etc/hotplug.d/iface and check for ACTION=ifup and INTERFACE=wan
that also works with dhcp and static ...

nbd, thank u very much~~ The router is now able to get WAN IP which start with 218, and create loopback firewall rule.

/etc/hotplug.d/iface/10-218
if [ "$ACTION" = "ifup" ] && [ "$INTERFACE" = "wan" ]; then
var1=`ifconfig ppp0 | grep 'addr:' | sed 's/.*addr:\([^ ]\{2,3\}\).*/\1/'`
if [ "$var1" != 218 ]; then
    ifdown wan && ifup wan
else
    WANIP=$(ifconfig ppp0 | grep addr | awk '{print $2}' | sed 's/addr://')
        iptables -t nat -A prerouting_rule -d $WANIP -p tcp --dport 8080 -j DNAT --to 192.168.1.100
iptables -A forwarding_rule -p tcp --dport 8080 -d 192.168.1.100 -j ACCEPT
iptables -t nat -A postrouting_rule -s 192.168.1.0/8 -p tcp --dport 8080 -d 192.168.1.100 -j MASQUERADE
fi
fi

The discussion might have continued from here.