How to restart wwan0 on command line

I have managed to get my OpenWrt box online through an LTE modem with QMI, but after restarting the box the LTE connection stays down until I restart wwan0 with the Restart button in Network/Interfaces page.
What does the interface Restart button do in practice? I would like to add the same as command(s) in the Startup script. I have tried the qmicli commands, ifdown + ifup and service network reload, but they did not do the trick.

1 Like

I was under the impression it was a combination of ifdown+ifup. Following to find the answer...

ifup wwan alone should do the job as well (in some cases there may be a reason to stage both commands, e.g. to tear down higher level services down gracefully (e.g. 6-in-4 tunnels)).

2 Likes

It is weird. After the restart I can see (with ifconfig) wwan0 being up with just IPv6 addressing. When I give ifdown wwan0 or ifup wwan0 I get "Interface wwan0 not found". Even though Restart button gets the connection up with IPv4 address too. So why cannot ifup/ifdown commands see wwan0 despite it is shown by ifconfig?

I checked from the system log what happens with Restart button. A lot of stuff:

Thu Jan 21 08:53:05 2016 daemon.notice netifd: LTE (7931): Stopping network LTE
Thu Jan 21 08:53:05 2016 daemon.notice netifd: LTE_4 (7508): udhcpc: received SIGTERM
Thu Jan 21 08:53:05 2016 daemon.notice netifd: Interface 'LTE_4' is now down
Thu Jan 21 08:53:05 2016 daemon.notice netifd: Network alias '' link is down
Thu Jan 21 08:53:05 2016 daemon.notice netifd: Interface 'LTE_4' has link connectivity loss
Thu Jan 21 08:53:05 2016 daemon.notice netifd: Interface 'LTE_4' is disabled
Thu Jan 21 08:53:05 2016 daemon.warn dnsmasq[4652]: no servers found in /tmp/resolv.conf.auto, will retry
Thu Jan 21 08:53:06 2016 daemon.notice netifd: LTE (7931): Command failed: Permission denied
Thu Jan 21 08:53:06 2016 daemon.notice netifd: Interface 'LTE' is now down
Thu Jan 21 08:53:06 2016 daemon.notice procd: /etc/rc.d/S95done: udhcpc: read error: Network is down, reopening socket
Thu Jan 21 08:53:06 2016 daemon.notice netifd: Interface 'LTE' is setting up now
Thu Jan 21 08:53:06 2016 daemon.info dnsmasq[4652]: read /etc/hosts - 4 addresses
Thu Jan 21 08:53:06 2016 daemon.info dnsmasq[4652]: read /tmp/hosts/odhcpd - 1 addresses
Thu Jan 21 08:53:06 2016 daemon.info dnsmasq[4652]: read /tmp/hosts/dhcp.cfg01411c - 2 addresses
Thu Jan 21 08:53:06 2016 daemon.info dnsmasq-dhcp[4652]: read /etc/ethers - 0 addresses
Thu Jan 21 08:53:06 2016 daemon.notice netifd: LTE (8005): Waiting for SIM initialization
Thu Jan 21 08:53:06 2016 daemon.notice netifd: LTE (8005): Device does not support 802.3 mode. Informing driver of raw-ip only for wwan0 ..
Thu Jan 21 08:53:06 2016 daemon.notice netifd: LTE (8005): Waiting for network registration
Thu Jan 21 08:53:06 2016 daemon.notice netifd: LTE (8005): Starting network LTE
Thu Jan 21 08:53:07 2016 daemon.notice netifd: LTE (8005): Setting up wwan0
Thu Jan 21 08:53:07 2016 daemon.notice netifd: Interface 'LTE' is now up
Thu Jan 21 08:53:07 2016 daemon.notice netifd: Network device 'wwan0' link is up
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: reading /tmp/resolv.conf.auto
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain test
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain onion
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain localhost
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain local
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain invalid
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain bind
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain lan
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using nameserver 2001:14b8:1000::1#53
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using nameserver 2001:14b8:1000::2#53
Thu Jan 21 08:53:07 2016 daemon.notice netifd: Network alias 'wwan0' link is up
Thu Jan 21 08:53:07 2016 daemon.notice netifd: Interface 'LTE_4' is enabled
Thu Jan 21 08:53:07 2016 daemon.notice netifd: Interface 'LTE_4' has link connectivity
Thu Jan 21 08:53:07 2016 daemon.notice netifd: Interface 'LTE_4' is setting up now
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: read /etc/hosts - 4 addresses
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: read /tmp/hosts/odhcpd - 2 addresses
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: read /tmp/hosts/dhcp.cfg01411c - 2 addresses
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq-dhcp[4652]: read /etc/ethers - 0 addresses
Thu Jan 21 08:53:07 2016 daemon.notice netifd: LTE_4 (8133): udhcpc: started, v1.30.1
Thu Jan 21 08:53:07 2016 daemon.notice netifd: LTE_4 (8133): udhcpc: sending discover
Thu Jan 21 08:53:07 2016 daemon.notice netifd: LTE_4 (8133): udhcpc: sending select for 37.136.45.254
Thu Jan 21 08:53:07 2016 user.notice firewall: Reloading firewall due to ifup of LTE (wwan0)
Thu Jan 21 08:53:07 2016 daemon.notice netifd: LTE_4 (8133): udhcpc: lease of 37.136.45.254 obtained, lease time 7200
Thu Jan 21 08:53:07 2016 daemon.notice netifd: Interface 'LTE_4' is now up
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: reading /tmp/resolv.conf.auto
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain test
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain onion
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain localhost
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain local
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain invalid
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain bind
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using local addresses only for domain lan
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using nameserver 2001:14b8:1000::1#53
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using nameserver 2001:14b8:1000::2#53
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using nameserver 62.241.198.245#53
Thu Jan 21 08:53:07 2016 daemon.info dnsmasq[4652]: using nameserver 62.241.198.246#53
Thu Jan 21 08:53:07 2016 user.notice root: starting ntpclient
Fri Nov  6 07:21:52 2020 user.notice firewall: Reloading firewall due to ifupdate of LTE (wwan0)
Fri Nov  6 07:21:52 2020 user.notice firewall: Reloading firewall due to ifup of LTE_4 (wwan0)

