7855 questions

9275 answers

14928 comments

12723 members

0 votes
486 views 1 comments
by
Hi,

I would like an overview of the WAN interface in my application.
How can I get the information of WAN interface, IP address, network mask, Gateway, DNS servers and uptime with SSH commands?

2 Answers

0 votes
by

Hello,

There are several ways, depends on what you need. For general interface info use on of these commands (output syntax is different):

  • ifconfig <IF_NAME> 
  • ip a show <IF_NAME>

Replace <IF_NAME> with the name of the required WAN interface:

  • wwan0 - mobile WAN
  • eth1 - wired WAN

To print only the required values, use the commands listed below:

WAN IP address:

  • ifconfig <IF_NAME> | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }'

Netmask:

  • ifconfig <IF_NAME> | grep 'Mask:' | cut -d: -f4 | awk '{ print $1 }'

WAN IP address/netmask:

  • ip a show <IF_NAME> | grep 'inet ' | awk '{ print $2 }'

Default gateway:

  • ip route | grep 'default' | awk '{ print $3}'

DNS server(s):

  • cat /tmp/resolv.conf.auto | grep 'nameserver' | awk '{ print $2 }'

Remember to replace <IF_NAME> with the actual interface name where required.

Hope this helps, good luck!

Best answer
by
curl ifconfig.io

this will give you the address you appear as to the world, lots of operators use sNAT etc
0 votes
by
Hello, try:

ifstatus wan

this command outputs json formated information. Also there are more interfaces, it depends on router, you can list them by command:

ubus list network.interface.*