Connect To Private or Public Wan specific IP address

Hi
i have 5G CPE Built on OpenWrt 19.7.

I'm not familiar enough with OpenWrt

My ISP It Give a Private IP that starts with 10 or 100.
The problem is that most of these IPs are very bad in Ping and speed.

What I do now is use

ifupwan

via ssh to disconnect and connect again until I get a good IP address. I may need to repeat this 10-20 times،Until I find a good IP

There are good IPs that I know from the number after 100 or 10, for example 10.90 or 100.50 and others.

I found this explanation

cat << "EOF" > /etc/hotplug.d/iface/10-fix-wan-ip
. /lib/functions/network.sh
network_flush_cache
network_find_wan NET_IF
network_get_ipaddr NET_ADDR "${NET_IF}"
if [ "${ACTION}" = "ifup" ] \
&& [ "${INTERFACE}" = "${NET_IF}" ] \
&& [ "${NET_ADDR%%.*}" = "10" ]
then
    sleep 10
    ifup "${NET_IF}"
fi
EOF

How do I apply it to try to connect to ip addresses that start with 10.90, 100.50, 10.89, etc.

Also, can I cancel that comman easily, Or it only works in the same SSH or Telnet session?

if you are behind CGNAT it is very unlikely that you will get a public ip address (or maybe I'm wrong)

unless you are referring to v6 ip addresses

1 Like

You might consider referring to the answer you were given in the previous thread:

1 Like

Well, where do I add the starting numbers of the IP address? It is more than one10.90 and 100.50 and other. Can you help me and write the command for me?

Also, can I cancel the command easily, or will it be canceled if I close the Telnet or ssh session?

I want him to Connect one of these private IP addresses:

100.90.××.××

10.125.××.××

10.145.××.××

10.150.××.××

The Wiki explains what you've asked.

Also, you asked that already. Perhaps a better method would be to explain what issues you're having with the Wiki.

[Solved] How to refresh Internet connection if assigned private IP - #8 by vgaetera

case ${WAN_ADDR} in
(10.125.*|10.145.*|10.150.*|100.90.*) exit 0 ;;
esac

I updated the script in the wiki for better scaling.

2 Likes

Thanks

I'm noob OpenWrt
please help me and don't get bored with me!

cat << "EOF" > /etc/hotplug.d/iface/10-wan-ipaddr
if [ "${ACTION}" != "ifup" ] \
&& [ "${ACTION}" != "ifupdate" ]
then exit 0
fi
if [ "${ACTION}" = "ifupdate" ] \
&& [ -z "${IFUPDATE_ADDRESSES}" ] \
&& [ -z "${IFUPDATE_DATA}" ]
then exit 0
fi
. /lib/functions/network.sh
network_flush_cache
network_find_wan NET_IF
network_get_ipaddr NET_ADDR "${NET_IF}"
if [ "${NET_IF}" != "${INTERFACE}" ]
then exit 0
fi
case ${NET_ADDR} in
(10.125.*|10.145.*|10.150.*|100.90.*) exit 0 ;;
esac
sleep 10
ifup "${INTERFACE}"
EOF

Copy and paste the command into an SSH session and it will attempt to connect to one of the IPs.

and How can I cancel the command?
Is it canceled by closing the session, or is there another command that I must write to cancel it?

why maybe i need to cancel command that Which selects the specific ips, because maybe not found specific ip

this is a special script, so called plugin which extends owrt's hot-plug system. it is an event based solution to react on special events like wan interfaces is being activated in this case.
when owrt detects that wan interface is being activated, i.e. when receiving an ip address from your ISP it fires an event which triggers this script. this will check the new ip address if does not meet your criteria ( 10.125.*|10.145.*|10.150.*|100.90.* ) will reconnect automatically. this will be repeated until you got a "good" ip, so you cannot stop it. but if you extend the script like:

cat << "EOF" > /etc/hotplug.d/iface/10-wan-ipaddr
if [ -f /tmp/wan_ip_ok ] then
  rm /tmp/wan_ip_ok
  exit 0
fi
if [ "${ACTION}" != "ifup" ] \
&& [ "${ACTION}" != "ifupdate" ]
then exit 0
fi
if [ "${ACTION}" = "ifupdate" ] \
&& [ -z "${IFUPDATE_ADDRESSES}" ] \
&& [ -z "${IFUPDATE_DATA}" ]
then exit 0
fi
. /lib/functions/network.sh
network_flush_cache
network_find_wan NET_IF
network_get_ipaddr NET_ADDR "${NET_IF}"
if [ "${NET_IF}" != "${INTERFACE}" ]
then exit 0
fi
case ${NET_ADDR} in
(10.125.*|10.145.*|10.150.*|100.90.*) exit 0 ;;
esac
sleep 10
ifup "${INTERFACE}"
EOF

and create via SSH a file /tmp/wan_ip_ok ( touch /tmp/wan_ip_ok ) it will not try to get a new ip address. or if you count times this plugin runs and limit after 10 runs for example.

1 Like