Just need to get these actions to the command line... :))

BTW, ifconfig wwan0 up command seems to find wwan0 even though ifup does not

I changed the commands in the Startup script and now the connection gets up without Restart button:

lsusb -t
qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
qmicli -d /dev/cdc-wdm0 -w
ip link set wwan0 down
echo 'Y' | tee /sys/class/net/wwan0/qmi/raw_ip
ip link set wwan0 up
qmi-network /dev/cdc-wdm0 start
udhcpc -q -f -i wwan0

I also have the file /etc/qmi-network.conf edited like this:

APN=internet
APN_USER=*
APN_PASS=*
PROXY=yes

Only one question left. Ping with URL does not succeed from the router. It works OK with an IP address, and ping (plus everything else) works OK from a PC connected to the router. What should I change to get also this working?

1 Like

ifup/ifdown use the uci interface name, in your case LTE_4.

Seems that the nameserver tjat OpenWrt is using doesn't work, or you have disabled it.

Please run the following commands (copy-paste the whole block) and paste the output here, using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have

ubus call system board; \
uci export dhcp; uci export firewall; \
head -n -0 /etc/firewall.user; \
ls -l  /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/* ; head -n -0 /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/*

Thanks, here you are:

/tmp/resolv.* /tmp/resolv.*/*
{
        "kernel": "5.4.61",
        "hostname": "FriendlyWrt",
        "model": "FriendlyElec NanoPi R2S",
        "board_name": "friendlyelec,nanopi-r2",
        "release": {
                "distribution": "OpenWrt",
                "version": "19.07.1",
                "revision": "r10911-c155900f66",
                "target": "rockchip-rk3328/generic",
                "description": "OpenWrt 19.07.1 r10911-c155900f66"
        }
}
package dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'
        option nonwildcard '1'
        option localservice '1'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv6 'server'
        option ra 'server'
        option ra_management '1'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'

package firewall

config defaults
        option syn_flood '1'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'

config zone
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        option network 'lan'

config zone
        option name 'wan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        option masq '1'
        option mtu_fix '1'
        option network 'wan wan6 LTE'

config forwarding
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config include
        option path '/etc/firewall.user'

config include 'miniupnpd'
        option type 'script'
        option path '/usr/share/miniupnpd/firewall.include'
        option family 'any'
        option reload '1'

# This file is interpreted as shell script.
# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.

# Internal uci firewall chains are flushed and recreated on reload, so
# put custom rules into the root chains e.g. INPUT or FORWARD or into the
# special user chains, e.g. input_wan_rule or postrouting_lan_rule.
ls: /tmp/resolv.*/*: No such file or directory
lrwxrwxrwx    1 1000     1000            16 Sep  4 07:49 /etc/resolv.conf -> /tmp/resolv.conf
-rw-r--r--    1 root     root            32 Nov  6 13:20 /tmp/resolv.conf
-rw-r--r--    1 root     root            74 Nov  6 13:20 /tmp/resolv.conf.auto
==> /etc/resolv.conf <==
search lan
nameserver 127.0.0.1

==> /tmp/resolv.conf <==
search lan
nameserver 127.0.0.1

==> /tmp/resolv.conf.auto <==
# Interface LTE
nameserver 2001:14b8:1000::1
nameserver 2001:14b8:1000::2
head: /tmp/resolv.*/*: No such file or directory

