How to set NAT on Beaglebone Black

I am using a Beaglebone Black with new debian
I used the new debian with reference to the following link

Through the answers to the previous question I set static IP using connmanctl
The following is ifconfig output of my beaglebone black

usb0 is a wired ethernet and wwan0 is connected with LTE modem.
I want to connect a device to eth0 and connect to the external network through wwan0

I tried the following

# sysctl net.ipv4.ip_forward=1
# iptables --table nat --append POSTROUTING --out-interface wwan0 -j MASQUERADE
# iptable --append FORWARD --in-interface eth0 -j ACCEPT
# route add default gw
# echo "nameserver" >> /etc/resolv.conf

But it didnot work.
Could you explain how to set NAT on beaglebone black?
thank you.

@sonds1, i think you have the wrong gateway… wwan0 is your net connection right?

route add default gw


Hi Robert C Nelson.

I succeeded in setting up NAT with your help. Thank you.

However, wwan0 is connected to the LTE modem
and the IP address is changed when the power is turned off and on.
Then I have to set it manually,
Is there a way to set it automatically

@sonds1, you could script it:

ip -4 -o addr show wwan0 | awk '{print $4}' | cut -d "/" -f 1

So your full command would be:
route add default gw $(ip -4 -o addr show wwan0 | awk '{print $4}' | cut -d "/" -f 1)


Hi Robert C Nelson

Thank you so much for your help~~~ !!!