How to get the ipv4 address from openwrt console?

Login my router which is running openwrt.

ssh  root@192.168.1.1
curl ip.sb
2408:8360:1e10:6b1:xx:xx:xx

How can get the ipv4 address with curl ?

RTFM :wink:

https://curl.se/docs/manpage.html

if you don't want to use the proper parameters (look for ipv4) in curl (might not be available, didn't try on openwrt) check your DNS settings.

Which setting file should i check?

I'd start by the DNS configuration, and your local DNS settings, if you've got one.

Do you just want to block this request, or all ipv6 traffic ?

curl ipv4.icanhazip.com ; curl ipv6.icanhazip.com
This would be the address internet sites see you. If you want to see the address the wan interface has, run ifstatus wan | grep address

2 Likes

Which configuration file decide the output action ?

Configuration file for what?

ipv4

like me and trendy said,

use a different IP lookup host, or make sure you tell curl to use ipv4 only.

1 Like

Is there a way to combine the two things together?

I am interested in Wan IPv4 and Public IPv4

so want it to show only WAN IPV4 + Public IPV4

curl ipv4.icanhazip.com
ifstatus wan | grep address

Works here. I see my WAN/Public IP address displayed. Not sure why you said "WAN IPv4 + Public IPv4" though.

Screenshot 2023-09-29 051350

BTW, in the future, you may wish to create a new thread.

2 Likes

Because my isp provides a private IP and a different public IP
example:
WAN Private IP= 10.01.02.03
Public IP when check from any ip checker cite=51.082.62.1

Many of the private wan ip are bad, a few of them are good, I know them from number after the dot, for example 10.55 is excellent 10.90 is bad

I tried combining the two, but it turned out poorly

curl ipv4.icanhazip.com ; ifstatus wan | grep address

root@ODU:~# curl ipv4.icanhazip.com ;  ifstatus wan | grep address
5.×.152.××
                "addresses",
        "ipv4-address": [
                        "address": "100.×.48.××",
        "ipv6-address": [
                        "address": "2001:16a2:c106:××××:1:1:4c8c:××××",
                        "address": "2001:16a2:c106:××××::",
                                        "address": "2001:16a2:c106:××××::",
                "ipv4-address": [
                "ipv6-address": [

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

2 Likes

Thank You

If I want to try to connect to this IP 10.185

by telnet or ssh paste this?

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.185" ]
then
    sleep 10
    ifup "${NET_IF}"
fi
EOF

GL using telnet on any recent openwrt version ...

2 Likes

Thanks

If I want him to try to connect to more than one specific IP address, can you write the command to me? I do not have enough experience.

The IP address that I want script to try to connect starts with these numbers :
10.185
10.165
100.105

You won't be able to remotely connect to any addresses starting with those octets. None of them are routable over the internet.

I was under the impression that certain IPs provide better Internet connectivity for the OP.

My Bad ISP He provided only such This IPs (CGNAT)

Currently, my 5G CPE router based on OpenWrt is connecting to one of these IPs, but after many attempts without exaggeration, it may reach 10 or 20 times of attempts.

and (10.185-10.105..etc) is the best of the bad of them

Yes, there is a big difference between one IP and the other, especially in Latency Ping. The difference may reach 50ms

1 Like