There are a couple of IPv6 nameservers advertised by your ISP. If you are not using IPv6, then they are no good.
Either negotiate IPv6 with the ISP or manually add an IPv4 nameserver (e.g 1.1.1.1 or 8.8.8.8) on LTE interface.

Thanks. That brings us to another point of wonder here.

If I start the connection just with commands...

qmi-network /dev/cdc-wdm0 start
udhcpc -q -f -i wwan0

... and Restart button, I have nicely also the IPv6 addresses OK, and ping works all the ways (address, name, IPv4, IPv6)

So I wonder how I can combine the best of these two ways, both automatic interface up and IPv4v6 addressing (with working ping)

Let's have a look at the interface config
uci export network

Here it is, first with just the two commands plus GUI Restart:

package network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdb5:12df:eacd::/48'

config interface 'lan'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.2.1'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ifname 'eth1'

config interface 'wan'
        option ifname 'eth0'
        option proto 'dhcp'

config interface 'wan6'
        option ifname 'eth0'
        option proto 'dhcpv6'

config interface 'LTE'
        option proto 'qmi'
        option username '*'
        option apn 'internet'
        option device '/dev/cdc-wdm0'
        option password '*'
        option auth 'both'
        option pdptype 'ipv4v6'

Then with all the commands (automatically up):

package network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdb5:12df:eacd::/48'

config interface 'lan'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.2.1'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ifname 'eth1'

config interface 'wan'
        option ifname 'eth0'
        option proto 'dhcp'

config interface 'wan6'
        option ifname 'eth0'
        option proto 'dhcpv6'

config interface 'LTE'
        option proto 'qmi'
        option username '*'
        option apn 'internet'
        option device '/dev/cdc-wdm0'
        option password '*'
        option auth 'both'
        option pdptype 'ipv4v6'

Oops, they seem identical. Still behaving differently. :hushed:

Add these:

uci set network.LTE.ipv6='1'
uci set network.LTE.peerdns='0'
uci set network.LTE.dns='8.8.8.8'
uci commit network
ifup LTE

and let us know how it goes.

1 Like

Thanks! It is fine now. The connection comes up automatically after POR or reboot, and everything - including bot v4 and v6 ping from the router - works OK.

One funny thing though: Basic "ping google.com" uses IPv6 as default. Even though, "ping -4 google.com" works OK. (This is not a problem at all, but would of course be nice to understand why.))

IPv6 takes precedence over IPv4 when both are available.

1 Like

Unlike on Windows, on my OpenWrt router "ping google.com" uses IPv4 even though also IPv6 is available.

Not in my case:

root@magiatiko:[/]#ping google.com
PING google.com(prg03s02-in-x0e.1e100.net (2a00:1450:4014:801::200e)) 56 data bytes
64 bytes from prg03s02-in-x0e.1e100.net (2a00:1450:4014:801::200e): icmp_seq=1 ttl=118 time=5.30 ms
64 bytes from prg03s02-in-x0e.1e100.net (2a00:1450:4014:801::200e): icmp_seq=2 ttl=118 time=12.0 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 5.297/8.663/12.029/3.366 ms

root@magiatiko:[/]#/usr/bin/ping -V
ping from iputils s20200821
1 Like

Funny. This is how mine works:

root@FriendlyWrt:~# ping -c 3 google.com
PING google.com (216.58.211.142): 56 data bytes
64 bytes from 216.58.211.142: seq=0 ttl=117 time=47.303 ms
64 bytes from 216.58.211.142: seq=1 ttl=117 time=30.054 ms
64 bytes from 216.58.211.142: seq=2 ttl=117 time=26.479 ms

--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 26.479/34.612/47.303 ms

root@FriendlyWrt:~# ping -6 -c 3 google.com
PING google.com (2a00:1450:400f:809::200e): 56 data bytes
64 bytes from 2a00:1450:400f:809::200e: seq=0 ttl=116 time=58.898 ms
64 bytes from 2a00:1450:400f:809::200e: seq=1 ttl=116 time=37.355 ms
64 bytes from 2a00:1450:400f:809::200e: seq=2 ttl=116 time=28.850 ms

--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 28.850/41.701/58.898 ms

You are likely using ping provided by BusyBox which prefers IPv4 by default.
Install this one if you want to make it prefer IPv6:

1 Like

Cool, thanks!

1 Like